42 Key Keypad on 5 wires

mikeologistmikeologist Posts: 69
edited November 29 in Propeller 1 Vote Up0Vote Down
This all started here in this thread.

I was having issues adding an extension to the standard 4X4 keypad in an effort to expand it with more keys. Even with the inline and pull-down resistors prescribed I was still getting cross-chatter.

The conclusion that I came to was that I needed to abandon the keypad and make a completely new one that uses diodes to prevent cross-chatter.

Several users helped and a couple of them really pushed me with new subjects to read and understand. I'm grateful for their contributions.

This is the result.

I arranged it in a 12X4 array. Thanks to VIRAND I will use a CD4040B ripple counter for the 12 input pins. I will run this with a single clock pin and no reset. Effecting a 5 pin bus that needs no resistors and suffers no power loss. Resistance is futile.

Each switch receives power from an input pin through a 1N4148 diode and passes the signal of another switch. This create a 4 bit output bus.

Each 4 switch row is read sequentially, one at a time buy pulsing the clock pin on the 4040 ic.

The spin software should be a bit simpler than the 4X4 software as it does not have to increment though input pin numbers. This will make it a single, simple loop and eliminate the frame references from multiple methods.

Due to a poorly written advertisement, my 4040s are delayed until Friday evening. So now I have to wait.

Shout-Out to Cluso99, WBA Consulting, and VIRAND for all their help.

Any comments, questions?
3024 x 4032 - 1M
3024 x 4032 - 1014K
3024 x 4032 - 1M
Any com port in a storm

Comments

  • 15 Comments sorted by Date Added Votes
  • @mikeologist

    The 4040 is not going to work as you describe it. It may be that I am not understanding what you posted, but I do not think so. A wiring diagram would clear that up. Main problem is that the '4040 does not change one pin at a time like the '4017 does. Some of the pins of the '4040 will be high and others low at most times.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • mikeologistmikeologist Posts: 69
    edited November 29 Vote Up0Vote Down
    kwinn wrote: »
    @mikeologist

    The 4040 is not going to work as you describe it. It may be that I am not understanding what you posted, but I do not think so. A wiring diagram would clear that up. Main problem is that the '4040 does not change one pin at a time like the '4017 does. Some of the pins of the '4040 will be high and others low at most times.

    Hmmmm. I see my mistake now. Thanks a bunch.

    The 4017 only has 11 outputs. Shoot.

    I've got some more reading to do :depressed:
    Any com port in a storm
  • kwinn wrote: »
    @mikeologist

    The 4040 is not going to work as you describe it. It may be that I am not understanding what you posted, but I do not think so. A wiring diagram would clear that up. Main problem is that the '4040 does not change one pin at a time like the '4017 does. Some of the pins of the '4040 will be high and others low at most times.

    I've got a 4017 and a 4022 on hand. Think it's possible to get a resetting 12 count out of the two?
    Any com port in a storm
  • kwinn wrote: »
    @mikeologist

    The 4040 is not going to work as you describe it. It may be that I am not understanding what you posted, but I do not think so. A wiring diagram would clear that up. Main problem is that the '4040 does not change one pin at a time like the '4017 does. Some of the pins of the '4040 will be high and others low at most times.

    I've got a 4017 and a 4022 on hand. Think it's possible to get a resetting 12 count out of the two?

    Ok, looking into this video now. Should do it if I can stop it at the right spot.

    Any com port in a storm
  • tonyp12tonyp12 Posts: 1,870
    edited November 29 Vote Up0Vote Down
    You have to use 5pins, or is 7 pins OK?
    Is only one key presses at a time?, if so google charlieplexing keypad. 7*(7-1) = 42keys.

    Other way I probably would use 5 daisy chained parallel-to-serial IC's (40keys), just to keep it simple.
    https://www.mouser.com/ProductDetail/Nexperia/74LV165AD-Q100J/?qs=sGAEpiMZZMtsbn1GaJyslypZg741RneR%2b1wT%2bc6bXC8=
    With Schmitt-trigger, allows you to put 0.1uF cap on all keys, to eliminate pesky switch bounce.


    They make key scan IC, this one is 0.65mm, many others are 0.50mm and not hobby friendly:
    https://www.mouser.com/ProductDetail/ON-Semiconductor/LC75700T-TLM-E/?qs=sGAEpiMZZMuleuVm2ofeX7XEavfHLEzz





  • mikeologistmikeologist Posts: 69
    edited November 29 Vote Up0Vote Down
    tonyp12 wrote: »
    You have to use 5pins, or is 7 pins OK?
    Is only one key presses at a time?, if so google charlieplexing keypad. 7*(7-1) = 42keys.

    Not a fan of charlieplexing because of the extreme number of clocks and I want multi-touch.
    tonyp12 wrote: »
    Other way I probably would use 5 daisy chained parallel-to-serial IC's (40keys), just to keep it simple.
    https://www.mouser.com/ProductDetail/Nexperia/74LV165AD-Q100J/?qs=sGAEpiMZZMtsbn1GaJyslypZg741RneR%2b1wT%2bc6bXC8=
    With Schmitt-trigger, allows you top put 0.1uF cap on all keys, to eliminate pesky switch bounce.

    I like that solution, nice and simple. But I'm not a fan of serial because of the unnecessary software decoding; again, just limiting the number of clocks.
    I tested it on my flip, using all 16 pins and it worked flawlessly; the diodes eliminated all the chatter.

    Switch Bounce:
    Since my switches are mechanical they absolutely have switch bounce.
    I'm using the same method that Parallax provides for the 4X4 keypad; It's a capacitive read approach. All 5 pins are set low (discharge), then all pins are set to input, the first pin(out for prop, in for keypad) is set to high. If a button is pressed it will change the capacitor state of any of the 4 read pins, rinse, repeat.
    It's important to note that I only plan on reading from the keyboard 7 or 8 full read cycles per second, so I can manually time-slice it into a background task cog program.
    Since this is not an interrupt circuit and since it is not edge triggered, and all the ICs are upstream from the switches, it is my opinion that switch bounce is not an issue in this circuit.
    If I do find it to be an issue I will use 2X MAX6817s to apply debounce to each of the 4 output pins.
    I would love to hear other analysis of these statements.



    I appreciate the tips. They're great, just not what I need for my specific application.

    What I'm doing is using a flip-flop(4013 maybe) to suppress/enable/reset a 4017 and a 4022, this will allow me to get nine steps from the 4017 and the last 3 from the 4022. Haven't figured it all out yet but I'm certain I can drive it with a single clock pin. Then, I'll use the 4 output pins in parallel to read and decode the keys with multi-touch and return an array of the first 5 keys captured in under 120 clocks. That's the project goal anyway. Hope I can hit it.
    Any com port in a storm
  • I2c expanders are great for this. 2 pins total needed. 3 x PCF8575 is one option using 16 I/O x 3. If cost is an issue there are tricks where you can use 1 16io expander on 2 pins and 3 pins for XYZ matrixing total 5 pins. Very simple For debounce it can be very simple just read the inputs twice with a slight delay between the first and second read. No need for fancy debounce code or hardware.
  • T Chap wrote: »
    I2c expanders are great for this. 2 pins total needed. 3 x PCF8575 is one option using 16 I/O x 3. If cost is an issue there are tricks where you can use 1 16io expander on 2 pins and 3 pins for XYZ matrixing total 5 pins. Very simple For debounce it can be very simple just read the inputs twice with a slight delay between the first and second read. No need for fancy debounce code or hardware.

    For my application it can't be i2c, but I see how that would work nicely and reduce pins very well.
    For me must be parallel or I'll spend forever downloading and decoding the keys, relatively speaking. I'm trying to avoid having to cut clocks from my primary applications by limiting the clocks necessary for secondary applications and hardware support.

    Currently, I'm working on making a single-pin flip-flop from a 4013. Any ideas there?
    Any com port in a storm
  • It is fair to not prefer other solutions, but I cannot imagine anything simpler than using a single MCP23017. This approach uses a maximum of 3 Propeller pins; fewer if I2C pins are already allocated and available. The third pin is an interrupt.

    Reading a key/switch takes more clocks due to communication, but using the interrupt means that you only read it when necessary. Probably a net gain.

    With 16 GPIO pins, a matrix could be 8x8, 12x4, etc. The general idea is described in this Microchip application note. I used this scheme years ago on a BS2P project. Full disclosure, I did not test simultaneous presses of multiple keys.

    If it isn't your cup of tea, then no harm.
  • Well I think decoding keys is plenty fast enough, plus as mentioned you could possibly set it up to monitor INT so you only run I2C signals when there is real input, otherwise the loop just checks the INT input.

    The PCF8575 provides an open-drain interrupt (INT) output, which can be connected to the interrupt input of a microcontroller.
    An interrupt is generated by any rising or falling edge of the port inputs in the input mode.

    http://www.ti.com/lit/ds/symlink/pcf8575.pdf
  • T Chap wrote: »
    Well I think decoding keys is plenty fast enough, plus as mentioned you could possibly set it up to monitor INT so you only run I2C signals when there is real input, otherwise the loop just checks the INT input.

    The PCF8575 provides an open-drain interrupt (INT) output, which can be connected to the interrupt input of a microcontroller.
    An interrupt is generated by any rising or falling edge of the port inputs in the input mode.

    http://www.ti.com/lit/ds/symlink/pcf8575.pdf

    Appreciate it, but no decoding an imperative. I have to stick to parallel output, but thanks.

    The plan is to chain 4017 and a 4022 for sequential triggering based only on a clock line. If you have any advise there I'd sure appreciate it.

    I found the attached picture here
    It's close but it still uses a reset and a clock. I'd like to get it down to the clock. Trying to add a capacitor to do so.
    620 x 481 - 38K
    Any com port in a storm
  • kwinnkwinn Posts: 7,641
    edited November 30 Vote Up0Vote Down
    kwinn wrote: »
    @mikeologist

    The 4040 is not going to work as you describe it. It may be that I am not understanding what you posted, but I do not think so. A wiring diagram would clear that up. Main problem is that the '4040 does not change one pin at a time like the '4017 does. Some of the pins of the '4040 will be high and others low at most times.

    I've got a 4017 and a 4022 on hand. Think it's possible to get a resetting 12 count out of the two?

    Sorry, the 4022 is also a binary counter so you would have the same problem as the 4040 has.

    What should work is a 4017 and a '165 shift register. That would allow for up to 80 keys, but needs a micro (2 pins) to do the clocking and decoding. The posted doodle was an idea I had for a project that never got off the ground so I can't guarantee it will work without a bit of tweaking.80%20key%20scanner%20v2.png

    PS - you would also need to add diodes to the 4017 for protection from shorting the 4017 lines together.
    1920 x 782 - 102K
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • T ChapT Chap Posts: 3,650
    edited November 30 Vote Up0Vote Down
    Whats the difference in shifting in bits from a shift register and shifting in the same number of bits on an I2C expander? Seems to me this flip flop method is more complicated.
  • T Chap wrote: »
    Whats the difference in shifting in bits from a shift register and shifting in the same number of bits on an I2C expander? Seems to me this flip flop method is more complicated.

    Either way works but the '165 works particularly well with the 4017 and I usually have several. It also allows me to save an I/O pin by using an RC circuit to differentiate between a shift clock pulse and a load clock pulse.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • tonyp12 wrote: »
    You have to use 5pins, or is 7 pins OK?
    Is only one key presses at a time?, if so google charlieplexing keypad. 7*(7-1) = 42keys.

    Not a fan of charlieplexing because of the extreme number of clocks and I want multi-touch.
    tonyp12 wrote: »
    Other way I probably would use 5 daisy chained parallel-to-serial IC's (40keys), just to keep it simple.
    https://www.mouser.com/ProductDetail/Nexperia/74LV165AD-Q100J/?qs=sGAEpiMZZMtsbn1GaJyslypZg741RneR%2b1wT%2bc6bXC8=
    With Schmitt-trigger, allows you top put 0.1uF cap on all keys, to eliminate pesky switch bounce.

    I like that solution, nice and simple. But I'm not a fan of serial because of the unnecessary software decoding; again, just limiting the number of clocks.
    I tested it on my flip, using all 16 pins and it worked flawlessly; the diodes eliminated all the chatter.

    Switch Bounce:
    Since my switches are mechanical they absolutely have switch bounce.
    I'm using the same method that Parallax provides for the 4X4 keypad; It's a capacitive read approach. All 5 pins are set low (discharge), then all pins are set to input, the first pin(out for prop, in for keypad) is set to high. If a button is pressed it will change the capacitor state of any of the 4 read pins, rinse, repeat.
    It's important to note that I only plan on reading from the keyboard 7 or 8 full read cycles per second, so I can manually time-slice it into a background task cog program.
    Since this is not an interrupt circuit and since it is not edge triggered, and all the ICs are upstream from the switches, it is my opinion that switch bounce is not an issue in this circuit.
    If I do find it to be an issue I will use 2X MAX6817s to apply debounce to each of the 4 output pins.
    I would love to hear other analysis of these statements.



    I appreciate the tips. They're great, just not what I need for my specific application.

    What I'm doing is using a flip-flop(4013 maybe) to suppress/enable/reset a 4017 and a 4022, this will allow me to get nine steps from the 4017 and the last 3 from the 4022. Haven't figured it all out yet but I'm certain I can drive it with a single clock pin. Then, I'll use the 4 output pins in parallel to read and decode the keys with multi-touch and return an array of the first 5 keys captured in under 120 clocks. That's the project goal anyway. Hope I can hit it.

    I would think you should be able to do the debounce in software.
Sign In or Register to comment.