Electronic – Options to read an 8×8 switch matrix

microcontrollerswitches

I have a project (pinball machine) that will have a decent number of microswitches that will be connected in an 8×8 switch matrix. I'm trying to determine what my options are for reading this matrix without consuming a large number of pins on a microcontroller.

I tried looking for an IC designed specifically for such an application (scanning a large number of buttons) but all I could find is the TCA8418 and TCA8418E chips from TI, looking for similar chips lead me to a couple others but they all share a common problem. They're only in QFN or BGA packages which is beyond my ability to hand solder. I know it's possible, but not something I want to undertake. Those chips are beautiful for this though, it's a real shame.

Alternatively, I've looked at 16 port bus extenders that can be communicated with via I2C or SPI. These seem to be a good option, but I worry about missing button presses. The pinballs will be racing around rapidly, so probably in the millisecond range. That isn't all that fast in terms of an MCU, but it's going to be busy doing a lot more than just reading switches (audio, dot matrix display video feed, and an 8×8 matrix of LEDs). On top of that, it would have to handle switch bounce.

My other concern is the necessary diode that may cause V(il) to creep up towards the 0.8V limit of LVCMOS. A 2×2 example is below.

I've also considered using a small 8-bit microprocessor to be dedicated to keyscanning, it could probably emulate the function of those TCA8418 chips. But I'd have yet more code to write, and another source of bugs to work out. They're about the same price as the bus extender though, so if it's a superior solution than it is what it is.

Is there something else out there, or some method for scanning large (ish) arrays of switches/buttons?

schematic

simulate this circuit – Schematic created using CircuitLab

Best Answer

I wouldn't try to get too clever, you'll just make your circuit more troublesome in the long term. Do you really need a switch matrix? Why not just use multiple port expanders or shift registers? Those should be fast enough. If not, many come with an interrupt output which you can hook up to your micro to make it INSANELY fast. That will also eliminate the polling overhead. If you can get away with a micro that has a lot of IO, like the Arduino mega I would go with that instead.

Many port expanders and shift registers are available in dip packages. For example the MCP23017-E/SP https://www.digikey.com/product-detail/en/microchip-technology/MCP23017-E-SP/MCP23017-E-SP-ND/894272

And here's a shift register you could use: CD4021B https://www.digikey.com/product-detail/en/texas-instruments/CD4021BE/296-2040-5-ND/67261

You can easily daisychain multiple shift registers together to get as many inputs as you need.

Tutorial: https://www.arduino.cc/en/Tutorial/ShiftIn