Dealing with switch bounce problem
-->Normally any embedded system has a relations with real word. Simplest and most common way is using buttons.
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.
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 – this may look like button vas pressed again after release.
To avoid this use simple routine:
-
Read a pin;
-
If switch were detected – 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.
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …Programming AVR ADC module with WinAVR,Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut … |
New on WinARM Tutorial
What are differences between WinARM and WinAVR,Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …LPC2000 watchdog timer,As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount … |
