The debounce debacle
By Bonnie Baker, Microchip Technology Inc -- EDN, October 28, 2004
Mechanical switches play an important role in many microcontroller and microprocessor applications. These types of switches are simple, inexpensive, and easy to install. But, the perceived simplicity of mechanical switches can be deceiving, and you want to keep your users happy. For instance, an annoying and poor switch implementation is a TV button that advances the channel by two or three channels instead of the intended one-channel advance. A more critical implementation might be a switch sensor that determines the status of a door. An open door may trip an alarm or motivate an attendant to check this door. False alarms can be disruptive and expensive. Some switches reside in time-critical environments, such as in keyboards, in which a quick, accurate determination of the switch position is critical.
It is easy to blame these problems on the switches, instead of on the electronics that sense the switch position. An alternative approach is to examine the dynamic characteristics of your switches and assess their environmental influences. All switches demonstrate a switch-contact bouncing action as the switch opens or closes. The switch contacts actually bounce off each other several times before the contacts settle into their final position. (If the switch position is sensitive to touch, a person who has had too much coffee could cause bouncing by inadvertently touching the switch. Switch manufacturers call this inadvertent touching "playing" with the switch.) You also need to look at environmental interference, such as vibrations or EMI. Once you evaluate these system dynamics, you are ready to design the electronics in your circuit.
You can implement the switch-interface electronics using an analog or digital option. The analog option uses an RC filter to control the bouncing signal. A digital gate with hysteresis takes the output of the RC filter and sends the switch-position signal into the microcontroller or the microprocessor. In this type of system, assume that the bounce time is slower than the RC time constant. You are probably safe if you design with a 500-msec switch-closure time. But don't hesitate to verify this timing with your switch on the bench. Switches bounce less as they open than when they close. In this configuration, the microcontroller or microprocessor receives the switch position after the switch position changes.
An alternative to the analog option is a purely digital one. A digital option is almost free, because you no longer need your external components. The analog option has the additional cost of materials, installation, and board real estate. The digital option can immediately determine whether the switch has changed. The microcontroller or microprocessor can then digitally filter the switch bounce. Think of this debounce circuit as a lowpass, or decimation, filter. The brute-force-debounce digital option uses a programmed delay time in firmware to replace the analog RC time constant.
As an alternative, you can adjust this programmed delay time by using clever programming techniques. This type of algorithm increases the value of a counter when the switch output signal is high and decreases the value of the same counter when the switch output is low. By taking multiple samples, the counter reaches its high or low range limits, which identifies the switch state. The programmer determines the number of and timing between samples. The timing of the samples should not correlate to the main frequency of microcontroller or microprocessor clocks.
Some say that paying attention to a switch's opening and closing is a lost art. If this scenario is true, evaluating all of your system's elements is a lost art as well. In the real world, electronic systems usually have a switch somewhere in the circuit. The opening or closing of a switch seldom demonstrates a clean transition. The connection consists of a series of breaks and makes before the final make or break. This bouncing phenomenon can occur several to hundreds of times before the mechanism settles. The best, most cost-effective option is the microcontroller/microprocessor approach. You can change your design as you experiment or on the fly at almost no cost.
| References |
|
-
I solved the switch debounce problem way back in 1975. I came out of the telecomunications industry where we, at that time had to interface many relay inputs to electronic circuits. When I woked for Morola, I received US Patent #4,028,560. I see many notes on how to solve the age old problem but, never see my scheme as shown in the above patent. Motorola made an CMOS IC implementing my patent.
James R. Bainter - 2005-23-3 10:29:00 PST -
Steve,
Thanks for your feedback. I did not mean to trivialization the topic. I
was intent on suggesting an easier way to deal with debounce issues. You
will still have to characterize your switch, but you will have the
option of programming and reprogramming your switch interface with very
little cost. This is opposed to taking the hardware route where rework
is required. The other part of the "free" equation is that a software
change does require time, but it will not (usually) require a hardware
change. I guess you could call this time the hidden cost, which is not
always seen by management.
Bonnie Baker - 2004-11-11 08:26:00 PST -
In your October 28, 2004 EDN column "The debounce debacle", you do
digital and firmware engineers a great disservice by trivializing their
efforts that address the problem of switch debouncing.
Debouncing switches using the digital option requires knowledge,
expertise, and time, none of which are "almost free" or even "almost no
cost" as you put it.
Steve Sanders - 2004-11-11 08:24:00 PST

















Bonnie Baker is the analog/mixed-signal-applications engineering manager for Microchip Technology's microperipherals division. You can reach her at 
