How to implement hardware debounce for switches and relays
10 May 2021
A switch is a component that can “make” or “break” an electrical circuit, thereby interrupting an electric current or diverting it from one conductor to another. There are many different types of switches, including toggle switches, pushbutton switches, micro and limit switches, and relays. All have one thing in common: they bounce.
Ordinarily, this bounce has little or no effect on the circuit, but if the digital circuit is fast enough to detect and respond to multiple bounces, there can be serious consequences. An engineer’s task is to avoid or mitigate the effects of this bounce, or “debounce” the switch. While the industry has long practised hardware debounce, it has more recently moved to software-based debounce approaches. However, there are situations where hardware debounce is a better option.
What is switch bounce?
When a switch or relay is flipped or toggled, what a human perceives as being an instantaneous single response, each time the device changes state, may actually involve 100 or more make-or-break actions, that persist for several thousandths of a second before the contact finally settles in place.
For example, consider a single pole, single throw (SPST), normally open (NO) panel mount toggle switch – like an M2011SS1W01 from NKK. Assume that one side of this switch, which can be considered the input, is connected to ground (0 volts), while the other side – which, in this case, is the output – is connected to a 5-volt power supply (shown as +ve), via a pull-up resistor (R1) (Figure 1).
Observe that switch bounce may occur both when the switch is activated (closed) and deactivated (opened). Sometimes, the bounces may transition all the way between the supply rails, here considered logic 0 and 1 states. In this case, these are “clean” bounces. By comparison, if the signal reaches only an intermediate voltage, these are referred to as “dirty” bounces.
In the case of a single pole, double throw (SPDT) panel mount toggle switch – like NKK’s M2012SS1W01-BC – bouncing may occur on both the normally open (NO) and normally closed (NC) terminals (Figure 2). In this case, only “clean” bounces have been shown for simplicity.
In many cases, this signal bounce duration is such that it has no effect. Problems arise when a switch is connected to a piece of electronic equipment that is fast enough to respond to multiple bounces. What is required is a way to debounce the signal coming from the switch, before it is acted on by the electronic equipment.
Read the full article in the May issue of DPA
Contact Details and Archive...