Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Timer/Counter (TC) Timeout Example 2 for ATmega1284p on STK600 Documentation

Introduction

This example shows how to use the Timer/Counter (TC) Timeout Driver to implement a software debounce filter on a button input.

Main files:

TC Timeout Driver

The driver can be found here.

Device Info

All megaAVR devices with a Timer/Counter module can be used.

Setup

The following connections are required on STK600 for this example:

  • For button input, connect PORTB pin header to SWITCHES pin header with a 10-pin cable.
  • For LED output, connect PORTD pin header to LEDS pin header with a 10-pin cable.
  • For 32KHz clock, connect a wire between 32KHz and TOSC2 on the AUX pin header.

Description of the 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.

Compilation Info

This software was written for the GNU GCC for AVR. Other compilers may or may not work.

Contact Information

For further information, visit Microchip.