Matrix Keypad Emulation  - Page 1
Forum section: electronics / projects

author: Chet T16
author_rank: Frequent Contributor
timestamp: August 07, 2021, 05:05:04 pm
content: Hi all,I'm looking at emulating a 3x2 matrix keypad with a microcontrollerThe general consensus seems to be to run two cd4051s back to back and I'm not opposed to this this solution in general but I think two 8x1 ICs is overkill here. At first I thought the 4052 would be ideal as I thought it was two 4x1s in the one package.The scan pulse voltage is 12v and I want to avoid driving the 3 inputs directly.Is there a cheap analog mux with 12v input and dual (seperate) 3x1/4x1 mux? Looking through the usual sources it's awash with 4052s or ICs that are 10x the price of a 4051

author: ajb
author_rank: Super Contributor
timestamp: August 07, 2021, 08:02:47 pm
content: I don't see why you'd need two 8-to-1 mixes for a matrix that size. Two 4-to-1 should be fine, you only need as many inputs as rows you have, and only as many outputs as columns (or vice versa).How fast is the scanning? If it's something old and slow and you're using an MCU anyway, it's possible that a modern MCU with appropriate level shifting electronics might be sufficient on its own. Monitor for the scan pulse on each line then assert the appropriate voltage on the other lines. Input could be a voltage divider or transistor, output could be a couple of transistors or a comparator. The frequency of the scanning isn't really significant to whether this will work or not, but the time between asserting a scan pulse and reading the output of the matrix is, so the MCU would generally need to be running at a clock speed significantly faster than the host system you're connecting it to, if the keypad is being scanned directly, but that may not be that hard depending on what it is.If you want/need to stick with an analog switch option, you don't necessarily need to use n-to-one muxes. Since you have 3x2=6 buttons, you could use six simple single-pole analog switches, or you could use a 4x4 crosspoint switch (which is almost the same as two back-to-back 4-to-1 muxes). On a larger matrix the n-to-1-to-m approach is more efficient but with only a 3x2 it hardly matters, it's not that many switches either way.

author: Benta
author_rank: Super Contributor
timestamp: August 07, 2021, 08:44:41 pm
content: A 3 x 2 scanned keyboard needs 5 I/O pins. Reading them directly needs 6 I/O pins. Do you really need to scan here?BTW, scanning is not really necessary, there are much more elegant ways to do thiis.

author: Chet T16
author_rank: Frequent Contributor
timestamp: August 07, 2021, 08:48:07 pm
content: Quote from: ajb on August 07, 2021, 08:02:47 pmThe scanning pulses are 5ms. The timing of inputs reads is an unknown which is why I'd be hesitant to go down this road in case there is anything funny going on.I 100% agree with all the rest you've said, although had never heard of a crosspoint switch until now. My problem seems to remain that from what I can see the use of 2x 4051s is a tenth of the cost of anything else suggested.

author: Chet T16
author_rank: Frequent Contributor
timestamp: August 07, 2021, 08:49:20 pm
content: Quote from: Benta on August 07, 2021, 08:44:41 pmI am not scanning, I am trying to replace a keypad with a microcontroller

author: ajb
author_rank: Super Contributor
timestamp: August 08, 2021, 01:18:32 am
content: 5ms is a long time to read a keypad matrix. Maybe that's just an artifact of how the scan interval is established.If you know you have positive scan pulses then it should be possible to do this with transistors. One PMOS at each switch location with an NMOS+pullup resistor for level shifting your drive signal to it. You'll need diodes at the matrix inputs to prevent backfeeding a scan pulse from one line to the other via the transistor body diodes. This wouldn't scale well to a larger matrix, but 12 transistors, six resistors, and two diodes should be pretty cheap if that's your priority.

author: NiHaoMike
author_rank: Super Contributor
timestamp: August 08, 2021, 03:48:51 am
content: At a previous job, I had to design a board to emulate (up to) a 8x8 keypad for automated testing. There was a crosspoint switch ASIC that fit exactly, pretty quick work to design a board to break it out and connect it to an Arduino, which also did a number of other functions they wanted. There was no need to emulate a "N key rollover" keypad with diodes to allow any combination of keys to be pressed without causing aliasing, if there was, the only solution I can think of is a small FPGA or CPLD to emulate the diode logic of the keypad.

author: gcewing
author_rank: Regular Contributor
timestamp: August 08, 2021, 04:48:57 am
content: Quote from: Chet T16 on August 07, 2021, 08:48:07 pm2x4016 or 4066 is probably about the same price. Which way to go would depend on what is the most convenient way for you to control it -- row/column selection or a separate signal for each switch.