Debouncing a switch

Discussion in 'General Electronics Chat' started by tpny, Dec 6, 2012.

  1. tpny

    Thread Starter Member

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

    1. npn is normally on
    Code ( (Unknown Language)):
    1.  
    2. vcc
    3. |
    4. |
    5. |----/\/\/\----npn
    6. |
    7. |
    8. switch (normally off pb)
    9. |
    10. |
    11. gnd
    12.  
    2. npn is normally off
    Code ( (Unknown Language)):
    1.  
    2. vcc
    3. |
    4. |
    5. switch (normally off pb)
    6. |
    7. |
    8. |----/\/\/\----npn
    9. |
    10. |
    11. gnd
    12.  
    Thank you!
     
    Last edited: Dec 6, 2012
  2. SPQR

    Member

    Nov 4, 2011
    379
    48
    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.
     
  3. tpny

    Thread Starter Member

    May 6, 2012
    216
    0
    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?
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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
     
  5. SPQR

    Member

    Nov 4, 2011
    379
    48
    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.
     
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You can have bounce that transitions between valid logic levels, even for a Schmitt trigger... that's the problem....
     
    Last edited: Dec 6, 2012
  7. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    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)
     
  8. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Ha, I didn't even look at that, I just answered the generic debounce response :D
     
  9. tpny

    Thread Starter Member

    May 6, 2012
    216
    0
    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:
    Code ( (Unknown Language)):
    1.  
    2. vcc
    3. |
    4. resistor
    5. |
    6. |----------/\/\/\----npn
    7. |        |
    8. |        |
    9. |      resistor
    10. pb      |
    11. |       cap
    12. |        |
    13. gnd    gnd
    14.  
    Code ( (Unknown Language)):
    1.  
    2. vcc
    3. |
    4. |
    5. switch (normally off pb)
    6. |
    7. |
    8. |----/\/\/\--------npn
    9. |                  |
    10. |                  |
    11. resistor       cap
    12. |                  |
    13. gnd             gnd
    14.  
     
  10. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305

    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.
     
    SPQR likes this.
  11. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    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".
     
  12. sheldons

    Active Member

    Oct 26, 2011
    616
    101
    heres a couple of 4093 based circuits......
     
  13. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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.
     
  14. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
     
Loading...