1

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

Anarkie
  • 329
  • 1
  • 5
  • 18
  • @apalopohapa I do have an edge detector in my code, otherwise I would send continously the same key when it is being pressed for a long time. But somehow I have to understand that a key is not being pressed, at that time, I set KEY_PRESSED to "0" assuming no key is pressed and then I switch to next states... Or is there another way? – Anarkie Jun 16 '14 at 22:13
  • What are you doing for key debouncing? What is the minimum hold-down time for a valid keystroke? Do you want action-on-depression or action-on-release? Do you know what "N-Key Rollover" is and do you want to incorporate it in your decoder? – FiddyOhm Jun 16 '14 at 23:18
  • @FiddyOhm min hold down is 10ms for a column, 30ms to detect any valid key. I want action on press. I don't have problem with debouncing, valid key is sent end of 10ms. I googled N-Key Rollover, a program which shows which keys I press in my keyboard. I think I don't need it. – Anarkie Jun 17 '14 at 07:47

1 Answers1

0

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.

user34920
  • 1,872
  • 2
  • 22
  • 44
  • Can you please elaborate your answer a little bit more? I am close to getting it! Thats why I added some portion of my code `KEY_PRESSED` plays a great role! – Anarkie Jun 16 '14 at 22:06
  • Also it isn't possible to detect a second key press in my code. – Anarkie Jun 16 '14 at 22:17
  • what is scan_1 and scan_2 ? – user34920 Jun 16 '14 at 22:25
  • state1, state2, first 2 states of my state machine. `Input` is rows – Anarkie Jun 16 '14 at 22:43
  • I changed the state switching way and implemented a vector like you suggested after a little bit tweaking, the result is I want :) thanks for the idea! – Anarkie Jun 17 '14 at 13:28
  • For the record, the suggested code `keypad_state = (others => '0')` is illegal - do `keypad_state = (keypad_state'range => '0')`. `=` is an operator, the compiler won't know the width of the right-hand side unless you tell it. – Carl Jun 18 '14 at 20:51