by dekhn · 3y ago · 0 comments
Correct solution for this issue is debouncing logic (be it in HW or SW). But if for your application an SPDT switch costs same as SPST switch, driving an RS flipflop from that works better (less latency) and component-wise is cheaper than deboucing in HW (same amount of logic, less passives).
A capacitor resists change in voltage. Where a switch's change on the oscilloscope usually looks like a steep cliff, adding a capacitor will introduce a curve as the voltage drops. The size of the curve depends on both the capacitance _and_ the resistance between ground and the capacitor: simply adding a capacitor won't give you much of a curve because there'll be very little resistance. You also need to add a resistor to make an RC network.
To handle the worst of switches you want an RC value somewhere around 10ms. What you choose for R and C depends on any other constraints you might have, like power consumption or capacitor size.
Because the RC network slows the transition time a lot you need a Schmitt trigger to convert the slowly curving voltage change into a nice sharp input signal change without allowing noise to ruin everything.
There are other ways to deal with bounces in hardware, too: you can convert the switch's on/off signal into a pulse using a monostable circuit (eg, a 555), you can use a dedicated debounce IC, you can use a flip flop with a SPDT switch, you could blow $50 on a Hall effect switch and use an ADC.
Or you can deal with it in software, which is popular because it's typically easier to find space in a ROM than it is to find space for discrete components on a PCB.