3 ms·
Some things I've learned in electronics: switches are noisy. They bounce. People will advice all sorts of things, like decoupling caps. I've applied these (a
by dekhn 4y ago
Some things I've learned in electronics: switches are noisy. They bounce. People will advice all sorts of things, like decoupling caps. I've applied these (artisanally) and they never make a difference (for switches) but schmitt triggers do. It was only after I looked at a switch with an oscope that it made sense, the noise is almost never due to coupling, and almost always bounce that causes the problem (assuming you're already pulling up/down the switch).
- dfox 4y agoPutting caps or even somewhat more complex networks in parralel to switches or around switches is a solution when you cannot change the rest of the system. 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).
- codebje 4y agoYou've seen the scope output for bounces: the signal will often go completely from one extreme to the other, as well as a little bit of noise just after a change. A switch might bounce a hundred times, rail to rail, taking 5ms or more to settle. A typical switch probably only bounces 1-10 times over 1-2ms, but unless you plan to test every switch and throw out the worst ones you should plan for the worst. 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.