Difference between revisions of "Debouncing Microcontroller Inputs"

From OpenCircuits
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Debouncing =
 
= Debouncing =
  
 +
under construction
  
 +
Debouncing is used on switches that are providing  digital input to a device like a micro controller – here we will assume that the input is a micro controller.  When the state of the switch is changed from open to closed and vise versa there is often a short period of time when the switch make many rapid transitions between open and closed.  These transitions are called bouncing and they often cause problems in the application where the assumption is made that actuating the switch once caused only one transition.  Getting rid of the effect of the transitions is called debouncing.
 +
 +
There are two general way of getting rid of the bounces, one called hardware debouncing add circuitry that actually gets rid of the unwanted transitions, the other is called software debouncing and causes the application to ignore the bounces.
 +
 +
Note:  if the button press triggers an interrupt then the bounce may cause more problems than code that just polls the button state.
 +
 +
== Method 1: Ignore it ==
 +
 +
This is actually a method that can work under some conditions.  Suppose you have a lid you want opened when a button is pressed.  Bounce may not matter for a couple of reasons:  the lid can only be opened once so a bounce will not open it twice ( but bad code may be confused by the bounce ), the delay involved in opening the the lid will give time for the bouncing to end.
 +
 +
== Method 2: Do not Ignore it ==
 +
 +
Fix in hardware, software or both.... more comming, but see links for now
 +
 +
 +
<!--------------------------------
 +
a few comments
  
  
Line 13: Line 31:
 
*[http://as220.org/labs/pages/Arduino%20and%20Servo%20Motor%20Workshop Arduino and Servo Motor Workshop] Course link at AS220 Labs.
 
*[http://as220.org/labs/pages/Arduino%20and%20Servo%20Motor%20Workshop Arduino and Servo Motor Workshop] Course link at AS220 Labs.
  
 
+
<!-------------------------------->
=== Table ===
+
=== Links ===
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 33: Line 51:
 
<!-------------------------------->
 
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[]
+
|[http://www.all-electric.com/schematic/debounce.htm How to de-bounce a switch using CMOS & TTL]
 
|
 
|
 
|
 
|
 
<!-------------------------------->
 
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[]
+
|[http://www.labbookpages.co.uk/electronics/debounce.html Switch Debouncing]
 
|
 
|
 
|
 
|
 
<!-------------------------------->
 
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[]
+
|[http://hackaday.com/2010/11/09/debounce-code-one-post-to-rule-them-all/#more-29916 Debounce Code – one post to rule them all]
 
|
 
|
 
|
 
|
  
<!--------------------------------
+
<!-------------------------------->
 +
|-valign="top"
 +
|[http://www.engscope.com/pic-example-codes/basic-io-button-debounce/ Basic IO: Button Debounce]
 +
|
 +
|
 +
<!-------------------------------->
 +
|-valign="top"
 +
|[http://www.rentron.com/myke6.htm Button Debouncing]
 +
|
 +
|
 +
<!-------------------------------->
 +
|-valign="top"
 +
|[http://www.patchn.com/index.php?option=com_content&view=article&id=59:debounce&catid=20:plc&Itemid=118 Debounce]
 +
|
 +
|
 +
<!-------------------------------->
 +
|-valign="top"
 +
|[http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=33821 Switch Debounce Code]
 +
|
 +
|
 +
<!-------------------------------->
 +
|-valign="top"
 +
|[http://www.jeremyblum.com/2011/03/07/arduino-tutorial-10-interrupts-and-hardware-debouncing/ Tutorial 10 for Arduino: Interrupts + Debouncing]
 +
|
 +
|[
 +
<!-------------------------------->
 +
|-valign="top"
 +
|[http://opensourcehardwarejunkies.com/tutorial-15-debouncing-a-button-with-arduino/ Tutorial 15: Debouncing a button]
 +
|
 +
|
 +
<!-------------------------------->
 +
|-valign="top"
 +
|[http://www.roguescience.org/wordpress/building-a-midi-out-controller/part-3-add-a-switch/exercise-6/ Roguescience Arduino Tutorials  127.0.0.1  4.2 Pull-up/down resistors, debouncing]
 +
|
 +
|
 +
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[[]]
+
|[http://forum.allaboutcircuits.com/showthread.php?t=41780 debounced SPDT switch]
 
|
 
|
 
|
 
|
<!--------------------------------
+
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[[]]
+
|[http://www.tigoe.com/pcomp/code/arduinowiring/63/ code, circuits, & construction Debouncing a digital input]
 +
|
 
|
 
|
|[[Special:Export/---]]
 
 
<!-------------------------------->
 
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[[BoostC Inline C Functions]]
+
|[http://www.eng.uwaterloo.ca/~tnaqvi/downloads/DOC/sd192/SwitchDebouncing.htmSwitch Debouncing]
 +
|
 
|
 
|
|[[Special:Export/---]]
 
 
 
<!-------------------------------->
 
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[[BoostC Explaining BoostC.h]]
+
|[http://www.ganssle.com/debouncing.htm A Guide to Debouncing]
 +
|
 
|
 
|
|[[Special:Export/---]]
 
 
 
<!-------------------------------->
 
<!-------------------------------->
 
|-valign="top"
 
|-valign="top"
|[[BoostC Wiki Help Needed]]
+
|[http://www.ganssle.com/articles/adbounce.htm Smoothing Digital Inputs There's a lot of way ways to debounce digital inputs. A few are listed in this article.]
 +
|
 +
|
 +
<!--------------------------------
 +
|-valign="top"
 +
|[http://www.elexp.com/t_bounc.htm Contact Bounce and De-Bouncing]
 +
|
 +
|
 +
<!--------------------------------
 +
|-valign="top"
 +
|[]
 +
|
 
|
 
|
|[[Special:Export/---]]
 
 
 
<!--------------------------------
 
<!--------------------------------
 
|-valign="top"
 
|-valign="top"
|[[BoostC Explaining BoostC.h]]
+
|[]
 +
|
 
|
 
|
|[[Special:Export/---]]
 
 
 
<!--------------------------------
 
<!--------------------------------
 
|-valign="top"
 
|-valign="top"
|[[BoostC Explaining BoostC.h]]
+
|[[BoostC Inline C Functions]]
 
|
 
|
 
|[[Special:Export/---]]
 
|[[Special:Export/---]]
 +
 +
<!-------------------------------->
 +
  
  

Latest revision as of 15:04, 3 January 2013

Debouncing[edit]

under construction

Debouncing is used on switches that are providing digital input to a device like a micro controller – here we will assume that the input is a micro controller. When the state of the switch is changed from open to closed and vise versa there is often a short period of time when the switch make many rapid transitions between open and closed. These transitions are called bouncing and they often cause problems in the application where the assumption is made that actuating the switch once caused only one transition. Getting rid of the effect of the transitions is called debouncing.

There are two general way of getting rid of the bounces, one called hardware debouncing add circuitry that actually gets rid of the unwanted transitions, the other is called software debouncing and causes the application to ignore the bounces.

Note: if the button press triggers an interrupt then the bounce may cause more problems than code that just polls the button state.

Method 1: Ignore it[edit]

This is actually a method that can work under some conditions. Suppose you have a lid you want opened when a button is pressed. Bounce may not matter for a couple of reasons: the lid can only be opened once so a bounce will not open it twice ( but bad code may be confused by the bounce ), the delay involved in opening the the lid will give time for the bouncing to end.

Method 2: Do not Ignore it[edit]

Fix in hardware, software or both.... more comming, but see links for now


Links[edit]

What Comment Comment2
A Guide to Debouncing Good guide
Contact Bounce and De-Bouncing
How to de-bounce a switch using CMOS & TTL
Switch Debouncing
Debounce Code – one post to rule them all
Basic IO: Button Debounce
Button Debouncing
Debounce
Switch Debounce Code
Tutorial 10 for Arduino: Interrupts + Debouncing [
Tutorial 15: Debouncing a button
Roguescience Arduino Tutorials 127.0.0.1 4.2 Pull-up/down resistors, debouncing
debounced SPDT switch
code, circuits, & construction Debouncing a digital input
Debouncing
A Guide to Debouncing
Smoothing Digital Inputs There's a lot of way ways to debounce digital inputs. A few are listed in this article.