1
\$\begingroup\$

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.

\$\endgroup\$
  • 3
    \$\begingroup\$ It depends. Can two buttons be pushed at the same time? Can N buttons be pushed at the same time? How fast should it be? \$\endgroup\$ – Eugene Sh. Sep 24 '15 at 19:30
  • \$\begingroup\$ @EugeneSh. Well, if this matters, the short answer is no. Only one single button will be pushed at the same time. \$\endgroup\$ – Michel Gokan Sep 24 '15 at 19:31
  • \$\begingroup\$ @EugeneSh. Oh and it won't be fast, it will be in human speed. Maybe 10-20 buttons per second. (one by one, not at the same time) \$\endgroup\$ – Michel Gokan Sep 24 '15 at 19:33
  • 2
    \$\begingroup\$ Than an encoder (or Priority encoder) is the circuit that is doing this job. It will compress 2^N inputs into N. The point is that probably you won't find any 128bit-wide encoder on the shelves. So I would look into the direction of semi-analog solution similar to this. Or just use an FPGA (kinda overshoot) \$\endgroup\$ – Eugene Sh. Sep 24 '15 at 19:41
  • 1
    \$\begingroup\$ Another possibility would be to use a PISO shift registers chained, while reading them serially. \$\endgroup\$ – Eugene Sh. Sep 24 '15 at 19:42
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I think this would work for me : arduino.cc/en/Tutorial/ShiftOut ... Because I'm using arduino. What do you think ? \$\endgroup\$ – Michel Gokan Sep 24 '15 at 20:23
  • 1
    \$\begingroup\$ I think you can do that, but shift in. Note the part number is different for PISO vs. SIPO shift registers. \$\endgroup\$ – Spehro Pefhany Sep 24 '15 at 20:26
  • 1
    \$\begingroup\$ Yes, that's the exact idea (using a different shift register). As I said though, some complications will manifest if you try to expand this too much but 128 shouldn't be a problem. \$\endgroup\$ – Spehro Pefhany Sep 24 '15 at 20:47
  • 1
    \$\begingroup\$ Yes, probably with modifications to buffer the two clock lines (called clock and latch in the Arduino tutorial). And not too fast or too physically large. The two outputs could drive 8 buffers each which could drive 150 chips (not too fast). Still only 3 microcontroller pins required! \$\endgroup\$ – Spehro Pefhany Sep 24 '15 at 20:59
  • 1
    \$\begingroup\$ Yes you can read any combination of switches captured at one instant in time. You get one bit for each switch. \$\endgroup\$ – Spehro Pefhany Sep 25 '15 at 3:48
14
\$\begingroup\$

Break the buttons into rows and columns, like is done with a keyboard. 12x12 will give 144 possible buttons, so should work.

Then you'll need to use encoders to translate those lines into binary. 3 of 8-bit encoders will take in all 24 lines and give you 9 bits to connect to your microcontroller.

\$\endgroup\$
  • 2
    \$\begingroup\$ Looking at how keyboards work is the right answer, particularly if you're really going up to huge numbers, as your i/o complexity grows as the square-root of the number of switches, rather than linearly. \$\endgroup\$ – user1844 Sep 24 '15 at 20:40
  • 1
    \$\begingroup\$ Yes, especially with the notation that only one button will be pushed at a time and the necessary polling rate is low, this sounds like an good solution. \$\endgroup\$ – Chris Stratton Sep 24 '15 at 21:55
  • \$\begingroup\$ Won't it be 10 bits (8 bit per encoder, plus 2 bit for choice of encoder)? Also, I am a bit confused by this question, because with 12x12 I would expect that you need 12 output lines and 12 input lines, so one 12-bit encoder and one 12-bit decoder? \$\endgroup\$ – Cactus Oct 22 '15 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.