Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Switch Multiplexing

Status
Not open for further replies.

2camjohn

Member
I am trying to save on inputs by multiplexing three switches to use two inputs..

I get the idea in theory, which is that 2 inputs can have 4 states 00 01 10 and 11.

but I cant figure out how to wire up my switches. Simply wiring one switch to both inputs to make a 11 doesnt work for obvious reasons...


The switches are simple push to make buttons using weak pullup resistors (external, not the ones built in to the PIC).


I have googled for switch multiplexing, but cant find anything useful.

If anyone can offer any help on how to wire this up, or point me in the right direction I would be grateful.

Thanks
John
 
2camjohn said:
I am trying to save on inputs by multiplexing three switches to use two inputs..

I get the idea in theory, which is that 2 inputs can have 4 states 00 01 10 and 11.

but I cant figure out how to wire up my switches. Simply wiring one switch to both inputs to make a 11 doesnt work for obvious reasons...


The switches are simple push to make buttons using weak pullup resistors (external, not the ones built in to the PIC).


I have googled for switch multiplexing, but cant find anything useful.

If anyone can offer any help on how to wire this up, or point me in the right direction I would be grateful.

You need blocking diodes to each switch, one for the '01' switch, one for the '10' switch, and two for the '11' switch. In fact, you could do it with only the two for the '11' switch.

It should be obvious how to connect them?.
 
typically, multiplexing only decreases pin count once you get above 5 inputs. you use a number of IO that is the square root of the number of switches (rounded up of course)

with 3 switches, you have a 3x1 matrix, ie- not even really multiplexed. at 4 switches, you would go with a 2x2, which is 4 IO. at 5 switches, you use a 3x2, and use 5 IO. at 6 switches, you still use a 3x2, and so you only need 5 inputs. and from then on you keep going up and up and when you get to 16 or 25 inputs, you are saving tons of I/O.

*edit* i've never looked at these diode methods, perhaps it's possible with those somehow.
 
Actually, using the N*(N-1) multiplexing scheme, you can realize pin savings when you get to 3 pins ---> 3*(3-1) = 6 switches (or 6 LEDs, or 3 switches and 3 LEDs)...

Regards, Mike
 

Attachments

  • n_n-1__switches.jpg
    n_n-1__switches.jpg
    33.3 KB · Views: 1,220
OK, here's a diagram of what I meant, obviously it has no way of discriminating between multiple key presses, but it allows three switches to use only two pins.
 

Attachments

  • switches.gif
    switches.gif
    2.2 KB · Views: 1,099
Hi,
a little disadvantage of the 3buttons/2diodes->2pins solution:
if the 2 single buttons are pressed simultaneously You'll get the same result as if only the 'dioded' button is pressed.
If You got a free A/D-pin You can use it to read all 3 buttons (or more) seperately with only one pin.
regards
joachim
 
If Zcamjohn had one output available, and one input available he could use some programming and hook up 100s of switches..
 
use a 3X8 decoder , and a counter to select its adderss with its clock input connected to the pic output..
set pic to know which pulse is accessing which switch , and connect the pic input through a resistor to the lower part of each switch , sort of hard wired ORed fashion..
on the decoder outputs are your switchs .. on the other end of your switch is a resistor to ground ..
connected across the top of each of these resistors is your pic input..
very hard to explain, a diagram is needed ..
 
2camjohn said:
I could easily make one of my two spare inputs into an output..
Please explain more what you mean?

You could easily use a single pin to read your three switches, use a capacitor charging/discharging technique to read a resistor value - use the switches to select different resistor values.

My joystick tutorial shows one way of implementing this kind of simple A2D technique.

However, it's more complicated than the diode gate way I suggested earlier, which looks to be as much as you need?. You mentioned that two of the buttons are UP and DOWN, use the outside two for those - this means that pressing the outside two together will have the same effect as pressing the middle one. Pressing the middle one with either of the others gives the same response as well.

I'm presuming the third button is 'select', 'OK', or something similar?, so I don't see any problem with that being the centre button.
 
Status
Not open for further replies.

Latest threads

Back
Top