Wednesday, November 25, 2009

LCB #1. HOW TO LIVE WITH CONTACT BOUNCE

Contact bounce is a subtle problem that can lead to unreliable circuit operation.                                  

                                                                                                                                                         Switches and relays all have one thing in common: electrical contacts that make and break a circuit. Contacts have mass, of course, and at least one of the contacts is usually mounted on a springy strip of metal so that it provides “wiping” action and allows overtravel.

Some simple things aren't so simple......Because the moving contacts have mass and springiness, they will bounce as they make and break. For example, when a SPST normally-open pair of contacts is closed, the contacts will come together and bounce off each other several times before finally coming to rest in a closed position. This is "contact bounce". See Figure 1. Note that contacts can bounce on opening as well as on closing, but bounce is usually much worse upon closing.  However, NEVER assume that contacts don't bounce when opening.



The duration of the bounce will vary depending of the design and physical variables of the device. A small, high-speed reed switch, for example, will settle in a few milliseconds; a large contactor may take 10 ms or more. With some switches, such as cheap doorbell buttons, the “human factor” may result in erratic opening and closing as long as a person is touching the button.

The Problem
If you want your switch or relay to simply turn on a lamp or a motor, then contact bounce is usually not a problem. But if you are using a switch or relay as input to a counter, toggle flip-flop, one-shot, or similar device, then you must consider contact bounce. This is necessary, of course, because a digital circuit can respond in microseconds. For example, suppose you want to count widgets as they go by on a conveyor belt. You could set up a mechanical arm that activates a switch at the input of a digital counter. What you might see is that the first widget produces a count of 12, the second widget produces a count of 21, and so on. This would occur because the contacts bounce each time the switch is activated.


The Wrong Solution
There are several ways to solve the problem of contact bounce (that is, to "debounce" the input signal). A common debounce circuit for a switch is shown in Figure 2A. It attempts to use an RC delay to swamp out the bounce from a N.O pushbutton. Resister R1 is the pullup resister. R2 and C1 are chosen so that the time constant is longer than the expected bounce time. An R x C value of about 0.1 seconds is typical. An inverting buffer follows the switch to produce a sharp transition.




 The above circuit is often used; however, it does NOT provide protection against contact bounce. Even if the RC time constant is made extremely long, it is always possible that a particular sequence of bounces will cause the voltage at B to fall and then rise, crossing the voltage threshold and producing a spurious output pulse. Even a slight wiggle of a fraction of a millivolt is enough to cause a rogue pulse.  See Figure 2B.







 


The Correct Solution
For this circuit to work reliably, you MUST use a Schmitt Trigger buffer or gate; one that includes hysteresis. An inverter with input hysteresis will output a LOW when its input exceeds a certain threshold.   However it will not go HIGH until the input drops to a second, lower threshold.  Gates with hysteresis have "snap" action and are invaluable for eliminating spurious pulses when an input is noisy or "squaring up" a signal that changes very slowly.  A CMOS gate such as the 4584 inverter has a hysteresis voltage (the difference between the two thresholds) of about 7-10% of the supply.

By adding hysteresis as in Figure 3A, you can guarantee reliable operation by choosing a time constant large enough so that the ramp time from the lower threshold to the upper threshold exceeds the longest time period that will ever exist between two bounces. In this way, the inevitable transitions that occur during the bounce interval cannot produce a spurious output pulse. See Figure 3B.



The voltage at point B produces a HIGH transition when it drops below the lower threshold. However, even if it rises again due to bounce (as shown), with the addition of hysteresis the output will not go LOW unless the voltage at B rises all the way past the upper threshold and then drops below the lower.  By incorporating a suitable time delay, this cannot occur.  


Another Good Solution
A second debouncing approach is shown in Figure 4.  It requires a SPDT (“form C”) switch, but it provides reliable switch interfacing without the debounce delay required with a SPST switch. It uses a cross-coupled latch made from a pair of NAND gates, an SR flip-flop, or other gate combinations.

If the switch is in the upper position, Q must be high since one of gate A’s inputs is LOW. Since both of gate B’s inputs are HIGH, not-Q must be LOW. The flip-flop will be stable in this state, even if the upper switch contact should be broken.

However, if the switch wiper touches the lower contact, not-Q is forced high. Now both of gate A’s inputs are HIGH, so Q goes LOW and, in turn, not-Q goes HIGH.. The flip-flop is, again, in a stable state and will remain in this state until the upper switch contact is made again.

Because of this bi-stable characteristic, switch bounce has no effect. If noise should produce a temporary LOW on the HIGH input, the flip-flop will not change state because the other input is held LOW with the switch contact; this prevents the flip-flop from changing state.  IMPORTANT: Note that such a noise pulse will be seen as a temporary HIGH on one output; this may cause an error. For this reason it may still be necessary to filter and otherwise condition the input lines.



CAUTION: This paper discusses contact debouncing, but it does not address two absolutely crucial aspects of interfacing to switches and similar devices. One concerns the need for adequate current and voltage so that the switch contacts remain “clean’ and free of oxides and insulating films. The second issue relates to the need to provide protection against noise and destructive transients that can be coupled to inputs. The circuits described here are only suitable for operation with very low current, “dry” switches such as reed, keyboard, or small “tactile” switches; also, these must be located very close to the circuitry to minimize noise problems. Toggle switches or pushbuttons must have gold contacts and be rated for very low power, such as “0.4 VA”. Typical logic voltages and pull-up resistors will not provide enough voltage and current for reliable operation of switches with higher ratings, such as “6 A, 120VAC”. These switches have contacts which are prone to oxidation, and low voltages and currents may not burn through the insulating oxidation layer if the switch has not been operated for a long time.

Stay tuned to Larry's Circuit Blog for a future discussion of interfacing to switches, contacts, and other real-world input devices.

Followers