This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Debounce in callbacks

Hello!

I currently have an external button and LED connected to the Icarus IoT dev board. For the time being, I just want to turn on the LED in the callback function when I press the button. However, the button (and the board) is highly sensitive and registers several interrupts with one push. I can even turn on the LED by touching the pin with my finger!

So I was wondering if there is any easy way to add some kind of debounce code in the callback itself? I have seen some examples here and there, but none of them that is a really proper method nor being used inside the callback itself. 

Looking forward to seeing your suggestions!

Parents Reply Children
  • I do not recall making any changes except for changing the pin numbers that fits the board. Have you tried to compile the code for actinius_Icarus_ns? Since that's the board I'm using and not the nrf9160dk. Not sure if that makes any difference? 

  • Hi Christian, 

    This sample does not support actinius Icarus board and it also has big differences with our supported nRF DK boards, so it will take some effort to modify the sample to fit this board. 

    I suggest you either switch to nRF9160DK to continue the learning of CAF or just search "debounce code in c" to quickly catch some debouncing implementation for your application. The general theory is that on edge detection wait for several ms and detect edge again and if the change is still present then it is a true change. The button.c from CAF set debounce interval CAF_BUTTONS_DEBOUNCE_INTERVAL 2ms as default.

    Best regards,

    Charlie

  • Hello again, Charlie!

    Before I made this post I was looking around for some suitable debounce code. However, I found none that was implemented directly into the callback, hence this post. Is there a reason why I can't find any that suits my use?

  • Hi Christian,

    Debounce need dealy, it is not wise to introduce significant dealy on a call back in the interrupt handler. 

    Maybe you can also think about a hardware solution?

    I am not sure if you have seen similar complaints on the board you are using. Do you have any chance to play with the Nordic nRF DK board? The combination of the HW+FW solution could be a good reference for your development.

    Best regards,

    Charlie

Related