Debouncing Circuits

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.

System boards will be able to capture some fluctuations before the actual change occurs. The yellow line is the button voltage state, the blue line is the measured digital logic reading. Image from learn.digilentinc.com.

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.

This is what a button press looks like on an oscilloscope, but it’s not so clean looking if we zoom in… Image from learn.digilentinc.com.
A zoomed in view of what actually happens when a button is released. Image from learn.digilentinc.com.
After we add an RC filter to our circuit, the button press waveform is a much smoother transition. Image from learn.digilentinc.com.

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.

Be the 1st to vote.

About James Colvin

The biggest thing that I enjoy is learning new things. Especially things involving some type of technology; computer components, fun gadgets, games, coding techniques, etc. I love spending time with my wife and our two sons and hanging out with our friends. During my normal work day, I manage the Digilent Forum and the North American Support team.

View all posts by James Colvin →

2 Comments on “Debouncing Circuits”

  1. 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.

  2. Hi Karl,

    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?

    Thanks,
    James Colvin

Leave a Reply

Your email address will not be published. Required fields are marked *