I want to build a keypad matrix to interface to a microcontroller. In order to avoid constantly polling the switches I plan to utilize interrupts, which will require hardware debouncing (I believe).
My question is how to go about debouncing a keypad matrix (4x3) in hardware. I have googled this problem but have only found software debouncing.
You aren't going to make it any more efficient by using interrupts with a matrix keypad and you are going to make your code more complex. You have to cycle through the columns anyway so just read the rows into a ring buffer at the same time and debounce in software.
Why do you want to debounce using hardware when you already have a microcontroller you are using. Doesnt make that much sense.
You dont have to KEEP polling, you only have to poll once you detect a first key press. Before that you can check for ANY key press which is much simpler because you can energize all of the scan lines at the same time. It's up to you of course.
There's also the possibility of using a second slave uC chip to scan and send the data to the master uC using any protocol you like.
I hadn't thought of that, I suppose you could use interrupts if you did it that way. The only reason I can think of that you would want to is if you were short on cycles, in which case moving to a faster chip would be my preference, but it should be possible.
Why do you want to debounce using hardware when you already have a microcontroller you are using. Doesnt make that much sense.
You dont have to KEEP polling, you only have to poll once you detect a first key press. Before that you can check for ANY key press which is much simpler because you can energize all of the scan lines at the same time. It's up to you of course.
There's also the possibility of using a second slave uC chip to scan and send the data to the master uC using any protocol you like.
I had previously thinking of using an OR gate driven by the 3 columns (3x4 keypad) to an external interrupt. That would then cause the uC to read the keypad lines and determine which button had been pressed. Is that what you are describing?
From my understanding, when polling buttons it is possible to miss button presses, hence my interest in hardware debouncing and interrupts.
Check that your problems are actually problems before solving them, unless you're running your uC right at the limit of what it is capable of there is no reason that you should miss key presses when polling, and if you are then you should fix your code or get a faster micro.
I had previously thinking of using an OR gate driven by the 3 columns (3x4 keypad) to an external interrupt. That would then cause the uC to read the keypad lines and determine which button had been pressed. Is that what you are describing?
From my understanding, when polling buttons it is possible to miss button presses, hence my interest in hardware debouncing and interrupts.
Well, yes and no. Yes if you use an external extra chip, but no if you do it in software. Couldnt you just set all of the 3 or 4 lines as interrupt on change (after energizing the other set of lines) ? If either of the 3 or 4 lines generated an interrupt, you would then jump to service the keypad in the normal way.
It's up to you how you handle the normal scan then, possibly doing other things between each scan.
Then there's always just straight multitasking where you scan the keypad every so often looking for a change, and do other things in between scans. Scans can be pretty fast so they dont eat up much time.
Setup a 50Hz timer interrupt and scan the keypad. Debounce is automatic, the scan takes micro seconds and you can implement automatic rollover and auto repeat. Simples.
Edit, seems the video still works.
Edit2, just fixed the original article. This would be a simple solution.
I want to build a keypad matrix to interface to a microcontroller. In order to avoid constantly polling the switches I plan to utilize interrupts, which will require hardware debouncing (I believe).
My question is how to go about debouncing a keypad matrix (4x3) in hardware. I have googled this problem but have only found software debouncing.
I have connected keypad columns to CD74HC4002 or gate ic. I am able to trigger interrupt on keppad press. I am right now trying to apply debouncing solution mentioned in below links.