title title title title


Debounced Switches and Buttons

Microcontroller are great, but when you need a HMI(human-machine interface) many times one uses a switch or relay (like a reed relay in a security circuit). Well, mechanical things have mass and spring constants no matter how small and the contacts bounce opening and closing the circuit for a few milliseconds. To a microcontroller, that's a long time and it will see all those false turn ons. The software solution is to watch each switch and run a routine to wait out the bounces (assuming you guessed correctly on how long that would be) and then read the switch one last time to see if the human REALLY turned it on or not. This is a lot of wasted time and complex code if the interface is busy. OR you could debounce the hardware using out-board electronics. If your design has a PCB and a panel of switches, you probably have enough room for some ICs to take care of bounce and not load the processor at all or waste its time. You get one clean switch. The R-S flip-flop works perfectly for this. It's been around since the dawn of TTL and still is very useful. The quad version is the 74HC279 chip, so you can debounce 4 switches with one chip.

What I've done here is place a 279 chip on a circuit board along with a 74HC14 hex-inverter chip to handle some LEDs, so I'll know what's going on. I use the board in conjuction with my Arduino breadboard to quickly set up manual switch inputs to the breadboard or Arduino. I added a 47uF fat cap and a little 0.1uF cap to make sure all this switching doesn't affect the 5V supply or breadboard circuits. The red LED lets me know the power is on the board. There are a set of resistors for each switch to establish a pull-up to 5V. The toggle switches provide a LOW for either position of the switch. This is done this way to match the active LOW inputs that the R-S flip-flop expects. So a LOW on the set input produces a HIGH on the Q output, and when you switch, the set goes HIGH and the reset input goes LOW, resetting the output to LOW.

There are resistors for current limiting of the LEDs. I used 680 ohms to dim-down the LEDs. I don't need a blast of light. It turns out, LEDs stay pretty bright until about 30% of their rated forward current, so why not take advange of that and save on power consumption. So +5 volts comes to the board, and a green LED means that output produced a HIGH on the outgoing cable.

You can see the debounce board operate in the 555 Timer rolling die video.