Welcome back to the Digilent Blog!
Pushbuttons are an inherent source of problems inside of sensitive circuits. Ideally, we like to think that when a button is pressed it is either “pressed” or “not pressed” without any sort of funny business. Unfortunately, as pushbuttons are a mechanical component, a lack of funny business simply isn’t going to be the case.
Both mechanical buttons and switches have an inherent problem with bouncing. This phenomenon is exactly what it sounds like: after changing state (going from on to off or vice versa) there is small amount of literal bouncing that the component experiences. While the physical material is vibrating, the voltage level of the output is affected causing the transition edges from on to off to not be as clean as we would like. Various microcontrollers and FPGAs are fast enough to capture some of these fluctuations that occur in the few hundred microseconds when it is switching state.
If the bouncing has a large enough changes, the system board may interpret them as additional button presses, which is detrimental for some types of programs. Luckily for us, we can mitigate this problem by implementing a method known as debouncing. There are many potential ways to debounce a circuit through both delaying software, a library, or hardware via something like a 555 timer, but what I will cover is using an RC circuit.
An RC circuit utilizes a resistor and a capacitor to “smooth out” voltage changes. This works by the capacitor storing up energy when the button is pressed and then slowly releasing that energy when the button is released. The resistor is there to limit the amount of current flowing in the circuit, effectively changing what is known as the time constant, tau, τ. Larger values of τ, corresponding to both larger resistors and capacitors (τ = R * C), indicate that it will take longer for a capacitor to charge or discharge. In a practical sense, the larger values of tau show that any transitions that occur will be smoothed out for a longer period of time.
While this all looks nice and theoretically helpful, when does debouncing actually come into play in our lives? One example is when you are pressing buttons on a TV remote. Nobody wants to press the mute button only to have the TV mute and then immediately unmute itself due to the button bounce, leading to awkward moments as you fumble with the remote. This is where debouncing comes in to save the day. By adjusting our resistor and capacitor values we can ensure that the changes will only be mitigated for an appropriate length of time, so that buttons can be pressed multiple times in a row without any of the intentional transitions being missed.
2 Comments on “Debouncing Circuits”
I’m not sure I’d recommend this route. Feeding analog voltages into digital CMOS inputs can consume an excessive amount of current (since at some voltages, both pmos and nmos transistors will activate, effectively creating a short). It’s easy enough to digitally debounce.
Thanks for your feedback and insight to some deeper level problems. I didn’t touch on this because I presumed that the system board would be providing the upper and lower voltage ranges for the RC circuit as well as the button, which would (ideally) be within the safe voltage range that an input pin on a chip can accept, such as between 0V and 3.3V.
Which voltages were you thinking of that would cause the aforementioned short?