BUtton bouncing

Onc we implement the FSM described in the previous page, we might notice that one single push results in more than one action. For example, if we implement the above FSM and use the action for incrementing a counter, we might notice that pushing the button once seems to skip some numbers. It feels like the button has been pushed more than once.  Why does this happen?

When you push a button, it causes two metal plates to make contact, indicating that a button has been pushed. In actuality, the metal plate attached to the button itself can sometimes “bounce” several times before making stable contact with the other metal plate. Thus, the microcontroller sees several brief instances of the button being pushed until the bouncing stabilizes.

The scope capture on the right illustrates this bouncing phenomenon. As can be seen, the rapid changes from low to high are due to the plates bouncing. This poses an issue where a single button push can be registered as several. If you had a counter that increments by one every time you push the button, then pushing the button could increment the counter several times due to the bouncing. 

A debouncing mechanism needs to be implemented in order to preserve the intended functionality of the programs we make. In essence, debouncing is a filtering operation that filters the undesired behavior of the button. There are hardware solutions for debouncing. However, modifying the Launchpad’s hardware is much easier said than done. Instead, we will look at a software solution. Specifically, we can use an FSM and one-shot timer to resolve this issue.