October 5, 2009
Jack Ganssle entitled "A Guide to Debouncing" a while back. Jack offers some great advice on the much ignored subject of debouncing inputs. He has another related article called "Smoothing Digital Inputs" which also might be of interest.
Often when I am experimenting with microcontroller designs, I need a few switch inputs (as we almost always do). I usually make it a practice to lay down on the proto-board some type of hardware debouncing similar to what Jack describes in his article. However doing so does take up some valuable real-estate on my breadboard. Furthermore it also takes some time to lay that circuit down. Even though it is nothing more than a simple gate, capacitor, 2-resistors and diode, it does take some time to do it and sometimes I make mistakes...further adding to the time to wire-it up and taking away from the time I have to actually work on what I wanted to.
Borrowing from some good software "re-use" ideas, I figure I could also do the same thing with hardware right? I always build the same debouncer (generally) so why not have a "debouncer module" I could slap on my breadboard whenever I need one? It seemed like a good idea so that's what I set out to build. So I decided to bust out my copy of EagleCad and just draw one up, layout a suitable PCB and have it made.
Sometimes I simply include a software-only debouncer for all mechanical inputs because it is good practice to do so, but sometimes I either don't feel like including the software, I don't have the code space for the debouncer or I just want to quickly try some things out without writing (or copying a bunch of code). Besides it's much easier to slap this module on my breadboard, hookup power and away I go. Once I have had a chance to prototpe the idea I can later either integrate a specific hardware debouncer, software debouncer or both. However while prototyping (when I am at my most inspired state) I can not worry about these details and just re-use this module when I need some inputs.
Overall the circuit design is not too complicated at all. Jack's article does a great job explaining the details so I'll just hit the highlights of my specific design here. The circuit shown below describes just one of the six push button RC-debouncers. The PCB layout of all six are the same however. Obviously a total of six debouncers were implemented on the board since there are six-inverters available on a single chip. A complete schematic can be found by clicking here.
I chose to implement the what I call the "uber"-debouncer which includes the diode (D1) that eliminates R2 from the charge equation. This is necessary due to the hysteresis characteristics of the CD40106 inverter. I chose the CD40106BC Hex Schmitt Trigger device instead of the 74AHCT14 in Jack's article. Why? Well that's what I had laying around. Plus I like the fact that the supply voltage is very flexible. So I can use this in different applications from 3V-15V instead of being limited to just 5V. But since these parts (and many others) are pin compatible, any other version can easily be substituted. The CD40106BC has a worst case input hysteresis of about 1V at any input voltage. At Vcc=5v the worst-case negative going threshold is 2V (Vt-), while the worst-case positive going threshold is 3v (Vt+).
The nice thing about having 6 debouncers on board is that if desired you can always change the RC values of anyone of them to just about any bounce rejection time needed. I chose R1= 270k, R2=220k, and C1=0.1uF. This configuration results in a debouncer which rejects anything less than 20.2 msec when the button is pressed, while also rejecting anything less than 32.3 msec when the button is released (worst case). However it is possible to make all six have different debounce configurations by changing the resistor and/or capacitor values of each block.
One modification to the original circuit was to place a 330-ohm resistor on each of the inverter's outputs. This might be overkill but its nice to include those when you can. Just in case someone ties these outputs to ground they wont sink more than 15ma @15mA with the 330-ohm resistor in place.
I also decided to make this mostly a SMT board. Why? Well I wanted to experiment with hand soldering SMT devices. Plus it makes for an overall much smaller board (which was the main point from the beginning). I was really surprised how with just a little patience (and a steady hand) those SMT devices really are not that difficult to solder. Since this board is pretty simple I would recommend using it if you are ever interested in experimenting with SMT yourself. You'll be surprised how easy it is to work with. The board and parts are cheap, so if you make a mistake or burn the board to badly just try another.
Below is a table of the parts you would need to populate the board if you make the same one I did. To make things easy, you can order all the parts for this board from Mouser Electronics using the EZBuy link. Total cost for all parts to make one board is less than $5. The PCB can also be ordered directly from BatchPCB as I have made this design public for anyone to grab for $7.50. I like to use BatchPCB for my PCB builds because they are inexpensive, high-quality and turn around time is decent as the stuff I work on with my hobbies are not that time critical. Although I have also posted source EagleCad schematic and board files as well as the gerbers if anyone wants them to modify or fabricate elsewhere.
Eagle 3D Images