Help with PushButtons on ADC input?

OLDmarty

Senior Member
Hi All,

I'm looking to replace a bunch of pushbuttons on 8 bits of a port by simply using a resistor divider into 1 pin (ADC input).
This free's up a load of pins for other uses.

My drawing shows what i plan to do, but are other people using a better approach?

23237

In my drawing, assuming NONE of the pushbuttons are pressed, then R1 will hold the ADC to the highest amount of the resistor ladder.
I will map a lookup ( or Select..Case) table so that this HIGH value is ignored or considered a 'home' position when no buttons are pressed.

Pressing any the other 4 buttons will obviously create different voltages levels going into the ADC pin.
I've used Select..Case in a similar fashion before, where i setup some 'zones' of a pot to keep it clear of the adjacent 'zone' for stable readings.

So, if the 4 buttons pressed presented readings into the ADC of say 47, 103, 151, 218, i would setup some 'zones' to become:
47 = Range of 40 to 60
103 = Range of 80 to 120
151 = Range of 140 to 160
218 = Range of 190 to 210

The zones will ensure any slight changes in resistors, or pushbutton pressure/conductivity will always give a precise result in the Select..Case table.

Am i on the right track? or should the resistor ladder be improved or done completely differently?
 

marks

Senior Member
Hi OLDmarty,
perhaps have a look at this thread which is similar to what you have come up with so far
 

OLDmarty

Senior Member
Hi OLDmarty,
perhaps have a look at this thread which is similar to what you have come up with so far
Thanks for that, geez, i'm pretty close on the resistor/button network, that's funny ;-)
 

techElder

Well-known member
OLDmarty, be sure and test for the cases where multiple/ALL buttons are pressed at the same time, because I just love to test equipment for the events that occur when I do that. I've found a few pieces of commercial equipment that the engineers forgot a thing or two. :D
 

hippy

Senior Member
Am i on the right track?
You are. If you map your input values you can find mid-points between the results and differentiate input pushes from that -
Code:
0   40  60     80  120     140 160     190 210       255     
|    ____       _____       _____       _____          |
|---|____|-----|_____|-----|_____|-----|_____|---------|
            |           |           |           |
           70          130         175         235
Code:
Select Case adcReading
  Case < 70  : buttonPush = 1
  Case < 130 : buttonPush = 2
  Case < 175 : buttonPush = 3
  Case < 235 : buttonPush = 4
  Else       : buttonPush = 0
End Select
You might want to increase your top resistor to 2 x 1K, which will help maximise the differences between button push values.
 

hippy

Senior Member
OLDmarty, be sure and test for the cases where multiple/ALL buttons are pressed at the same time,
I don't think that is possible with the scheme proposed. As soon as a higher button is pushed its point on the resistor ladder is pulled to 0V and buttons below are ignored.
 

OLDmarty

Senior Member
OLDmarty, be sure and test for the cases where multiple/ALL buttons are pressed at the same time, because I just love to test equipment for the events that occur when I do that. I've found a few pieces of commercial equipment that the engineers forgot a thing or two. :D
Haha, cheeky. Yep, i planned to add in combo patterns, but i thought the Select..case would just ignore any values that i haven't defined in my mapping. I will test to prove it anyway "just in case" ;-)
 

OLDmarty

Senior Member
You are. If you map your input values you can find mid-points between the results and differentiate input pushes from that -
Code:
0   40  60     80  120     140 160     190 210       255    
|    ____       _____       _____       _____          |
|---|____|-----|_____|-----|_____|-----|_____|---------|
            |           |           |           |
           70          130         175         235
Code:
Select Case adcReading
  Case < 70  : buttonPush = 1
  Case < 130 : buttonPush = 2
  Case < 175 : buttonPush = 3
  Case < 235 : buttonPush = 4
  Else       : buttonPush = 0
End Select
You might want to increase your top resistor to 2 x 1K, which will help maximise the differences between button push values.
Yep, i was thinking about making R1 either 2k2 or 4k7 during testing, but i wanted to play with what numbers and ranges i would get, so it's noted to be tested ;-)
 

techElder

Well-known member
but i thought the Select..case would just ignore any values that i haven't defined
What I would test first is multiple tapping on multiple buttons to see how fast your ADC routine converts. :D
 
Top