Debouncing a switch

Thread Starter

tpny

Joined May 6, 2012
220
How do I debounce the pushbutton switch in these 2 configurations:

1. npn is normally on
Rich (BB code):
vcc
|
|
|----/\/\/\----npn
|
|
switch (normally off pb)
|
|
gnd
2. npn is normally off
Rich (BB code):
vcc
|
|
switch (normally off pb)
|
|
|----/\/\/\----npn
|
|
gnd
Thank you!
 
Last edited:

SPQR

Joined Nov 4, 2011
379
Hi,
A few months ago I was bouncing around :D with the same problem.

THIS is a nice site that studied debouncing. (pdf format)

THIS site talks about hardware debouncing.

I ultimately chose a Schmitt trigger.
 

Thread Starter

tpny

Joined May 6, 2012
220
Hi,
THIS site talks about hardware debouncing.
I think figure 2 in this link is a bit incomplete.. I would think there should be a resistor between the cap and ground when the switch is ON..

I ultimately chose a Schmitt trigger.
What's a schmitt trigger? And why did you choose that over an rc debouncer for example?
 

tshuck

Joined Oct 18, 2012
3,534
I'm not sure that a Schmitt trigger alone would help unless you have really fast bounce....you'd need some sort of delay(the Schmitt trigger has a small delay, though not usually enough), usually in the form of charging a capacitor when the button is pressed...

It can also be done in software with a digital circuit...

Below is a rather good reference for debouncing...
http://www.all-electric.com/schematic/debounce.htm
 

SPQR

Joined Nov 4, 2011
379
I think figure 2 in this link is a bit incomplete.. I would think there should be a resistor between the cap and ground when the switch is ON..


What's a schmitt trigger? And why did you choose that over an rc debouncer for example?
HERE's a Wiki on the Schmitt trigger.

It's just a way of of assuring a fixed output (hi or low) for voltages above or below a certain thresshold.

So you can have a noisy low signal, or high signal (just like bounce) and it will be ignored until the voltage reaches a certain thresshold.

There was no rational reason for the choice other than my switches were far away from the circuit board, and an IC would fit nicely on the board.
It worked very well - just beginner's luck.
 

tshuck

Joined Oct 18, 2012
3,534
You can have bounce that transitions between valid logic levels, even for a Schmitt trigger... that's the problem....
 
Last edited:

John P

Joined Oct 14, 2008
2,026
Trick question, right?

I don't see why you care about debouncing the switch in either of those diagrams. The function of the switch appears to be short circuiting the power supply, and it'll do that quite effectively without getting into anything complicated.

(Grin)
 

tshuck

Joined Oct 18, 2012
3,534
Trick question, right?

I don't see why you care about debouncing the switch in either of those diagrams. The function of the switch appears to be short circuiting the power supply, and it'll do that quite effectively without getting into anything complicated.

(Grin)
Ha, I didn't even look at that, I just answered the generic debounce response :D
 

Thread Starter

tpny

Joined May 6, 2012
220
Yes, those diagrams are incomplete as shown, I merely wanted to indicate where the switches will be placed.. But indeed you would need to add a resistor along with the switch to avoid shorting, I left that out because I wanted to get ideas about where one might place the cap and resistor(s).

I think this is one way solve the debounce problem:
Rich (BB code):
vcc
|
resistor
|
|----------/\/\/\----npn
|        |
|        |
|      resistor
pb      |
|       cap
|        |
gnd    gnd
Rich (BB code):
vcc
|
|
switch (normally off pb)
|
|
|----/\/\/\--------npn
|                  |
|                  |
resistor       cap
|                  |
gnd             gnd
 

THE_RB

Joined Feb 11, 2008
5,438
Rich (BB code):
vcc
|
|
switch (normally off pb)
|
|     resistor2
|----/\/\/\--------npn
|                  |
|                  |
resistor1      cap
|                  |
gnd             gnd

That is the correct way.

Ideally the pulldown (or pullup) resistor1 should be a few times smaller in resistance than the RC filter resistor2, this gives symmetrical debouncing times for OFF->ON and ON->OFF times.
 

John P

Joined Oct 14, 2008
2,026
That may work adequately, but I'm still not satisfied. What any RC circuit will do is slow down transitions, but there will still be transitions--as the transistor turns on, or off, a glitch on the input may get carried through to the output. What really works is a circuit with hysteresis, where small glitches can't get through. You can build it with 2 transistors, or use an IC like the 74HC14. Alternatively, use a flip-flop with a double-throw switch, where the switch must make a new contact to cause a change in the output.

If you must do the job with an RC circuit, I can imagine trying to design it so the initial operation of the switch occurs when the transistor is fully on or fully off, so there's no chance of transients carrying through to the output. That says that the circuit with the capacitor on the transistor base isn't the way to do it, because that cap will only charge up to Vbe, and as soon as it drops, the circuit is vulnerable to transients. But maybe it's "good enough".
 

thatoneguy

Joined Feb 19, 2009
6,359
I try a different switch. Then I go to fix in software, but if software limited, an RC circuit with a time constant of about 10mS tends to correct most issues (though it's ugly and adds a lot of parts). If not, using a Schmitt trigger input in addition to a small R/C circuit tends to eliminate all but the most severe bouncing. It also is the most spendy option, short of a debouncing IC. Debouncing IC is best described as a non-retriggerable one shot.

When choosing switches, some are advertised with their expected bounce times or "bounce free", test first. :)

Responding to the input instantly is easy, the hard part is deciding if trailing pulses are additional button presses or bounce. As noted in the articles above, most switches bounce more in the on-off transition than in the off-on transition.

De-bouncing for longer than 1/15th of a second (~65mS), people will notice if they are trying to push buttons fast, such as on a keypad. I've been very frustrated entering my discount code at Walgreen stores since I tend to type quick, it misses 1 or 2 of the 8 numbers, so don't go too far in a debouncing quest like the makers of those terminals did. Seems like they want 1/4 second between each keypress, which is annoying.
 

THE_RB

Joined Feb 11, 2008
5,438
...
If you must do the job with an RC circuit, I can imagine trying to design it so the initial operation of the switch occurs when the transistor is fully on or fully off, so there's no chance of transients carrying through to the output. That says that the circuit with the capacitor on the transistor base isn't the way to do it, because that cap will only charge up to Vbe, and as soon as it drops, the circuit is vulnerable to transients. But maybe it's "good enough".
The button turn-on glitches are fully safe as there is no way the initial button debounce can get >0.6v Vbe because it will take some time before the cap can charge anywhere near 0.6v.

That's a valid point you made about the turnoff, but it doesn't seem to be a problem in real life. I think this is because the 0.6v Vbe is not like a comparator threshold that is very sensitive to the mV, but is more like a fuzzy zone of about 0.15v, which still takes a finite time for the cap to discharge before the transistor can start to turn off. Also the button bounce on turnoff is very little and any bounce is likely to be very high speed, occuring before the transistor turns off.

You could extend the turn-off delay if needed by adding another resistor between the cap and the base.
 
Top