Debouncing
Can anyone help me with debounce code in C for Rising and falling edge interrupt??
Can anyone help me with debounce code in C for Rising and falling edge interrupt??
As the first thing, forget about the EXTI interrupt, and *never* use it again, when it comes to mechanical switches.
Perform the sampling based on a timer, or timer-controlled process (either in timer interrupt, or based on flag set in timer interrupt, or any other mechanism ensuring you will do it regularly but not too often). You want to sample once in a few milliseconds, and you want to sample a few times - say four to twelve - basically for the duration of bouncing of the switch. Have a variable with several states controlling your process - "stable 0", "bouncing 1", "stable 1", "bouncing 0" - and then the transition between "bouncing x" to "stable x" is the "output edge" upon which you perform the action you want to do when the button is pressed/released.
You also have to work more to remove the input noise, as Ozone said above.
JW
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.