Multiple buttons read by one pin: individual and combination

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've found a few other designs that use resistor ladders:

https://www.avrfreaks.net/index.p...

http://tronixstuff.wordpress.com...

However, I haven't seen a formal analysis of what is the "optimal" choice in resistor values for a circuit like this:

Vcc
|
Rup
|______________________ ADC
|
----R1-------S1----|
|                  |
----R2-------S2----|
|                  |
----R3-------S3----|
                  GND

So, for example, if button S1 is pressed, the voltage at the ADC is Vcc * R1/(R1+Rup), etc. There should be an optimal set of R values that spread the ADC values as much as possible (for both individual and combination presses).

I did a little bit of experimenting in a spreadsheet, and found that these values worked best:

Rup = 1
R1 = 2
R2 = 4
R3 = 8

A power-of-two configuration makes sense, but it uses less than half the available dynamic range of the ADC. The smallest interval difference is about 200mV (assuming 5V Vcc), requiring 5 bits of resolution. The software will measure the ADC and pick whatever one is closest. This should be enough, but I'm wondering if there's a way to do better, especially with more buttons. I would think there's a way to calculate the optimal values exactly.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This handles multiple simultaneous switch selections? Like a half dozen toggle switches on a panel?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, it would. The simulation was for three buttons so far, and requires 5 bits of resolution. Unless there is a more optimal set of resistor values, additional buttons would require more ADC resolution.

If switches (SPDT) instead of buttons are used, more traditional R-2R ladders can be used, since you have both "one" and "zero" logic levels explicitly, and (ideally) need only one bit of resolution per switch. With buttons, you only have "one" and "open", which decreases the intervals between analog states, requiring more resolution, and makes it a harder, non-obvious problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To simplify optimization, just modify the topology so that you have a string of resistors and the buttons short across the resistor. That way the power-of-two arrangement should be optimal and you should be able to get connect nine buttons with the 10-bit ADC. I might actually limit it to six or seven buttons, however, so that the signal isn't lost in noise, but theoretically...

Martin Jay McKee

Edit: Thinking some more, there is still a non-linearity created by the fact that the total resistance of the voltage divider is changing, so it still requires more resolution than ideally required with power-of-two taps. It does remove one non-linear element, however, and should, therefore simplify things.

As with most things in engineering, the answer is an unabashed, "It depends."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you can use an R-2R ladder as used for DAC and feed the output to the ADC (ideally through an opamp)

http://en.wikipedia.org/wiki/Res...

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks. Martin, this looks like the best approach for sure.

Alex: I don't think the R2R particular configuration works in this case, as it requires a definitive state for "0" (i.e. SPDT switches instead of SPST buttons), instead of just "open".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I did a little bit of experimenting in a spreadsheet, and found that these values worked best:


Quote:

The simulation was for three buttons so far, and requires 5 bits of resolution. Unless there is a more optimal set of resistor values, additional buttons would require more ADC resolution.

This has been discussed here before, and also "around the Web".

Does this one handle multiple presses?
https://www.avrfreaks.net/index.p...

This one is x4 and claims multiple-press: http://blog.littlebirdelectronic...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

However, I haven't seen a formal analysis of what is the "optimal" choice in resistor values

I have. Must have been in about 2005-2006. Someone had developed a spreadsheet for varying numbers of resistors to give equal sized "bins" for the various ADC value ranges. I think it was on a site like hackaday or similar.