Key press/Key release

state-machinesvhdl

I'm designing a keypad in VHDL and for protection purposes I disable pressing a second or more keys while one key is being pressed. Example while I'm pressing "7" a press of "2","3","5","4","1","0" etc. will be ignored and no tone will be heard. Each valid key press generates a tone. My keypad is consisting of 3 columns and 4 rows, 12 keys. I have 3 states in my FSM and I scan each column for a valid key press(states: scan_column1, scan_column2, scan_column3). I switch from state to state under the condition when no key is pressed. This way if I am scanning column3, all key presses in column2 and column1 are ignored and unseen. Now I have a final problem lets say I'm pressing "7" , tone of 7 is heard, I'm still holding my finger on "7" and then I press "3", 3 is of course ignored, but I'm still holding "3" and then I release "7", then 3 becomes a valid press and tone of "3" is heard. But 3 is not a new pressed key, it was being pressed while 7 was pressed, so I want to avoid tone generation in this case. Any suggestions? Because this is an ongoing project I can't upload my code 🙁

More details about my keypad

Best Answer

Define a bit vector that will hold the current state of all buttons. When you detect an edge caused by a press, you update the appropriate bit (set to 1) in the vector. When you detect the other edge caused by a release you update the bit again (back to 0 for example). When you detect a new key press all you need to do is check that the vector is

keypad_state = (others => '0')

to find out if this is the only button currently being pressed. If the vector is not all 0's you can decide to do nothing and when the '3' is released you simply update its state in the vector and this does nothing as your code probably does not react to key releases. This way you simply add a single if statement and eliminate the problem. If you had posted some code I might be able to edit it to reflect this mechanism.