Shop OBEX P1 Docs P2 Docs Learn Events
64 Keypad Matrix - Using 2 Shift registers — Parallax Forums

64 Keypad Matrix - Using 2 Shift registers

DavidMDavidM Posts: 626
edited 2007-10-07 14:15 in Propeller 1
Hi,

I have used both kinds of shift registers ( 74HC595 & 74HC165 )with the propeller and have no problems with them I have code for both.

So, Is it possible to combine the OUTPUTS of the 74HC595 with the INPUTS of the 74HC165 as in my attached schematic to make up to 64 keypad matrix to use with a MEMBRANE SWITCH OVERLAY?

I plan the following logic ( in spin )

1) LOOP ( 8 TIMES)
2) TURN ON OUTPUT 1, of the 74HC595 SHIFT REGISTER
3) WAIT FOR A SHORT TIME
4) READ THE 74HC165 INPUT SHIFT REGISTER
5) WAS ANY KEY VALUE RETURNED? ( VALUES 1 -8)
6) IF NO VALUE, THEN REPEAT FROM STEP 2 BUT INCREMENT THE OUTPUT NO BY 1
7) IF YES, USE THE LINE NO ( 1-8 ) MULTIPLIED BY THE KEY VALUE ( 1-8) AND STOP THE LOOP

Questions..

1) Can I run both shift registers at 3.3 volts?
2) What Pullups /pulldown resistors do I need?
3) Do I need to delay for a short period between each row when reading the values?

regards

Dave M

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-09-30 02:42
    Hi Dave cool.gif

    What are you asking for? You have already got it figured out! (have some confidence)

    As shift cycles take time it is easier to output all lows with pullups on the inputs to detect a key pressed. If you get something that does not equal $FF then you know a key is pressed, all you have to do is scan through for it. The 1of8 row code is reduced to 3 bits and you simply combine that with the column code by using shifts and ors.

    Of course there is no problem running at 3.3V, the chips are rated for operation at that voltage.

    Resistor values can be in the range of 1K to 100K and you wouldn't know the difference. However 10K is probably an optimum value. Pullup or pulldown doesn't really matter, it only did with TTL because it could sink more current then it could source unlike CMOS.

    Keep in mind that multiple key presses can short output lines together but normally this is not catastrophic. Use diodes in the outputs if you want to be able to press multiple keys or just use 220R resistors if you don't care but want to play it safe.

    It is good to think about timing problems but in this case you don't need a delay between reading values as anything you do with shift registers is still slow anyway.

    You know that even though you can do it with shift registers that I would probably just program a $1 PIC chip to scan the keypad and communicate back to the prop. But there is nothing wrong with doing it the way you describe.

    *Peter*
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-30 09:35
    David,
    I was planning an example of using shift registers in my course, and your schematic comes in absolutely handy! It will be the task of the students to find out exactly what Peter said smile.gif

    We then will discuss the pros and cons of using an encoder/decoder ('42, '147) solution (needing 6 lines)
    Q: How many lines do you need?
  • DavidMDavidM Posts: 626
    edited 2007-09-30 23:25
    Hi,

    I have updated my Schematic as it was COMPLETELY WRONG!

    By default all the inputs to the 165 will be pulled to ground, registering 0 on the shift register bits.

    When a SCAN is started, line 1 ( output A of the 595 register will output a HIGH and the 165 will read this as a high ( if a button is pressed in that ROW).
    I think this will register multiple key presses along the same ROW, so I have to decide to IGNORE MULTIPLE KEY PRESSES and rescan.

    I looked at the flow of power and I don't think I need DIODES, but I could be wrong! smile.gif

    I am sure that I only need 4 lines back to the PROP as I can share the lines between the shift registers.

    What do you think?

    Dave M
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-30 23:34
    The 220R will avoid a short.

    I think you have to LOAD the '165
    You cannot use the clock for both, so two clock lines
    You have to read the '165
    You need the data for the '595

    Should be 5 smile.gif

    Post Edited (deSilva) : 9/30/2007 11:47:29 PM GMT
  • DavidMDavidM Posts: 626
    edited 2007-09-30 23:51
    Hi DeSilva,

    yes I think its 5 lines, I will modify my schematic with the rest of the circuit back to the propeller + other components to make it more complete.

    dave M
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-09-30 23:55
    Dave,

    If you are going to show us a circuit it might be a good idea and show us the "unimportant" stuff too like the clock and load lines etc and mark or connect any unused lines.
    Critique of a skeleton is difficult.

    You could share the clock as it does not matter that you clock dummy data into the output register while you are trying to read the input register (just as long as you don't latch it). Of course you could clock real data to it while reading but that might complicate your software for the moment.

    Propeller pins should be:
    SCK Common clock
    SDO Data to 595 output shift register
    SDI Data from 165 input shift register
    WR Latch (RCK) 595 output register after writing data to it.
    RD Latch (SH/LD) 165 input register prior to reading data from it.

    Yes, 5

    *Peter*
  • DavidMDavidM Posts: 626
    edited 2007-10-01 00:03
    Hi Pete,

    yes , that's what I plan to show, I should do this So I have a reference when I go to make the circuit ( at least for bread-boarding). And it would be more useful to others showing complete circuits.

    Now, I want to breadboard this, I don't have an issue with the shift registers and resistors etc , But how do I breadboard 64 switches I guess I only have to test out at least TWO / maybe tree rows?


    Dave M
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-01 00:04
    You could also use a decade counter (4017) for your row select rather than a shift register. Synchronize with the carry output. Just a thought...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?

    Post Edited (Ken Peterson) : 10/1/2007 12:10:12 AM GMT
  • DavidMDavidM Posts: 626
    edited 2007-10-01 00:17
    HI Ken,

    Yes I could ( I had a quick look at the specs on that), But I am using shift registers as They are really cheap, I use many of them in other boards I have designed, so I like to minimize the number of different components.

    And I know how they work , ( but I am definitely no expert! wink.gif

    Also I have reliable SPIN code for the two types of registers and I am confident in using them.

    BTW, I could also use I/O line from the propeller directly as well, If I had spare for a given project


    Thanks

    Dave M
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-01 00:23
    DavidM said...
    Now, I want to breadboard this....
    Because of the simplicity of your design (this is meant as an appreciation - I seem to have a very bad reputation..) it does not matter whether a "key" is present at all, or not.

    I used the following simple scheme some years ago for testing:
    I took the next best solderless breadbaord, 8 of the colums at the upper side were the X and 8 of the columns at the lower side Y.

    A key push was simulated by just plugging a (or more!) wire(s) between an upper and a lower column for a moment.

    I could also create highly interesting bouncing patterns stressing that part of the program to the utmost smile.gif
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-10-01 00:26
    You could use a 4017 but you miss out on setting all the outputs active during idle to detect any key pressed. Besides, I think Dave's got lots of 165s and 595s smile.gif

    You don't need switches, just short them with a bit of wire or anything.

    Dave, you are designing from the top trying to work down to the nitty-gritty, millimeter by millimeter. Just get your hands dirty and the fog will lift making things a bit clearer.

    *Peter*
  • DavidMDavidM Posts: 626
    edited 2007-10-01 00:34
    HI DeSilva

    I understand what you are saying, thats a good Idea, I do have quite a few tactile switches lying around probably enough for 3 rows, So I should try that out.


    Dave M
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-01 00:37
    Was that really what I was saying ???
  • javerjaver Posts: 6
    edited 2007-10-01 00:49
    David,

    There is very simple solution, without any additional chips, and with minimum number of lines. Buttons are placed in the symetric matrix of NxN, with one diagonal replaced with diodes (usualy Schottky, BAT48 or similar). Scan procedure is simple: All port pins are inputs except one, with low level. After reading all inputs, move output to next port pin and repeat reading. Important is that always is only one port pin declared as output, and it is at low level. Because of diodes, matrix NxN supports up to Nx(N-1) buttons, so for 8x8 buttons, you need 9 lines. This is 72 buttons (9x8), so you can remove last row and you will have 64 buttons.

    Yaver
    509 x 668 - 12K
  • Ken PetersonKen Peterson Posts: 806
    edited 2007-10-01 00:56
    This looks familiar. There is at least one other thread on the forum covering this same method.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
  • DavidMDavidM Posts: 626
    edited 2007-10-01 01:23
    HI Javer ,

    Thanks for your Idea, Its simple enough, but it use more I/O pins than I can afford for my design


    Dave M
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-01 06:44
    Javer,
    I like your proposal very much! It a creative variation of the "Charlieplexing" principle (That should stirr-up Ken's memory!)
    The resistors are not just simple pull-ups, but wired-or circuits; in combination with the absolutely needed diodes and the input gate they form what we called DTL not so many years ago smile.gif So this circuit does not contain a "chip" but its "diode-equivalent" ...

    I consider it an enormious task that you could devise this!

    David's approch has the great charm that it needs no scaling concerns. It will work with 5 lines totally independant of the size of the matrix! That's the main difference to encode/decoder solutions, and I am curious whether my students will identify this on Thursday...

    Post Edited (deSilva) : 10/1/2007 6:49:20 AM GMT
  • DavidMDavidM Posts: 626
    edited 2007-10-01 10:33
    HI,

    Here is an updated Schematic, I have added the propeller lines.. All that it needs are some decoupling caps.


    This circuit should be scalable to many more switches if you so desire?

    what do you think?


    Dave M
  • javerjaver Posts: 6
    edited 2007-10-01 16:59
    David,

    If you connect 165 output (QH) to Prop pin, you cannot use this Prop pin as output.

    165 has asynchronus parallel load, and 595 use raising edge for RCLK. Attached simplified schematic shows serial driven keyboard by using only 4 lines, (Peter proposed similar version, but with 5 lines). The same line is used for parallel load and for triggering output register of 595. The main idea is:

    1. Keep SH low and shift 8-bit data to 595.

    2. Raise SH - this will transfer data to 595 output and latch keyboard data in 165.

    3. Shift-in data from 165 and at the same time shift-out new data to 595.

    First time, you need to shift-out the same data twice, and first keyboard reading is dummy.

    So, while shift-in data from 165, you will send new data to 595 at the same time.

    Usualy, R-C elements are not needed, because 165 will latch input data before output of 595 is changed, but with R-C (small values for R and C), you will have additional delay. 165 latched data are always result of previous 595 output and keyboard state.

    Yaver
    284 x 448 - 4K
  • OzStampOzStamp Posts: 377
    edited 2007-10-07 12:39
    Hi to all.. ( re scanning a keypad with 64 key's)..(sorry for the spanner in the worx)

    I recall seeing a schematic awhile ago using 2 PCF8574 I2C I/O expander chips configured for scanning
    64 key's ( one chip for outputs and the other one for inputs..)
    Also the INT line was looked at.. so effectively only needing 3 I/O lines >> I2C + the INT signal.
    Now I2C as we all know hangs of the Propeller on pins 28 + 29 .. so that is pretty neat..
    The million $$ question is probably how fast would you be able to scan the key's ..
    Would not be hard to do and speed should be fine ..even in SPIN..

    Tried to find this schematic but no luck sofar... since Philips renamed or sold that division to NXP
    alot of the original I2C links do not seem to work anymore in Google....

    Cheers from OZ.
    Ron
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-07 12:57
    This is no secret. You would connect the keyboard matrix EXACTLY as you would connect it to 16 Propeller Pins, as the I2C expanders (8 or 16 bits wide) behave nearly identical.
    The Philips Chips are around 1 Euro per 8 I/O.

    You can scan it around 10 kHz a should say...

    The MAX7324 is also a very interesting chip for such purposes, but comes in SMD only
    www.datasheet4u.com/download.php?id=563628

    Post Edited (deSilva) : 10/7/2007 1:31:13 PM GMT
  • WhelzornWhelzorn Posts: 256
    edited 2007-10-07 13:26
    Wow, javer's solution is very elegant... I'm having a little bit of trouble understanding it though, so here comes a stupid question: How would the prop tell the difference between you pressing button 1 in row 1, or button 1 in row 2? I'm assuming all of the resistors are the same value, right?
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-07 13:37
    ... and here is a quite instructive overview over the Philips Port Expanders
    www.standardics.nxp.com/products/gpio.expanders/i2c/~PCA8574/
  • deSilvadeSilva Posts: 2,967
    edited 2007-10-07 13:48
    Whelzorn said...
    How would the prop tell the difference between you pressing button 1 in row 1, or button 1 in row 2?
    Only a key in a column that is pulled down at that moment can set one of the other lines low.
    In each of the rows of a column this key press is directed to exactly one of the input lines.

    Are you sure you have undererstood the Charlieplexing thing? Would help smile.gif
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-10-07 14:15
    If we skip Dave's specific requirement to use common shift-registers then I2C is another logical choice. Using PCF8574 style I/O you could hook-up the matrix as per normal but we have one slight advantage besides using the I2C lines for the EEPROM, that is there is an INT output from the 8574's which will pull down if there is a change of state from the last time it was read. How does that help? Easy, if all your column outputs are driven low then ANY key pressed will cause a change of state on the row inputs and the INT line will activate. Assuming the software is monitoring the INT line it can then scan through each column one by one until it finds the correct row/column. This means that the prop does not have to scan the matrix unless a key has been pressed.

    The PCF8574's have a weak pull-up on their open-drain (effectively) pins which means you could get away without any extra pullups.

    A single 8-bit PCF8574 could scan 56 keys using the clever charlieplexing scheme but you would have to scan it continually plus add some diodes.

    *Peter*
Sign In or Register to comment.