It Is a Matter of TimeAs everything in our universe, state changes take time to complete and switches, mechanical or not, are no exception. Most mechanical switches are rather slow devices and a change of state may take several tens of milliseconds to stabilize. During the state change the contact bounces a few times, like a ball hitting the ground. Unlike a ball, bouncing also appears when a contact is opened.
Systems much faster than the switch may notice contact bouncing and be disturbed by it. As a result, instead of a single keypress the system may detect multiple presses and race through menus, leaving no chance to the user to select the desired option.
Thou Shallt DebounceDebouncing is the technique of proofing a system against contact bounce. Several methods exist, from analog RC filters through specialized ICs to software algorithms. They all have in common that they try to deliver a well-defined, glitch-free contact state to the system.
Please keep in mind that a contact can be a human-operated switch or pushbutton or a machine-controlled contact like a microswitch, rotary encoder or relay.
RC Network for DebouncingThe idea here is to connect the switch to a circuit that is even slower than the switch itself. When this circuit is slow enough, it will simply not notice the bouncing at its input. The output of the circuit is a steady state, low or high, with slow transitions in between different states. This sounds like a nice & easy solution, but there are issues:
- When the input does not have enough hysteresis and noise is present, a slowly changing signal driving a fast input can produce undesirable effects somewhat similar to contact bounce. They can also result in excessive power consumption. Schmitt-trigger inputs at the receiving end are therefore highly recommended. If they are not available, add them to your filter;
- If made too slow, short but valid state changes may be missed;
- It requires extra components that eat up board space and which cost money;
- In the common switch-to-ground-with-pull-up-resistor-and-RC-network, pressing and releasing the button do not produce identical results. Adding a diode may overcome this problem (see drawing above) but adds yet another line to the bill of materials.