When the software debounce is not suitable, how to realize the hardware debounce of switches and relays?

In electrical and Electronic engineering, a switch is a component that can “engage” or “break” a circuit, thereby interrupting or transferring current from one conductor to another. As engineers know, there are many different types of switches, including toggle switches, rocker switches, push-button switches, micro switches and limit switches, magnetic switches and reed switches, and relays. All switches have one thing in common: they have jitter. This is how they work.

In electrical and electronic engineering, a switch is a component that can “engage” or “break” a circuit, thereby interrupting or transferring current from one conductor to another. As engineers know, there are many different types of switches, including toggle switches, rocker switches, push-button switches, micro switches and limit switches, magnetic switches and reed switches, and relays. All switches have one thing in common: they have jitter. This is how they work.

Normally, this kind of jitter has almost no effect on the circuit, but if it is a digital circuit, as long as the speed is fast enough, it can detect multiple jitters and respond to it, and cause serious consequences. The task of the engineer is to avoid or reduce the influence of this kind of jitter, or to “debounce” the switch. Although the industry has been adopting hardware debouncing for a long time, it has only recently turned to software-based debouncing. However, in some cases, hardware debouncing is a better choice.

This article explains what jitter is, and discusses software and hardware methods for debounce. Then use an example to prove that hardware debounce is a better choice, and explain how to implement this method. Finally, taking products from companies such as NKK Switches, ON semiconductor, Texas Instruments, Maxim Integrated, and LogiSwitch as examples, several specific switching devices and hardware debounce components are shown.

What is switch jitter?

When a switch or relay is flipped or toggled, or every time the device changes state, people usually regard it as an instantaneous single reaction, but in fact it may involve more than 100 engagement or disconnection actions, which last for several thousandths of a second , The contact will stabilize at the end.

For example, a single-pole single-throw (SPST) normally open (NO) panel mounted toggle switch like NKK’s M2011SS1W01. Suppose one side of the switch (which can be regarded as the input terminal) is connected to ground (0 volts), and the other side (in this case, the output terminal) is connected to a 5 volt power supply (shown as +) through a pull-up resistor (R1) ve) (Figure 1).

When the software debounce is not suitable, how to realize the hardware debounce of switches and relays?

It has been observed that switch jitter may occur when the switch is activated (closed) and deactivated (opened). Sometimes jitter may span both power rails all the way, that is, either a logic 0 or a logic 1 state. In this case, these are “clean” jitters. In contrast, if the signal only reaches an intermediate voltage, these are called “dirty” jitters.

For single-pole double-throw (SPDT) panel-mounted toggle switches like NKK’s M2012SS1W01-BC, jitter may occur on both the normally open (NO) and normally closed (NC) terminals (Figure 2). In this case, for the sake of simplicity, only “clean” jitter is shown.

When the software debounce is not suitable, how to realize the hardware debounce of switches and relays?

In many cases, this continuous signal jitter has no effect. When a switch is connected to an electronic device, if the device is fast enough to detect multiple jitters and respond, it will cause problems. What needs to be done is to debounce the signal from the switch before the electronic device responds to it.

Software and hardware debounce comparison

In the 1960s and 1970s, various hardware techniques were used for switch debounce, from simple resistive capacitor (RC) delay circuits used with SPST switches to more complex set/reset (SR) latch functions.

Recently, since many systems have adopted microprocessor units (MPU) or microcontroller units (MCU), it has become common to use software technology to eliminate signals from any switches. However, software debounce is not always the best method. There are some applications that use small, low-performance, and limited-memory processors that have limited code space and/or clock cycles and cannot implement de-jitter routines. In these cases, hardware implementation may be a better solution.

In addition, many software developers are not familiar with the physical characteristics of switches. For example, the debounce characteristics of switches may not only change in different activation modes, but may also be affected by environmental conditions such as temperature and humidity.

Software developers lack switch expertise, and the existing literature on switch jitter is often chaotic and contradictory, further exacerbating the severity of this problem. For example, we usually read that a switch stops shaking 1 millisecond (ms) after it is activated or deactivated. However, well-known embedded system expert Jack Ganssle conducted empirical tests on various types of switches, activated each switch 300 times, and recorded the minimum and maximum amount of jitter when the contacts were opened and closed. According to its report, the average jitter duration is 1.6 ms, and the maximum jitter duration is 6.2 ms. Some industrial and military “best practices” recommend waiting 20 ms after initial activation, and then assuming that the switch has stopped shaking; others advocate waiting 20 ms after the shaking is finally detected before triggering any action.

In addition, there are many simple non-processor systems that also need to eliminate switch jitter. To cite a few examples of such systems: a binary counter that drives a seven-segment Display to count pulses from a relay; a trigger input for a 555 one-shot timer used as a gate or gate motor control device; and a key-based input Registered Finite State Machine (FSM). There is also an electronic trimming potentiometer (Pot) whose value is modified with switch input (addition, subtraction, and sometimes storage). At this time, the switch jitter will be a problem.

All these examples clearly show that some knowledge of how to perform hardware debounce is useful to any designer or developer.

Use RC network to hardware debounce SPST switch

One of the simplest hardware-based switch debounce solutions is to use a resistor-capacitor (RC) network in combination with SPST switches. There are many variations of this circuit. One of the more common implementations is to use two resistors and one diode (Figure 3).

When the software debounce is not suitable, how to realize the hardware debounce of switches and relays?

When the switch is activated (closed), the capacitor C1 discharges through the resistor R2. If the diode D1 is omitted from this circuit, then when the switch is disabled (open), C1 will be charged through the resistor (R1 + R2). However, the existence of D1 means that C1 can only be charged through R1.

In some cases, people only pay attention to the activation of the switch (that is, the trigger action occurs). In this case, D1 can be omitted. However, if you want to trigger an action when the switch is activated and deactivated, and consider minimizing the delay, it is recommended to increase D1.

Observe the exponential charge-discharge curve shown by the capacitor voltage VC. Feeding this signal directly into the input of the downstream digital logic function is not a good idea, because the downstream digital logic function will not like to see a signal hovering in an undefined area between the “good” logic 0 and logic 1 values . Instead, the signal should be sent to the input of a buffer with Schmitt trigger input. In addition, an inverting buffer is usually used, such as a channel of Texas Instruments’ CD74HC14M96, because the switching speed of the inverting function is faster than that of the non-inverting function.

Debounce SPDT switch with SR latch

In the case of SPDT switching, a common hardware debounce scheme is to use SR latches. Since IBM and other companies applied this technology to the switch panel of large computers in the 1960s, this method has been regarded as the essence of simple hardware debounce solutions. This kind of latch can be formed using two back-to-back dual-input NAND gates; for example, using Texas Instruments’ SN74HC00DR four-way dual-input NAND IC with two channels (Figure 4).

When the software debounce is not suitable, how to realize the hardware debounce of switches and relays?

When the NC terminal of the switch is grounded, as shown in the upper part of Figure 4, this forces the output of gate g2 to logic 1. In turn, the two logic 1s at the input of gate g1 force its output to become logic 0s. In contrast, when the NO terminal of the switch is grounded, as shown in the lower part of Figure 4, this forces the output of gate g1 to logic 1. In turn, the two logic 1s at the input of gate g2 force its output to become logic 0s.

The reason this circuit works so well is because when both of its inputs are in the inactive logic 1 state, the SR latch will remember its previous value. Remember, as shown in Figure 2, when an SPDT switch is toggled, at that moment, no matter which terminal is grounded, it will shake. Since these dither signals are between their original value (logic 0) and the new value (logic 1), they have no effect on the current state of the SR latch. Only after this terminal stops dithering, the opposite terminal will start dithering, and then the SR latch will change its state.

Debounce the SPST switch with special equipment

One problem with the previous solution is that many designers like to use SPST switches because their cost is generally lower than SPDT. There are many well-known dedicated SPST de-jitter devices on the market, such as ON Semiconductor’s MC14490DWG and Maxim Integrated’s MAX6818EAP+T.

Another manufacturer LogiSwitch also provides a set of three-channel, six-channel and nine-channel de-jitter solutions, using both through-hole and surface mount (SMD) packages. For example, consider the circuit using the LogiSwitch LS18-S device (Figure 5).

When the software debounce is not suitable, how to realize the hardware debounce of switches and relays?

Like all members of the LogiSwitch product family, LS18-S supports an operating voltage range of 2.5 to 5.5 volts (the power supply voltage value does not affect the response time of the device). In addition, unlike some other dedicated IC solutions, LogiSwitch debounce devices do not require any additional components, such as external clocks, RC timing networks, or pull-up resistors on inputs or outputs.

LS18-S uses LogiSwitch’s proprietary adaptive NoBounce (no jitter) technology to achieve a high level of noise immunity. Disable noise spikes of less than 20 ms duration when starting or terminating a cycle, and then after the last jitter when the switch is activated and released, the output will be delayed by 20 milliseconds regardless of the jitter duration.

Concluding remarks

There are many different types of switches, including toggle switches, rocker switches, and push-button switches, all of which may jitter. If switch jitter is not alleviated, it will cause microprocessors and other electronic circuits to treat one switch activation as multiple events.

People often use the software running in the microcontroller to debounce the jitter signal sent by the switch. As mentioned above, although this is a low-cost solution, it may not be the best choice in all situations. These situations include: the system is based on a microcontroller with limited performance and storage space, software developers lack expertise in switching-related issues, or the system is implemented without a microcontroller.

As an alternative, we can use a variety of methods to debounce in hardware. Specific methods include resistor-capacitor networks, SR latches, and application-specific integrated circuits.

The Links:   PM30RMC060 LQ084S3LG02

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *