By Cameron Burge | Oct 8, 2013
We press mechanical buttons hundreds of times a day on our cellphones or computer keyboards, and we take for granted that the desired action occurs imperceptibly quickly and only once. This behavior only occurs because of good engineering practices where mechanical switches are debounced.
What is switch debouncing and why is it needed? When a common mechanical push-button switch is pressed two electrical contacts are forced together forming a low impedance path for current to flow. The problem that arises is that the contacts do not go from a state of no contact to contact cleanly. The contacts rub against each other and bounce off each other several times before coming to rest against each other.
A common switch topology is shown below, along with the resulting voltage waveform that is produced when the switch is pressed. This switch completed essentially all bouncing after only 100 microseconds, but other types of switches can bounce for many tens of milliseconds. A fast processor sampling the switch waveform would see several transitions even though the user only pushed the button once. Switch debouncing in an electronic design ensures that the device that is sampling the switch waveform does not misinterpret a single button press as many.
There are many different ways to accomplish switch debouncing in both hardware and software. The best debouncing solution depends on numerous factors such as the application’s cost, size, processing power, environment, and type of switch.
Common Debouncing Schemes
RC Filter Debouncing
One of my favorite debouncing techniques is using a RC filter, as shown below. The RC filter slows down the signal transitions generated by the switch so the each button press gives one slow edge. It is usually best to follow the RC filter stage with a Schmitt trigger buffer.
Although this is a high part count solution to debouncing, it offers a lot of flexibility. The RC filter is easy to tune, which can be useful if the pushbutton is located off board and the button type is unknown. It is also easy to add level translation, ESD protection, and over-voltage protection to this circuit with just a few additional parts.
Integrated Circuit Solutions
Another way to debounce switches in hardware is to take advantage of application-specific integrated circuits. Semiconductor manufacturers such as Maxim Integrated offer switch debouncers like the MAX6816 in very small packages, with built-in ESD protection. These parts cost a few dollars, depending on the purchasing volume. Although they are extremely easy to use, they are more expensive and offer less flexibility and customization than designing your own RC filter.
If you’d prefer to debounce a switch with software, one of the most basic methods is the counter method. The idea is to sample the switch’s waveform at periodic intervals, such as once every millisecond. Every time the signal is sampled in the active state the counter is incremented, and otherwise the counter is cleared. Once the counter reaches a certain threshold the switch is considered to have been pressed. Since the debounce time becomes the product of the sampling period and the counter threshold, it is easy to adjust.
Software Shift Register
Switch debouncing can also be accomplished in software by using the shift register method. Similar to the counter method, the switch’s waveform is sampled at periodic intervals. The sampled state is then clocked into a shift register. The contents of the shift register are compared to a set pattern or hexadecimal value to determine whether the button is depressed. The hexadecimal value can be used to adjust the debounce time. For example, if the value 0xF000 is compared to the contents of a sixteen bit shift register, only 12 subsequent zeros need to propagate through the shift register. The shift register method is also well suited for use in FPGAs.
These methods should give you some ideas for how to implement switch debouncing for your next electronic product design. They should also give you a whole new appreciation for what goes on the next time you adjust the volume on your car stereo!
Nuvation provides the full range of electronic design services to bring products from concept to market for our clients. Contact Nuvation to learn more about the services our skilled engineering and manufacturing teams offer.