Reading many switches with few pins

For the discussion of the sciences. Physics problems, chemistry equations, biology weirdness, it all goes here.

Moderators: gmalivuk, Moderators General, Prelates

mikeonsixstrings
Posts: 8
Joined: Thu Jun 05, 2008 3:47 am UTC

Reading many switches with few pins

I was recently considering ways of referencing many switches from a few pins on a microcontroller, as in a keyboard or similar. It occurred to me to place the switches such that they would route current through different resistances:

This should be possible as long as the resistances were determined in such a way that each possible sum of them would be unique.

So for the sums of any number of resistances A and B, A != B.

I created a few series and it seems that any geometric series would work: 1, 2, 4, 8, 16, 32

It seemed cubes and higher powers of arithmetic series were also possible: 1, 8, 27, 64, 125
That may have been an overzealous extrapolation of Fermat's Last.

I imagine issues would arise from voltage resolution rather quickly, especially if low tolerance resistances were used. I would estimate that a single pin should be able to handle 6 switches comfortably however. Standard matrix-scanning setups with n pins have a switch-to-pin ratio of n/4. This method would have a constant switch-to-pin ratio of 6, which is much improved unless dealing with upwards of 24 pins, or 144 switches. The two techniques could even be combined, offering a 3n/2 switch to pin ratio. This third alternative would produce (3/2)*n^2 switches, a phenomenal increase in density over the (1/4)*n^2 of using a matrix alone.

Has anyone heard of prior implementation of this method?

Also, mathematically, what are some ways one could determine an ideal series of resistances?

Goemon
Posts: 442
Joined: Mon Nov 19, 2007 4:57 am UTC

Re: Reading many switches with few pins

If you have a moderately expensive car which has switches on the steering wheel for speed control and/or operating the radio or other systems, you've seen this method at work

Since the steering wheel can typically rotate one or more full turns in each direction, it's not easy to get wires from the wheel mounted switches to the body of the car. It's done using a "clockspring", a device that's basically a big spring which wraps around the steering column shaft. The spring gets wrapped more tightly when turning the wheel in one direction, and loosens in the opposite direction. Obviously, it has to have enough turns initially to accomodate the full range of motion of the wheel.

It's much more difficult to build a reliable clock spring that has multiple wires in it. So the system is designed exactly like you proposed - with a group of resistors on the steering wheel that get connected in various combinations to the clockspring according to which buttons you push. An integrated circuit on the body side interprets the signals and performs the corresponing function.
Life is mostly plan "B"

ks_physicist
Posts: 230
Joined: Wed Jun 27, 2007 10:09 am UTC

Re: Reading many switches with few pins

I guess my Plymouth Neon is "moderately expensive" then.

Five switches control the cruise functions (on, off, set, cancel, resume), but only one signal line (and a common ground). They use similar logic to the original poster's--resistances that do not duplicate in combinations.

Minerva
Posts: 947
Joined: Sat Nov 11, 2006 2:58 pm UTC
Location: Australia
Contact:

Re: Reading many switches with few pins

Here's a schematic that a friend of mine designed that implements this technique.
(It's a fancy, elaborate stepper motor controller for a CNC milling machine, before anyone asks.)

(Fairly large image does 900 damage.)

http://imagestore.ugbox.net/image/steps ... 17a850.jpg
...suffer from the computer disease that anybody who works with computers now knows about. It's a very serious disease and it interferes completely with the work. The trouble with computers is you play with them. They are so wonderful. - Richard Feynman

MarvinM
Posts: 95
Joined: Tue Jul 29, 2008 11:45 pm UTC

Re: Reading many switches with few pins

If you only needed a matrix style input, IE one key at once, then using a power line that was +V on one phase and -V on the other, then you could move to 2D scanning with diodes (only doubles the number of switches if you want to know the state of every switch). If you added capacitors you could scan in 3D, final voltage on one phase is the X final voltage on the second phase is the Y and the time constant getting there is the Z. There's more! By adding another diode and a resistor you can give it a different time constant in one direction to another for 4D scanning. By this point you need a capacitor, 3 resistors and 3 diodes for each button which probably makes it cheaper to use a PIC and serial communications. That's potentially over a thousand keyboard style buttons (or 24 switches if you need to know the state of every one individually) multiplexed onto one output pin though. Want to go crazy and add an inductor for 5D, two inductors (each direction one in series with a diode) for 6D scanning? Of course all of this increases the workload of the MCU and you need more samples over a longer period to extract all the information. If you want the ultimate in state of every switch on one line, then maybe instead of feeding DC voltages you could feed white-noise, or a chirp and have many RC circuits on every switch and get the states from the resulting pattern of harmonics. In two directions with diodes and DC offsets and both directions and resistors muaahaha and 87D billion trillion wooha quadrilli

No Nurse I wasn't getting excited.

Yes Nurse I know it's time for my Thorazine.

Thank you Nurse.

eternauta3k
Posts: 519
Joined: Thu May 10, 2007 12:19 am UTC
Location: Buenos Aires, Argentina

Re: Reading many switches with few pins

This technique is used by lego enthusiasts to multiplex touch sensors (link)
VectorZero wrote:It takes a real man to impact his own radius

That's right, slash your emo-wrists and spill all your emo-globin

Solt
Posts: 1912
Joined: Tue Mar 27, 2007 5:08 am UTC
Location: California

Re: Reading many switches with few pins

Pretty cool (and clever), though it requires a dedicated ADC pin and a bit of extra code.
"Welding was faster, cheaper and, in theory,
produced a more reliable product. But sailors do
not float on theory, and the welded tankers had a
most annoying habit of splitting in two."
-J.W. Morris

evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Reading many switches with few pins

effectively what you are doing is implementing a DAC
in ur beanz makin u eveel

thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: Reading many switches with few pins

A good point. It might be worthwhile to use a cheap DAC chip instead, since your resistances will be more precisely controlled, and there would be fewer components. Something like this, perhaps.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Solt
Posts: 1912
Joined: Tue Mar 27, 2007 5:08 am UTC
Location: California

Re: Reading many switches with few pins

evilbeanfiend wrote:effectively what you are doing is implementing a DAC

Good point. In a binary representation of a decimal number, every combination of states in binary has a unique number.

In fact (correct me if I'm wrong), that tells you the maximum resolution of this strategy. An 8 bit ADC has a maximum resolution of 1 in 28 = 256. 8 switches have 256 possible states. Assuming you have no noise, then, the maximum number of switches is the resolution of the encoder.

You can get far higher densities using 100% digital components, if you were so inclined, but you'd probably need at least one extra pin to use as a clock.
"Welding was faster, cheaper and, in theory,

produced a more reliable product. But sailors do

not float on theory, and the welded tankers had a

most annoying habit of splitting in two."

-J.W. Morris

mikeonsixstrings
Posts: 8
Joined: Thu Jun 05, 2008 3:47 am UTC

Re: Reading many switches with few pins

evilbeanfiend wrote:effectively what you are doing is implementing a DAC

Excellent point. Using a DAC also simplifies code greatly, as the function between the digital input and voltage output is linear. So if one used the 8-bit DAC you suggest, I suppose the question is what sort of processor time would one consume using an Analog pin on a microcontroller (including the calculations) versus, say, some sort of serial input?

Solt
Posts: 1912
Joined: Tue Mar 27, 2007 5:08 am UTC
Location: California

Re: Reading many switches with few pins

mikeonsixstrings wrote:
evilbeanfiend wrote:effectively what you are doing is implementing a DAC

Excellent point. Using a DAC also simplifies code greatly, as the function between the digital input and voltage output is linear. So if one used the 8-bit DAC you suggest, I suppose the question is what sort of processor time would one consume using an Analog pin on a microcontroller (including the calculations) versus, say, some sort of serial input?

I think you'd save a lot of processor time and probably a lot of code. Once you get the value from the ADC, you just have to save it then look at the bits you are interested in. It would be almost no burden on either resource. Of course, you have to add more hardware.
"Welding was faster, cheaper and, in theory,

produced a more reliable product. But sailors do

not float on theory, and the welded tankers had a

most annoying habit of splitting in two."

-J.W. Morris