The best way to do hardware debounce? (Multi-part question)
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.gif](http://forums.parallax.com/images/smilies/wink.gif)
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.gif](http://forums.parallax.com/images/smilies/wink.gif)
![tongue.gif](http://forums.parallax.com/images/smilies/tongue.gif)
Comments
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
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
http://www.ganssle.com/debouncing.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- 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
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.
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
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?······
Post Edited (Kramer) : 2/19/2008 3:51:24 PM GMT
I found that earlier, which is why I mentioned calculus (pages 15-16).
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?······