Switch debouncing in hardware - Page 1
Forum section: electronics / beginners

author: Maxlor
author_rank: Frequent Contributor
timestamp: November 13, 2013, 06:36:22 pm
content: I've always done debouncing of switches in software, but recently I've started wondering how to do it in hardware. The accepted way seems to be to have a capacitor in series with the switch, and a pull-up resistor, like shown infigure 2.A here. Now here's the part that I don't understand: while this wonderfully debounces the switch release, I don't see how it does anything for pressing the switch. The voltage curves given indicate that the capacitor decharges slowly (same thingshown here), but it seems to me it's always decharged pretty much instantly. Oscilloscope measurements are confirming it.So... am I missing something here? Maybe some implicit element in the circuit? I understand that I could add a resistor in series with the switch, but then I'd have a voltage divider and can't get the switch output down to GND anymore.If I am right, and this does nothing for closing the switch, is there a circuit that does, yet still gives me unchanged VCC/GND voltage levels at the switch output?

author: tszaboo
author_rank: Super Contributor
timestamp: November 13, 2013, 06:47:04 pm
content: Quote from: Maxlor on November 13, 2013, 06:36:22 pmParallel.Why is it OK? Because software takes time to do it's stuff. If you have small glitches while you processing the button's press, you just dont check during that time if there was another press. At release, it is more important, because there you might re-trigger your circuit.If you really want to debounce both ways, make a 1K-10K setup. It will not violate the voltage levels, and both will be denounced. Adding a schmitt trigger is usually a huge waste of resources.

author: AG6QR
author_rank: Frequent Contributor
timestamp: November 13, 2013, 07:12:21 pm
content: Quote from: Maxlor on November 13, 2013, 06:36:22 pmThe way pushbutton switches work, a closed pushbutton may temporarily spuriously go open for a brief time while the user intends to keep it pressed. But an open switch which isn't being pressed will never go closed, not even for a brief instant. As long as the contacts are apart, they are open.You seem to be under the impression that a debounce circuit should wait for a while after switch closing before signalling a low output. That would serve no purpose except to make the system slower to respond to button pushes. The goal of debounce is just to ensure that one single transition is seen on the output.A bounce at switch pressing involves at least contact, opening, contact, in rapid succession. It might repeat many times.As you point out, the switch does discharge the capacitor very quickly, limited only by the parasitic resistance and inductance in the switch and wiring.During a bounce event, what that circuit does is prevent the very quick opening of the switch from bringing the output voltage all the way high. That way, only one transition from high to low is seen by the microcontroller.(Incidentally, good, responsive, software-based debounce can work the same way. When a button closure is sensed, react to it in software immediately, but ignore any switch openings for a time period. When an opening is sensed, wait for it to remain open for a time before reporting the open state to the software.)

author: babysitter
author_rank: Frequent Contributor
timestamp: November 13, 2013, 07:38:25 pm
content: The one and only true hardware debouncing(tm) is done with a SPDT Switch, each side connected to a RS FLIPFLOP and the common contact connected to the appropriate stimulus for the FF. The RSFF will take the state the first touching defines. It is improbable that the bounce bounces bouncy between the NO and the NC contact.

author: jimmc
author_rank: Frequent Contributor
timestamp: November 13, 2013, 09:30:55 pm
content: AG6QR has covered why a single RC network works.If you want to use an additional series resistor (it's kinder to the switch if the capacitor is large) then add it as shown in the attachment, this avoids having a potential divider.As babysitter has said the surest debounce circuit is a SPDT switch and SR flipflop, but with a correctly chosen time constant the RC network /Schmitt trigger method is reliable and has the advantage that any spikes picked up on the switch leads are filtered (especially when using the two resistor circuit).Jim

author: Maxlor
author_rank: Frequent Contributor
timestamp: November 13, 2013, 10:36:16 pm
content: Thank you for all your insights. I think I understand now the limitations and intentions involved.I experimented a bit with a couple of different PCB mount switches I found laying around. The really cheap ones are pretty awful in terms of bounce and reliability of contact. I guess you get what you pay for

author: amyk
author_rank: Super Contributor
timestamp: November 14, 2013, 09:12:28 am
content: I remember mercury-wetted contacts were used in some applications for non-bouncing switches.

author: Moshly
author_rank: Regular Contributor
timestamp: November 14, 2013, 10:12:51 am
content: Have a read of this ->http://www.eng.utah.edu/~cs5780/debouncing.pdf