Debounce matrix keypad

Thread Starter

diamondman

Joined May 23, 2010
19
I have been a C++ coder for some time now, but i wanted to get into some hardware, and after taking a digital logic class in college i found the transition between code and digital components quite easy, however I still suck at analog so that is partially my problem.

My project I am working on is a 4 pin security system and i need the input from the keypad to be bounce free(for obvious reasons). I found this site and it seems to present an easy enough solution (for someone who sucks at analog circuits like me) for debouncing a push button. Unfortunately, I don't know if this circuit will work with a matrix keypad the same as it would with normal push buttons or switches, if i have to do something special, or if i am completely SOL. Thanks to replies in advanced.

Also, I have seen some posts of people suggesting pics to decode and debounce the matrix outputs automatically, but for now i am trying to get everything working using only gates, (de)multiplexers, latches, etc.. (It would kind of defeat the point to have a state machine made out of gates and latches get it's info through a microcontroller)
 

beenthere

Joined Apr 20, 2004
15,819
Keypads only make a single contact at a time. The dual NAND debouncer requires the switch input to be a SPDT type.

One dodge for the keypad is to use a Schmitt trigger gate. The keypress can discharge a capacitor through a resistor to suppress the bounce, and the Schmitt trigger will signal on the absolute voltage change.
 

jpanhalt

Joined Jan 18, 2008
11,087
Here is another method from an MIT site for push button switches:


Unfortunately, the original link is dead, so here are notes copied from when it was up.

Source: http://www.mitedu.freeserve.co.uk/Circuits/Switching/debounce.htm

Design :Andy Collinson

Using a 555 timer as a monostable circuit, it is easy to build a good switch debouncer circuit. There are many circuits for SPDT debouncing, but not many for a normally open, push-to-make press button switch (PBS). The 555 monostable gives an output pulse of around 20 msec with component values shown. The formula for determining the output pulse is:

tout = 1.1 R1 C1

With the values in my circuit this equates to:

tout = 1.1 x 1.8x106 x 10x10-9 = 0.0198 sec or 19.8ms

The 555 circuit can be re-triggered if the input is held low longer than the output pulse. To prevent this happening, I have included a further timing circuit comprised of the 1Meg resistor and 47n capacitor. Normally, the 47n capacitor is discharged via the 1 Meg resistor. When the switch is pressed the capacitor quickly charges and provides a brief negative pulse to the 555 input. When the capacitor is fully charged, the potential across the voltage divider formed by the 10k and 1Meg resistors is insufficient to retrigger the monostable. Releasing the switch quickly discharges the capacitor. The output of a 555 monostable is suitable for connecting to TTL and CMOS logic circuits.
I have used it on a few projects and like it.

John
 

Thread Starter

diamondman

Joined May 23, 2010
19
One dodge for the keypad is to use a Schmitt trigger gate. The keypress can discharge a capacitor through a resistor to suppress the bounce, and the Schmitt trigger will signal on the absolute voltage change.
That is why I am trying to use the schmitt trigger because from what i have found it is the simplest way to do it, and I have the equations to calculate the resistor values I would need based on the voltages i want to occur over the capacitor, i just don't know if hooking up each output pin from a matrix keypad to it's own debounce circuit and then putting those debounced outputs into the rest of the logic circuit will work just like using 12 push buttons with 12 individual debounce circuits.

This should clarify. Will this diagram i made work to debounce all 7 outputs from the matrix so i can use them for Boolean logic.


Here is another method from an MIT site for push button switches:

Unfortunately, the original link is dead, so here are notes copied from when it was up.

I have used it on a few projects and like it.

John
Also, thanks for the help, but I looked into using a 555 timer, but I would have to use 7 separate 555 times because i am debouncing 7 outputs (Unless I am completely wrong) and would then be having the same problem i am now, except with your 555 timer circuit.
 

Attachments

rjenkins

Joined Nov 6, 2005
1,013
If you are reading the keypad in software, just copy the last read value to a temp location before each new read and compare the two.

Only use the new value once there have been no changes between reads for eg. 10mS. That guarantees you only use valid states and any transients are ignored.

If working in hardware, at some point you must be generating an 'any key pressed' signal to latch the key into the logic.

Use a similar principle on that, an R-C delay and a schmitt trigger so the data latch signal does not occur until the key bounce has had time to settle.
 

Thread Starter

diamondman

Joined May 23, 2010
19
The point of the project is to do it with no software, all with basic digital components (Nothing more complicated than a shift register or a decoder), and whatever analog components i need to clean things up. I am just gonna order the parts to do that schematic i made and update on how it works out.
Wish me luck.
 

John P

Joined Oct 14, 2008
2,025
This contact debouncing stuff is a bugaboo that doesn't have to exist. It's only a problem if you use the contact closures (or openings, perhaps) to trigger events. If you arrange things so that the buttons are read according to a clock, and if you set the time of that clock to be longer than the maximum bounce time, you never need to worry. The data sheet for that keypad lists it: maximum bounce time, 12msec. Just read slower than that, and you can ignore the issue.

I'm editing this after a minute to add: I really think you do have to run this device with a clock. How can you read a matrix on a static basis? Well, I can imagine pulling up each column to Vcc through a different resistor, and pulling down each row to Gnd through another different resistor, and then looking for deviations from Vcc and Gnd on those lines (actually maybe only the rows, or only the columns, need to have different resistors--some could be the same) but then it's an analog design project. You'd need a lot of comparators.
 
Last edited:

Thread Starter

diamondman

Joined May 23, 2010
19
Thanks both of you.
First off, I do have a clock (33 khz) running the state machine that does the necessary things with the data in the four 4bit shift registers. the registers have to be shifted only when there is a button press, so i didn't want to hook them to the main clock. Instead I am made a logic circuit (diagram as of yet) that with turn on a bit (1-4) based on which buttons are pressed (eg. 0001 for 0, 0010 for 1 etc. I am using 0001 for 0 because the machine initializes with all registers at 0 and i want '0000' to be a valid pin so i am treating the register's state 0000 as NULL) and then have an OR gate checking if any of the bits are high and clocking the shift registers to store them.
Because of this, I am wanting to make sure there is no bouncing because it could cause the shift registers to count several button presses and cause havoc.

And secondly... well i guess i don't have a second thing to say.

Anyways, I would like to thank you all. I will post the results when i finalize my part list and the parts come in. (Special thanks to beenthere for the link)
 
Top