How to Debounce a Mechanical Contact or Switch
More Involved Debouncing Circuits
A set-reset (SR) latch or a D-type flip-flop can be used to eliminate contact bounce. However, to do so requires an SPDT or changeover switch which is more expensive than a basic SPST pushbutton. Note that this method can be implemented easily in software if you are willing to sacrifice two pins per SPDT switch.A one-shot multivibrator or timer can be a solution but will produce a pulse instead of a steady level.
Special debouncing ICs exist. A classic is the MC14490, but there are others like the MAX6816 (multiple channels MAX6817 & MAX6818) or the LTC6994. The company LogiSwitch seems to try to make a living out of debouncing. Furthermore, Maxim offers so-called contact monitors that do debouncing. The advantage of debounce ICs is that they can pack more than one channel in a single device and that they may add features like overvoltage and ESD protection. Their main inconveniences are, of course, extra cost and board space.
Debounce in Software
The reason to debounce in hardware usually is because, for some reason, it cannot be done in software. Yet in many microcontroller-based applications the MCU has ample resources to take care of debouncing. But how? Use polling or interrupts?When polling the MCU checks the contact input on a regular basis. This can be done under timer control or whenever the MCU has time for it. Polling may miss contact state transitions when they are too short or detect them late (high latency), but it does not really interfere with time-critical processes.
Interrupts, on the other hand, can detect contact state transitions almost as soon as they occur (low latency), resulting in a responsive system. However, when the MCU is fast enough, it may trigger several times due to contact bounce and hinder time-critical processes, produce false positives or both. Disabling pin interrupts during the bounce phase may help here.
Never say never
Some people say that you should never connect a switch to an interrupt pin because the bouncing may disturb the interrupt input’s internal logic (or some other reason). This is, of course, nonsense as it all depends on the application. If contact bounce can lock up a system, then EMI and other noise can do so too, and so noise filtering must be added to such systems anyway. Most, if not all modern microcontrollers have glitch filters on their inputs. If this is not enough, insert a noise filter between the contact and the input pin.Read full article
Hide full article
Discussion (1 comment)