This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Switch Debounce using timer interrupt

Hi,

 

I am facing an issue with the push button switch. I am detecting the switch press using interrupt on falling edge, but I am getting multiple interrupts and I know that it is because of bouncing of the switch.

I searched through the community for a solution, many suggested to sense based on polling, but I like to keep it based interrupt.

Finally I saw a post to debounce using timer based interrupt and disabling the port.

But I am unable to get further details.

Can anyone post the example code for that or concept which can explain in detail??

 

Thanks in advance

Regards,

Rajesh Reddy

  • Hi Rajesh,

    I added a small state machine with states: Off, GoingOn, On and GoingOff. The state Off -> GoingOn as well as On -> GoingOff is triggered by button switch and started a timer. The state transition from GoingOn -> On and GoingOff -> is triggered by a timer interrupt. I hope this summary helps.

    Regards
    Guenther

  • Hi!

    To get rid of this problem, the software solution could be based on adding a short delay after the first interrupt detection and, after the delay, check again if the button is pressed :)

    Check the delay_cycles() instruction.

    Good luck!

**Attention** This is a public forum