electroSome

Switch Debouncing

Contents

Haven’t you all noticed about the fact that sometimes while pressing a remote of a TV once, the channel shifts by 2 levels or more. Some may have even seen when a tuning button of an old FM radio has pressed the channel advances more than the desired. What is the reason behind it?  Have anyone thought about it?  The answer lies within the switches. The problem is ‘Switch Bounce‘.

Switch Bounce

Switch bounce or contact bounce or even called as chatter is a common problem associated with mechanical switches and relays. Switch, relay contacts are made up of spring metals which are forced to contact each other by an actuator. While they collide each other there is  a possibility of rebounding for some time before they make a stable contact. It’s similar to case of dropping a bouncing ball or basketball. The ball keeps on bouncing till it comes to rest. This case can be taken analogous to on/off of a switch. When the ball touches the ground analogous to on and when it rises to certain level analogous to off of a switch. As a result of this effect there will be on/off transitions generated as the contacts rapidly open and close.

Switch Bouncing in Pull Down Connection
Switch Bouncing in Pull Up Connection

This effect is not taken as important while doing power circuits or electrical circuits but creates a major problem while we deal with logic circuits. For example if you made a counter and it increments not by one but by any other value when you press the input switch and what if the units of increment is not uniform?

So here we have to remove bounces. And the method to get rid of such bounces is called Switch Debouncing.

Switch Debouncing

It can be implemented in 4 ways,

  1. Hardware Debouncing
  2. R-C Debouncing
  3. Software Debouncing
  4. Using Debouncing IC’s

1. Hardware  Debouncing

Hardware debouncing technique uses an S-R latch to avoid bounces in the circuit along with the pull up resistors. S-R circuit is most effective of all debouncing approaches

The figure below is a simple debouncing circuit which is often used.

Hardware Switch Debouncing

The circuit uses two cross coupled NAND gates which form an S-R latch, A SPDT (Single Pole Double Throw) switch, two pull up resistors. The resistor generates a logic ‘one’ for the gates, Switch pulls one of the inputs to ground.

If  the switch is in position as shown in figure  the output of the upper gate is ‘1’ irrespective of the input of the other gate and the one created by the bottom pull up resistor which drives the lower NAND gate to zero which in return races back to the other gate. If the switch moves back and forth between the contacts and is suspended for a while in neither region between the terminals,the latch maintains its state because ‘0’ from the bottom NAND gate is fed back. The switch may move between the contacts but the latch’s output ensures it never bangs back and thus switch is bounce free.

2. R-C Debouncing

The S-R circuit is common but the bulkiness of the circuit causes it to be used rarely also SPDT switches are costlier than SPST (Single Pole Single Throw) switch. Another method of debouncing is to use a R-C circuit. The basic idea behind such circuit is to use a capacitor to filter out quick changes in the switch signal.

RC Switch Debouncing

The basic R-C circuit used for debouncing is shown above. The circuit uses two Resistors, Capacitor, Schmidt trigger hex inverter (eg : 7414) , SPST switch.

During the bouncing condition the capacitor will stop the voltage at Vin when it reaches either Vcc or Gnd.

There will be question in every one’s mind that why a standard inverter is not used ??

We can’t use the standard inverter gate here. TTL defines a zero input when the applied voltage is in between 0 and 0.8. The output becomes unpredictable in some situations.So we use a Scmitt trigger hex inverter. The output remains stable even if the inputs vary or dither also it prevents the output from switching because of its hysteresis property.

  • To increase the circuit speed we can connect a diode across R2 thereby reducing the charging time of the capacitor as it charges only through R1 when switch is off.
RC Switch Debouncer with Diode
RC Switch Debouncer with Diode Working

 

3. Software Debouncing

Software debouncing is another method to get rid of bounces in the circuit. The basic principle is to sample the switch signals and filter out glitches if any. There are two methods for software debouncing.

The algorithm for software debouncing is shown.

Counter Method

  1. Initially set up a count value to zero
  2. Using a timer set up a sampling event with a period (say 1 ms)
  3. On the sample event:
  4. If  switch signal high then
  5. Set count=0
  6. Set internal switch state released
  7. else
  8. Increment count to a max of 10
  9. end if
  10. if count =10 then
  11. Set internal switch state to pressed
  12. end if

Shift Register Method

Similar to that of counter method.Only difference is that it uses shift register. The algorithm assumes  unsigned 8 bit reg value usually  found in microcontrollers

  1. Initially set up a shift register variable to xFF
  2. Using a timer set up a sampling event with a period (say 1 ms)
  3. On the sample event:
  4. Shift the variable towards MSB
  5. Set LSB to current switch value
  6. if shift register value =0 then
  7. Set internal switch state to pressed
  8. else
  9. Set internal switch state to released
  10. end if

4. Switch Debouncing IC

Switch debouncing can also be done by some specialized IC. They are only a few of them and rarely used.

Switch Debouncing using IC MAX6816
Switch Debouncing using LS118
Exit mobile version