This example shows how to use the Timer/Counter (TC) Timeout Driver to implement a software debounce filter on a button input.
The driver can be found here.
All megaAVR devices with a Timer/Counter module can be used.
The following connections are required on STK600 for this example:
This example will continuously sample button input from SW0 on STK600, and then apply a software debounce filter to get a stable button press indication. A valid button down-press will cause LED0 to toggle.
This filter is implemented by starting a 50ms timeout on every change on the button input sample. Any noise will cause the timeout to restart, but if the signal is stable for a minimum of 50ms it will be considered as a valid button press.
This software was written for the GNU GCC for AVR. Other compilers may or may not work.
For further information, visit Microchip.