Perú - Marcar Perú

Términos internacionales de comercio (Incoterms):FCA (punto de envío)
Los costos de aranceles, aduana e impuestos se cobrarán en el momento de la entrega.

Confirme su elección de moneda:

Sol peruano
Términos internacionales de comercio (Incoterms):FCA (punto de envío)
Los costos de aranceles, aduana e impuestos se cobrarán en el momento de la entrega.
Solo se aceptan pagos con tarjetas de crédito, excepto American Express

Dólares estadounidenses
Se encuentran disponibles todas las opciones de pago

Bench Talk for Design Engineers

Bench Talk

rss

Bench Talk for Design Engineers | The Official Blog of Mouser Electronics


Battling the Bouncing Button Mike Parks

Mechanical buttons and switches can present unintended input trouble for embedded electronics projects. There’s an undesired effect known as “bounce.” What is bounce? When you press a button it sometimes does not cleanly change states. There is some electrical noise generated as the button rapidly oscillates between states immediately after a button is pressed but before it settles. Think of it like pulling a mass-spring system downward, letting go, and waiting for it to settle at equilibrium. Switches and buttons oscillate similarly, though the time to settle is measured in milliseconds. Let’s take a look at bounce on an oscilloscope:

In some applications this is not a problem, however for certain applications that count button presses, bounce can cause a microcontroller to count additional presses that were not intended. Fortunately there are some techniques known as “debouncing” that can alleviate this problem. Debouncing can be achieved in both hardware and software.

Debouncing with Hardware

One of the simplest hardware solutions for debouncing is to use two NAND gates configured in what is known as a “SR latch”. Let’s take a look at the schematic below. If we consider point “X” as the “on state”, then we must decide if we want to use active-low or active-high logic. This will determine if we use Q or Q’ as the output to feed whatever circuit is downstream from the SR latch. If we want active-high (meaning there should +5V at the output when the button is pressed) we would select Q as the output pin. If on the other hand we want active-low logic (0V), then we would use the Q’ pin as our output.

Debouncing with Software

If space on your circuit board is tight and you are using a microcontroller then it is possible to write some code to handle debouncing. A popular method is to utilize a timer and basically ignore an input pin for some period of time after an initial change in pin logic level is detected. The period of time can vary, though is usually measured in milliseconds. Here is a look at one particular implementation you can use on an Arduino:

The concept of this code is not quite as complicated as it may first seem. In short, we are taking a reading of the I/O pin we are interested in. If we read the pin’s current state does not equal the pin state from the previous time through the main loop, we then take a timer reading. We then compare the current timer reading to the previous timer reading and ensure enough time has passed. You can tailor this value for your particular hardware by experimenting with the value assigned to the debounceDelay variable. 50ms is a recommended value to start with. If enough time has passed we then perform whatever action we wish to perform in response to the button press. If you understand the basic concept you can rewrite the above in whatever language you are using for your particular embedded project.

Leave us a comment down below telling us how you prefer to handle button bounce.

*** All circuits were done in the new MultiSim BLUE from Mouser and NI. Check it out at mouser.com/MultiSimBlue.



« Back


Michael Parks, P.E. is the co-founder of Green Shoe Garage, a custom electronics design studio and embedded security research firm located in Western Maryland. He produces the Gears of Resistance Podcast to help raise public awareness of technical and scientific matters. Michael is also a licensed Professional Engineer in the state of Maryland and holds a Master’s degree in systems engineering from Johns Hopkins University.


All Authors

Show More Show More
View Blogs by Date

Archives