Saturday, August 27, 2011

De-bouncing

Pressing or releasing a mechanical switch in general does not produce a clean edge in the output waveform
  • Digital input may interpret this as multiple edges.

  • Referred to a “Bouncing” on the input.


clip_image002
There is a hardware solution as well as a software solution for bouncing.

Hardware Solution

Use of a capacitors
clip_image004
Here R2 should be much higher than R1 and the resistance of the gate, otherwise current will not flow according to above diagram.

 

Software solution

The problem is the bouncing is taken as multiple edges. If we do not check the signal for some time, it will do the work (for this it will be T1 to T2).


clip_image006
Think we check the signal through polling, according to above paragraph we must wait() for some time when we get a change in the signal. However we cannot do that because there can be things that need a continuous attention. As an example, take a washing machine with a press button to add detergent.
Wash(){
Check water sensor; // to stop overflowing
Check detergent button;
If pressed wait(for t ms)
}
We cannot do this, as while we are waiting there can be an overflow. This problem is solved by use of threads. There will be a variable that will be checked by the main loop and there will be a separate thread for setting that variable, (all polling and waiting will happen there) OR this can be done as below.
clip_image008
Procedure for this state machine
clip_image010

Whether to use SW de-bouncing or HW de-bouncing

We know that when we are using SW de-bouncing there is overhead but if the bouncing is large or duration of it is large we cannot use a cap to handle it. Large cap will work fine but it will affect the power supply.
There are some other factors, which we will decide on:
  • Noise

  • Size of bouncing

  • Power

  • Reliability

  • Length of bouncing




Content

Email:

Syndicators/Readers:

FaceBook: