Electronic – Reading hundreds of inputs with a single atmega32

atmegaavrmultiplexer

I have 128 inputs (push buttons) in a single row in a project and I want to read them using a single atmega32. Of course there is not enough pins in an atmega 32 for this purpose and I know the solution would be using some kind of multiplexer but I don't know which one suits the best.

What I'm thinking is to have some kind of multiplexer that have 128 pins as input and have 7 pins for output that represents the result of inputs into binary (as an example if all inputs were 1 (UP) and output pins will be 1111111 (all UP)). But I'm not sure if there is any multiplexer doing this ?

I have to mention that I need a cost effective solution. Becasue I have to extend this solution to maybe 1000 or even 10,000 inputs in the future (which we have to use several multiplexers to read all of them)

Any help would be appreciated. I need to know which multiplexer I need to use ? (probably part no. or any other suggestion)

Update:

Only one single button will be pushed at the one given time AND it update rate won't be fast. maybe 10-30 times per second or much less.

Best Answer

An easy approach would be to use hardware SPI to read shift registers serially.

You could daisy-chain as many 8-bit shift registers as required. If you use 74HC165 you could simultaneously sample each switch (1/8 74HC165, 1 resistor required per switch) and then shift the data to the micro at perhaps 10MHz, so you could get 1000 switch states in 100 usec or 10,000 in 1ms. 10,000 inputs would require 1250 shift registers so you would need to buffer the clocks and/or reduce the shift rate.

Physical bus length will become a problem at high clock rates- you have to make sure that datasheet setup and hold times are observed.