Shop OBEX P1 Docs P2 Docs Learn Events
buttons multiplexing — Parallax Forums

buttons multiplexing

max72max72 Posts: 1,155
edited 2012-08-05 10:24 in Propeller 1
I would like your opinion about the possibily to read the state of a relatively huge amount of buttons.
The idea is to have more buttons than pins available (say 64 buttons, and some prop pins used for other activities).
I usually test the single buttons and use a debounce routine, but I have a 1:1 relationship, in this case it wouldn't work.
Is there a way to multiplex them?
Thanks in advance,
Massimo

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-02 14:29
    Usually this is done by putting a diode in series with each pushbutton (like a 1N4148 or 1N914) and then have a matrix connection for the switches. In your case, you could use 8 x 8 for 64 pushbuttons. You would use something like a 74HC138 selector to select one of 8 rows (or columns) and an 8-1 multiplexor for the other side of the matrix. With 7 I/O pins, you could scan 64 pushbuttons. I think there are examples in the Nuts and Volts Columns archive for the Stamp, but the same setup works for the Propeller. 8 I/O pins could get you 128 pushbuttons using a 1:16 selector.
  • max72max72 Posts: 1,155
    edited 2012-08-02 14:38
    Thanks,
    I'll check the datasheet.
    Massimo
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2012-08-02 15:23
    If only one button is pressed at a time, then you can also implement a method called Charlie-Plexing. ... with 9 I/O lines you can read 72 buttons. (9 resistors and 9 diodes in addition to the buttons needed)
    1024 x 582 - 92K
  • max72max72 Posts: 1,155
    edited 2012-08-02 23:50
    Thansk for the Charlie-Plexing.
    Probably I could accept two buttons at the same time in two different areas, so maybe I could have two separate areas with independent circuits.
    At least I know it is possible... time to jolt down some specs.

    Massimo
  • jmgjmg Posts: 15,183
    edited 2012-08-02 23:52
    max72 wrote: »
    I would like your opinion about the possibily to read the state of a relatively huge amount of buttons.
    The idea is to have more buttons than pins available (say 64 buttons, and some prop pins used for other activities).

    So you mean other than the usual Keyboard matrix (rows x columns cross point) design ?

    http://pcbheaven.com/wikipages/How_Key_Matrices_Works/

    For 64 buttons, you would need 16 io lines, as a simple 8x8 matrix, or depending on the wiring, you might decide that a 16 bit i2c expander makes more sense ?

    I see a PCA9655E is under $1, which gives 16io, and you can connect 64 of those, if you want "relatively huge amount" to reach 4096 buttons....
  • msrobotsmsrobots Posts: 3,709
    edited 2012-08-03 00:24
    just take a ps2-keyboard or two ... tons of buttons and 2 pins each on the propeller

    Enjoy!

    Mike
  • max72max72 Posts: 1,155
    edited 2012-08-03 01:39
    Ok... time to start writing some specs..
    The idea is to use mushroom style buttons to create a kind of push game ( I saw one, professional and high quality, and it was great fun).
    So I would have to decide if allow multiple press.
    I would light the buttons to be pressed (LEDs around the buttons, TBC).
    Light control would be multiplexed too.
    I guess 64 is already a large enough number, probably I'll settle for less.
    A PS2 keybard would work, as long as I could hack it and connect the mushrooms in place of the standard keys.

    Massimo
  • msrobotsmsrobots Posts: 3,709
    edited 2012-08-03 02:24
    Max72l

    Usualy they have some small rubber-caps under the plasic-keys. Leave them there where they are and push them with something else, mounted above.

    or the hard way ... follow the traces and hook up buttons/wires....

    the keyboard-objects available return sometimes a key-code and sometimes a scancode also. So multiple buttons may be available too.

    Enjoy!

    Mike
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-08-03 03:01
    64 push buttons are quite a few, but merely an 8x8 matrix.

    The multiplexer chips ar 16 to 4 and rarely used beyond 32 buttons.

    There is also a 4x4 matrix chip called a 74c922 that is really handy and off loads the effort of supporting 10 key and 16 key numeric entry. It handles all the issued - debound, second key roll over, and auto repeat. Guther's SX assembly textbook has an excellent example of providing all these features in a DIY keyboard as large or larger than yours.
  • jmgjmg Posts: 15,183
    edited 2012-08-03 03:11
    max72 wrote: »
    The idea is to use mushroom style buttons to create a kind of push game ( I saw one, professional and high quality, and it was great fun).
    So I would have to decide if allow multiple press.
    I would light the buttons to be pressed (LEDs around the buttons, TBC).

    So is this a reaction-time game ? - for how many players, and what button separation ?
    If you want to chase reaction times, a generic keyboard is likely too slow.

    You could pre-prime the scan matrix, so it was ready for just the valid keys (and a few other non-lit ones, you can probably just ignore) and that would get the reaction time capture down to sub us levels.
  • max72max72 Posts: 1,155
    edited 2012-08-03 04:54
    It is a kind of reaction game, but it is slower and more physical.
    The original is made of panels about 20X20cm, and the pressure required is quite high. They are more slam-panels.. so I thought about emergency mushrooms.
    There are many option, and 1 or two players (I saw a bunch of kids slamming the panels at the same time and having a great time, but this wasn't really "legal" play..)
    Combining the widely spaced panels and the pressure required the game is a combination of reflexes and physical activity, and is not requiring a tight timing.
    I think it would make a great diversion in a rainy day.
    Massimo
  • kwinnkwinn Posts: 8,697
    edited 2012-08-03 13:08
    One '4017 and one '165 would scan a 10 x 8 matrix using 3 I/O pins.
  • max72max72 Posts: 1,155
    edited 2012-08-03 14:21
    I checked the 74c922 but it is EOL.
    I have to study the 4017 and 165 combination.
    In the meanwhile I got a PS2 keyboard to open.... for sure cheap and low pin count... have to see if it is easy to hack.

    Considering the hardware cost I'll start smaller (4X4 probably), but I would like to have room to grow. So I'll work on a modular approach.

    Massimo
  • kwinnkwinn Posts: 8,697
    edited 2012-08-04 00:16
    @Massimo

    Here is the diagram of the circuit using the '165/'4017 to scan key switches. If you have a couple of extra I/O pins you can get rid of the resistors and capacitor and simplify programming a bit as well.
    646 x 511 - 26K
  • jmgjmg Posts: 15,183
    edited 2012-08-04 01:19
    kwinn wrote: »
    Here is the diagram of the circuit using the '165/'4017 to scan key switches. If you have a couple of extra I/O pins you can get rid of the resistors and capacitor and simplify programming a bit as well.

    Missing are pull down / pullup resistors on the Shiift register Dn lines.
    (the 4017 pulses hi 1:10, so I would use pull-downs and look for any hi on Dn)

    A 4021 can be used with similar effect to '164, and you can remove the R's and C if you want.

    a) If the DS pin on the Shift register is connected to any 4017.Qn, then you can sample Qn state with a 9th clock, and do not need to change CLK pin direction.

    b) As the PL is level based, if the 4017 clocks on the leading edge of PL, then the 4017 ticks to a new scan, and SR loads, and when PL is de-activated to shift, the Dn data on the trailing edge is what is sent.
    This makes CLK speed much more tolerant.

    c) if you use a HEF4017, instead of HC4017, the lower drive on the pins means the diodes can be dispensed with.
    (but the top clock speed does lower)

    d) A 4000 series HEF4021/HEF4017 would have a maximum CLK speed the Prop could exceed, so test < 1MHz to begin with.


    This Circuit still needs 8 passives + 2 packages, so you may decide the sub $1 i2c device (PCA9655E) is a better bet.

    That includes Pullups, and has an INT pin, that allows very low RFI operation, as you can set all SCANs low, and wait for a input button press.
    This could trigger the time capture, and a following key-scan-check would confirm the correct button, but the scan time is not part of the response time.

    The i2c device can also drive LEDs, and 64 PCA9655E can clip on a single i2c lane.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-04 02:41
    The PCA9655E you mention looks like a very nice chip. It would certainly be better, use fewer parts, and less board real estate for scanning 64 key switches.

    I know this circuit could be improved, and your suggestion of putting one of the outputs from the '4017 or '4021 shift register as the serial input of the '165 and reading it's state as the ninth bit of the '165 is an excellent one.

    You are right, the pulldown resistors are missing. There should be 8 pulldown resistors on the parallel inputs to the '165. Thanks for noticing that, missed them when I copied the diagram from my notebook to paint.
  • max72max72 Posts: 1,155
    edited 2012-08-04 14:26
    Thanks for your insight and the detailed explanations.
    I'll have to study a lot..

    Massimo
  • kwinnkwinn Posts: 8,697
    edited 2012-08-04 18:49
    Here is an updated diagram that incorporates the suggestions jmg made and includes the pulldown resistors I forgot to include previously. I have not built or tested this version so no guarantees, although I see no reason it should not work. The status of Q0 on the '4017 is now read as the ninth bit of data in from the '165. If anyone is interested in this circuit and wants an explanation of how it works post or PM your request and I will write it up and post it here.
  • Mark_TMark_T Posts: 1,981
    edited 2012-08-04 20:05
    Just in case anyone builds that circuit - in that diagram you've wired the 4017 to never clock. CP1-bar should be wired LOW. For CMOS chips you don't need resistors for inputs wired HIGH, BTW, that's a TTL thing.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-04 23:33
    Sheesh, fix one thing, break another. Ok, fixed that mistakel. Thanks Mark. Again, I have not tried this one out so no guarantees.
    674 x 457 - 21K
  • CRST1CRST1 Posts: 103
    edited 2012-08-05 04:39
    Just use a chip like 74ls165 and series as many as you want. Only three prop pins for as many inputs as you like. Also reads multiple inputs at the same time.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-05 10:24
    CRST1 wrote: »
    Just use a chip like 74ls165 and series as many as you want. Only three prop pins for as many inputs as you like. Also reads multiple inputs at the same time.

    That would work but would require 8 chips for 64 keys and 10 chips to do what these 2 chips do. Both chips and board real estate cost money. A small inexpensive microcontroller is the best way to go for low cost high volume production (ie PC keyboards).
Sign In or Register to comment.