Shop OBEX P1 Docs P2 Docs Learn Events
The best way to do hardware debounce? (Multi-part question) — Parallax Forums

The best way to do hardware debounce? (Multi-part question)

MarkSMarkS Posts: 342
edited 2008-02-20 15:59 in General Discussion
I've seen circuits ranging from a simple resistor to multi-component designs. I know that there are even ICs dedicated to this task. What I want to know is what methods do you guys prefer and why.

The RC circuit with Schmitt Trigger looks to be a very good method to use for my purposes (I need to debounce 4 buttons for a MENU interface). The only question I have with this method is the values for R and C. How do I calculate these?

I know that debouncing can be done in software, but where is the fun in that? wink.giftongue.gif

Comments

  • phil kennyphil kenny Posts: 233
    edited 2008-02-18 00:42
    You're right that an R-C circuit feeding a Schmitt trigger is a very reliable way to
    debounce switches, if you choose the time constant correctly.

    The R-C network timing needs to be several times longer than the expected contact
    bounce time. If you make the R-C time constant somewhere around 250 ms it
    will give a slowly changing voltage that will cause the Schmitt trigger output to
    change state as it crosses the threshold level.

    The time constant you need for a particular switch will vary, so some experimentation
    is needed. Then increase the R-C time constant to give yourself some safety margin.

    phil
  • MarkSMarkS Posts: 342
    edited 2008-02-18 01:27
    Sorry, but calculus makes my head hurt. Is there an easy way to calculate those values?
  • phil kennyphil kenny Posts: 233
    edited 2008-02-18 03:56
    No calculus involved, just simple multiplication.

    The time constant of a series R-C network is given by

    T_c = R * C

    where T_c is the time constant in seconds,
    R = resistance in ohms
    C = capacitance in Farads

    Example:

    R = 50k, C = 0.5 uf

    T_C = 50,000 * 0.5 * 10^(-6) = 25,000 * 10^(-6) = 0.025 seconds

    Post Edited (phil kenny) : 2/18/2008 3:49:48 PM GMT
  • RDL2004RDL2004 Posts: 2,554
    edited 2008-02-18 13:50
    Here is some good info:

    http://www.ganssle.com/debouncing.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • phil kennyphil kenny Posts: 233
    edited 2008-02-18 15:47
    Excellent reference in Ganssle's paper, Rick.

    Looks like my estimate of needing an R-C time constant of 250 ms
    is on the high side, for most switches. However, I noticed that one
    of the switches he tested had a bounce time of 157 ms. So perhaps
    I was in the ballpark for that one.

    phil
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-02-18 19:43
    The slowest ones I've seen have been reed switches in old irrigation flowmeters. The 2 inch long reeds needed close to 100 milliseconds.

    For most purposes, a few milliseconds will suffice. I generally use a 0.1 uF capacitor with around 20 to 50 kOhms. That is only 2 to 5 milliseconds of debounce, but it usually works fine, even directly into a Stamp pin without a Schmitt trigger. Also include a resistor between the the switch and the pin. The purpose of that is (1) to protect the pin from static electricity that might come from the outside, and (2) to limit the surge current that would flow from the capacitor through the switch. The surge current melt the microscopic contact points and eventually ruin the switch.

                                     20k
                            ,----/\/\---+Vdd
        button            |
        -\/-               |
    ,--O   O----/\/\---o-o-------- Stamp pin
    |            270         |
    |                     =====0.1uF
    |                         |
    `--------------------o--------- Vss
    
    



    You can test for bounce very effectively using the Stamp COUNT command, which is very sensitive to bounce. If it counts more than once per push, then it may need more debounce or a schmitt trigger circuit.

    That said, for debouncing pushbuttons, software can be fun too!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 2/20/2008 4:30:46 PM GMT
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-02-19 15:28
    The Art of Electronics has a discussion on debouncing and while their are many cheaper and more compact tricks, they recommend using ICs to do a proper job of it. While the schematics look simple, you still have to add a Vss and Vdd to the IC. So it starts to enlarge your project. They use a SPDT switch and a flip-flop. Say the common lead of the switch is to ground, each pole has a pullup of 1K to 5V which go to the S and the R inputs, and·the SR flip-flop outputs a clean signal.

    Apparently the BasicStamp uses another trick and just waits in software for the signal to stablize before deciding what it is. A small timed loop of reading the input 3 or 4 times may save a lot of board work.

    You do have built-in Schmitt Triggers available on the SX chips and these are in·some BasicStamps.· That would mean just providing the R and C elements and enabling the Schmitt Trigger.

    Another trick is to use a non-inverting gate or buffer WITH A WIRE from output to input·as feedback.· This requires a SPDP switch, but one·pole is Vss and the other pole is Vdd, the common is to the input.· Seems a bit curious, but the say the momentary shorting does no harm.

    Hall-effect switches seem to be the least hassle of all.· No mechanical contacts to wear out and no bounce to debounce.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PLEASE CONSIDER the following:

    Do you want a quickly operational black box solution or the knowledge included therein?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 2/19/2008 3:51:24 PM GMT
  • MarkSMarkS Posts: 342
    edited 2008-02-20 06:16
    RDL2004 said...
    Here is some good info:

    http://www.ganssle.com/debouncing.pdf

    I found that earlier, which is why I mentioned calculus (pages 15-16).
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-02-20 15:59
    Seems to me that there are a few good choices.

    1. Use a Hall Effect switch if it is at all possible
    2. If a SPST switch must be use, use a genuine debouncing IC like the 4490 'hex' contact debouncer
    3. If special and very bouncy switches are required won't behave, turn to a software solution.
    4. SPDT switches might be very appealling if you require a toggle switch, but they may be hard to come by in momentary push buttons.

    BTW, the RC time delays are indeed derived from calculus; but equations that provide estimates can easily avoid all the hassle of using calculus.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PLEASE CONSIDER the following:

    Do you want a quickly operational black box solution or the knowledge included therein?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Sign In or Register to comment.