Keypad decoding for micrologix 1500

F

Thread Starter

Ferg

Hi, I'm trying to develop logic to enable me to punch in a four digit number into a 16 button keypad, and read the numerical result in an
integer or string of a micrologix 1500. I'm pretty sure I have to sequentially scan either the rows or columns and match them up with their
opposites. An example of full ladder logic would be very much appreciated if possible.
Thanks and regards
Ferg
 
G

Gerald Beaudoin

Why not use a keypad with Hex outputand just run the 4 bits into 4 inputs of the PLC?? Then do the decoding in the logic. There is even a DCD instruction to decode the four bits to "one of 16".

Gerald Beaudoin
 
J

Johan Bengtsson

Well, like this perhaps (long post):<br>
<br>
<pre>

;first 8 timers to sequentially select a row and wait for the signal
T7 T0
--|/|----------------------( )--

T0 T1
--| |----------------------( )--

T1 T2
--| |----------------------( )--

T2 T3
--| |----------------------( )--

T3 T4
--| |----------------------( )--

T4 T5
--| |----------------------( )--

T5 T6
--| |----------------------( )--

T6 T7
--| |----------------------( )--


;output what row to scan
T1 Row 0
--|/|----------------------( )--

T1 T3 Row 1
--| |--|/|-----------------( )--

T3 T5 Row 2
--| |--|/|-----------------( )--

T5 Row 3
--| |----------------------( )--


;logic to determine what button is pressed and not pressed
;Row 0
T0 T1 Col 0 Dig 1
--| |--|/|--*--| |---------(S)--
|
| Col 0 Dig 1
*--|/|---------(R)--
|
| Col 1 Dig 2
*--| |---------(S)--
|
| Col 1 Dig 2
*--|/|---------(R)--
|
| Col 2 Dig 3
*--| |---------(S)--
|
| Col 2 Dig 3
*--|/|---------(R)--
|
| Col 3 Dig A
*--| |---------(S)--
|
| Col 3 Dig A
*--|/|---------(R)--

;Row 1
T2 T3 Col 0 Dig 4
--| |--|/|--*--| |---------(S)--
|
| Col 0 Dig 4
*--|/|---------(R)--
|
| Col 1 Dig 5
*--| |---------(S)--
|
| Col 1 Dig 5
*--|/|---------(R)--
|
| Col 2 Dig 6
*--| |---------(S)--
|
| Col 2 Dig 6
*--|/|---------(R)--
|
| Col 3 Dig B
*--| |---------(S)--
|
| Col 3 Dig B
*--|/|---------(R)--

;Row 2
T4 T5 Col 0 Dig 7
--| |--|/|--*--| |---------(S)--
|
| Col 0 Dig 7
*--|/|---------(R)--
|
| Col 1 Dig 8
*--| |---------(S)--
|
| Col 1 Dig 8
*--|/|---------(R)--
|
| Col 2 Dig 9
*--| |---------(S)--
|
| Col 2 Dig 9
*--|/|---------(R)--
|
| Col 3 Dig C
*--| |---------(S)--
|
| Col 3 Dig C
*--|/|---------(R)--

;Row 3
T6 T7 Col 0 Dig *
--| |--|/|--*--| |---------(S)--
|
| Col 0 Dig *
*--|/|---------(R)--
|
| Col 1 Dig 0
*--| |---------(S)--
|
| Col 1 Dig 0
*--|/|---------(R)--
|
| Col 2 Dig #
*--| |---------(S)--
|
| Col 2 Dig #
*--|/|---------(R)--
|
| Col 3 Dig D
*--| |---------(S)--
|
| Col 3 Dig D
*--|/|---------(R)--

</pre>
Now some about the above. First of all I assume it is a 16 button keypad of the type where you set a row (or column) to scan and read the other. I assume it is safe to set a row and read a column, if not you have to change to program accordingly.<br>
I also assume the layout is<br>
1 2 3 A<br>
4 5 6 B<br>
7 8 9 C<br>
* 0 # D<br>
If this is not the case you have to adjust accordingly of course<br>
<br>
How it works: there are 8 states in the program (decided by the 8 timers)<br>
Timer 0 counting - set output to read row 0 and wait<br>
Timer 1 counting - set output to read row 0 and read it<br>
Timer 2 counting - set output to read row 1 and wait<br>
Timer 3 counting - set output to read row 1 and read it<br>
Timer 4 counting - set output to read row 2 and wait<br>
Timer 5 counting - set output to read row 2 and read it<br>
Timer 6 counting - set output to read row 3 and wait<br>
Timer 7 counting - set output to read row 3 and read it<br>
<br>
Each read state (odd numbers above) latches or unlatches those flags for the buttons on that row, this means a button flag will be off until the row is read the first time while being pressed and is on until the row is read the first time after it is released.<br>
<br>
Ok, I realize this is inly the first half of the problem but I think this is the part you needed help with to begin with. If the other part is still a problem (and there isn't anyone else responding) I suggest you repost.<br>
<br>
One problem you might get is if the reading is too slow if the scanning can't be made fast enough (what are your lowest timer resolution?).<br>
<br>
<br>
/Johan Bengtsson<br>
<br>
Do you need education in the area of automation?<br>
----------------------------------------<br>
P&L, Innovation in training<br>
Box 252, S-281 23 H{ssleholm SWEDEN<br>Tel: +46 451 49 460, Fax: +46 451 89 833<br>
E-mail: [email protected]<br>
Internet: http://www.pol.se/<br>
----------------------------------------<br>
 
M

Michael Griffin

I won't attempt to answer the first part of your question - the best way to do that requires knowing that particular PLC better than I do. I believe that someone mentioned a hex keypad decode instruction (these are sometimes found on small PLCs). You can scan the outputs by simply shifting a single bit around the outputs via a 4 bit shift register at some suitable rate.

However, assuming that you have decoded the keypad into a numeric value representing a key "index" (i.e., a number from 0 to 15 representing a key) you need to do the following:
1) Detect that any numeric key has been pressed (how you do this depends upon how you are decoding the keypad to begin with).
2) Read the keypad and decode it to a key "index".
3) Use the "key index" to look up the corresponding integer digit which the key represents. This is necessary because "key 5" won't likely be the key which has the number "5" printed on it. Your look-up table will take care of this translation.
4) Store the resulting digit in the beginning of a FIFO.
5) Wait for all keys to be released.
6) Repeat the above steps each time a numeric key is pressed and released. The existing digits in the FIFO will get shifted over in the FIFO buffer as new digits come in.

You combine the four digits into one into one integer as follows:
1) Clear the result word (the word where the combined integer is to be stored).
2) Take the first digit in the FIFO and move it to the result.
3) Take the second digit in the FIFO, multiply it by 10 and add it to the result word.
4) Take the second digit in the FIFO, multiply it by 100 and add it to the result word.
5) Take the third digit in the FIFO, multiply it by 1000 and add it to the
result word.

Alternatively, if you have a BCD to integer conversion instruction, you can simply stuff each digit into the corresponding nibble in a single word, and then do a BCD to integer conversion.


--
************************
Michael Griffin
London, Ont. Canada
************************
 
Top