Switch matrix with ring counter

matrixswitches

Hello I am creating a little device, which has a total number of 30 tactile switches arranged in a matrix with 3 rows and 10 columns. My problem is, that I have only left 5 IO pins on my AVR micro-controller. For normal, I would scan my switch matrix, with enabling only one of the 10 columns at a time, and than read the input from the three rows. This is, how I determine the pressed switch, but this would need 13 IO pins.

My first approach, to find a solution was using a ring counter, but I was a little bit confused, on what it actually does, and how it works. I could also find only so called Johnson counters in my preferred electronics store. Can anyone help me out with this?

EDIT: Sorry I forgot to mention, that I also need to detect, if multiple keys are pressed. I am using diodes on each switch to prevent shorting(hope I can call it like this, not so experienced in english).

Best Answer

I'm going to suggest that you learn about shift registers. 4 pcs of a 8-bit parallel-to-serial shift register would work very well for you and would need a maximum of 3 lines to your controller. Some of those lines can even be shared with other functions if you are clever.

The CD4021 is a nice part that I use in many of my designs. You will need a pull-up resistor for each input. I use SIP bussed resistor networks - 10 pin package gives you 9 pullup resistors in a very small space.

You can also mount the shift registers very close to your switches to minimize the number of wires to the controller.