Position: Index > Switch Circuit >

Dealing with switch bounce problem

2015-09-01 12:08  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

Normally any embedded system has a relations with real word. Simplest and most common way is using buttons.

button.PNG

This is how application interact with human. But real world like a human is not perfect. Practically mechanical contacts bounce (turns on and off repeatedly for a short period). And you cannot do anything about it. And for simple applications there is no need to look for higher quality buttons or try special button construction or event try to press button precisely. It is better to deal with it wisely. In digital circuits there may be used special circuits like triggers, RC circuits and so on. But when working with microcontrollers there is simpler to remove bouncing by adding a couple lines of code. Usually switches bounce for less then 20ms bigger ones may take up to 50ms.

button_bounce.PNG

Buttons in embedded systems may cause a number of problems like:

Rather reading value ‘A’ microcontroller may read ‘AAAAAA’;

When button released it bounces two a€“ this may look like button vas pressed again after release.

To avoid this use simple routine:

Read a pin;

If switch were detected a€“ wait for 20ms and then read pin again;

If second reading confirms the first reading, then assume that button was pressed.

Select delay time according to buttons you use. If 20ms doesn’t guarantee stability then add more ms. You may determine this time by using oscilloscope.


Reprinted Url Of This Article:
http://www.scienceprog.com/dealing-with-switch-bounce-problem/