This website uses cookies primarily for visitor analytics. Certain pages will ask you to fill in contact details to receive additional information. On these pages you have the option of having the site log your details for future visits. Indicating you want the site to remember your details will place a cookie on your device. To view our full cookie policy, please click here. You can also view it at any time by going to our Contact Us page.

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.

(Image: Shutterstock)
(Image: Shutterstock)

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...

Print this page | E-mail this page