input and save input

Status
Not open for further replies.
Note: These calculations neglected the effect of the pulldown resistor. Corrected results are below.

Here, all the work is done for you MrDEB. This is based on a ladder of 1k, 1% resistors as shown in the table. Build it exactly as shown (with none of your typical improvements) and this table shows the values you will get for each switch. Test* for the range of values shown and it will work every time. Remember, integer math is INTEGER values only - no decimal points.

The range of values for each switch is calculated assuming all +1% resistors on one side of the voltage divider and all -1% resistors on the other. It's extremely unlikely you would get this distribution, but the range calculated here includes all of the possibilities.

* I'm sorry, "test" is going to generate many more pages here.

 
Last edited:
* I'm sorry, "test" is going to generate many more pages here.

Since I can't sleep anyway, maybe we can shortcut this process.

I will assume MrDEB can plagiarize an example to set up and read an ADC channel.

Code:
Dim ADC as word 'ADC value read

Select ADC

     Case <25
           'no button pressed
     Case <96
           'button 1 pressed
     Case <190
           'button 2 pressed
     Case <284
           'button 3 pressed
     Case <378
           'button 4 pressed
     Case <471
           'button 5 pressed
     Case <564
           'button 6 pressed
     Case <657
           'button 7 pressed
     Case <749
           'button 8 pressed
     Case <841
           'button 9 pressed
     Case <933
           'button 10 pressed
    Case > 932
           'something is wrong

End Select

This is a quick and dirty way to test. Why don't you need to test the lower bound of each range? Remember, select case exits when the condition was met. If no button is pressed, the routine kicks out when "<25 " is tested. If button 1 is pressed, the first condition is bypassed and the next selected. A more comprehensive routine could test for each possible range, which would eliminate the possibility of most multiple button presses resulting in erroneous indications.
 
Thanks Mike, I was curious as to where the 51 came from.
I realize resistors are not all the same resistance due to tolerance variation.
After reading Mikes description about why he used certain numbers in his calculations I now understand better about integers etc.
In my simulation program Tina, I added the capacitor and the 100K resistor and the 3v with all open switches took a trip to China. Now the input does not float.
 
This is real life 10 button readings

Button1 = 88
button2 =182
button3 =272
button4 =362
button5 =452
button6 =543
button7 =635
button8 =728
button9 =824
button10 =922
 
Interesting Bert. Your readings are all just a little lower than mine. I did not account for the 100k pulldown resistor, which would lower the reading somewhat.

Considering the top switch, the voltage divider would have 1k on the top and 10k in parallel with 100k = 9091 ohms on the bottom. Re-calculating the nominal value with pulldown resistor results on an expected value of 921.6 ohms. I'd say the math and your results agree!

Sorry I neglected to include the pulldown resistor in my calculations. I didn't think it would have that large of an effect.

 
dang close lol!! Am i the only one to lose the parts you want work with lol
been looking fo days can't find them. lol
 
dang close lol!! Am i the only one to lose the parts you want work with lol
been looking fo days can't find them. lol

No. I can be sitting in one place, not moving, and loose something. Or I put something in a safe place so I can find it...and forget where.
 
The nRF24L01 2.4G Wireless Transceiver Module i lost 4 of them
Add some of these and you could play wireless.


Jon what did you draw with I'm looking for a app like that.
 
Last edited:
Here are the calculated steps for the nominal resistance values including the 100k pulldown resistor which I originally neglected. Pretty close to Bert's measured values.

922
824
728
634
543
452
363
272
182
92

Calculating the bounds for each step based on resistor tolerance is a simple but tedious exercise. Perhaps MrDEB could learn something if he tried it.

Consider one step as an example. The top switch has a single nominal 1k resistor on the "top" of the voltage divider, and 10 1k resistors on the bottom in parallel with a 100k resistor.

The lower bound may be computed if the top resistor is 1% high while all the resistors on the bottom are 1% low. R1 = 1010 ohms. R2 = 10 × 990 ohms in parallel with 99k ohms = 9k ohms.

ADCout =1023 × 9000/(9000+ 1010) = 919 counts.

Reverse the high and low tolerances to find the upper bound, which equals 924 ADC counts.
 
Bert, they will think we dry-labbed this one! Your measured values and my calculated values are almost exactly the same.

Got to love it when science works!
 
Bert, they will think we dry-labbed this one! Your measured values and my calculated values are almost exactly the same.

Got to love it when science works!
Yep the math is really close to the real thing the 88 did hit 92 I was sleepy I didn't change it I tested like five presses 92 3 of them 88 was 2 of them
 
Very en-lighting reading, Thanks guys.
ONE interesting I noticed was where did the 10k resistor come into play. Looking at example in post #126 there is no 10K resistor but in post# 145 it makes an appearance. No big deal as when I breadboard the ladder am going to replicate circuit as well.
Jons example is different than what Mike posted with inserting 51 and 102 but am going to experiment using both examples.
the equation A0-out=(R2/R1) * 1023 is easier to see what is going on with the ADC equation.
 
LOL math my man math you have 10 resistor they add up to 10 k then one the divides plus 1 100k and a cap that keep's the pin from floating.

Mike posted a range 52 to 102 he's mapping 10 buttons to a center point so the supply don't matter.
 
ONE interesting I noticed was where did the 10k resistor come into play. Looking at example in post #126 there is no 10K resistor but in post# 145 it makes an appearance. No big deal......


Ahh, actually, it's a very big deal to understand "where the 10k eesistor came from". If you don't understand that, you are lost.

In this ladder there are a total of eleven 1k resistors connected in series from Vdd to ground. Consider what happens when the switch closest to Vdd is pressed. You have a voltage divider. A single 1k resistor on the top, and ten 1k resistors on the bottom (neglecting the pulldown resistor for now). Resistors in series add. 10 × 1k = 10k. If you look at a classic voltage divider picture, R1 on the top = 1k, R2 on the bottom = 10k when the first switch is pressed.

When the 2nd switch is pressed, the R1 of the voltage divider = 2 × 1k = 2k, and the R2 = 9 x 1k = 9k.

And so on and so on and so on.

But the situation is complicated a little. In our voltage divider R2 is paralleled by the 100k pulldown resistor. Look up how parallel resistors add.
 
Last edited:
Jons example is different than what Mike posted with inserting 51 and 102 but am going to experiment using both examples.

Do youself a favor and do it the way Bert and I have. The numbers are all ready worked out for you so we don't have to figure them out again because Lord knows you will have problems with it.
 
Last edited:
Got time to experiment with this as per post #126 including the 100K resistor and capacitor. These measurements are EXACTLY what the CASE SELECT section of code is outputting using 12 LEDs to indicate what the ADC is actually doing.
I see no pattern to determine what the Case Select uses to compare to
Starting at the 2K resistor junction
184, 256, 276,309,320,363,384,407,431,461
This took some time but I wanted to see and compare with posted suggestions.
And yes I realize the breadboard circuit will produce different results but the figures I posted will be in the ballpark.
And yes I tried ALL the posted suggestions.
 
Just to add a little 'story' to this method of using switched resistors and an A2D for reading multiple switches.

This technique was used a LONG, LONG time ago on early JVC VCR's - back before IR remote controls they used to use a corded remote, which used a 3.5mm jack plug, and a number of switched resistors inside the remote.

Nice idea, but poorly implemented - for two reasons:

1) One of the buttons switched directly across the cable, giving 'zero' ohms (I think it was the Play button - in any case, it was one commonly used).

2) The next button up from that (the next lowest resistor value) was the record button.

So this gave an unfortunate result, the cable for the remote tended to get bent and twisted, and started to give significant resistance in the cable. So when you pressed 'Play' it could inadvertently go to Record instead, erasing what you were trying to watch - which could be quite disastrous. I repaired countless remotes for this fault, replacing the existing wire with thin microphone cable, and a new 3.5mm jack plug.

I see that you aren't using 'zero ohms', but it still might be a good idea to consider which button you use for each option, just in case something strange happens (like a poor contact in a switch, giving a higher resistance reading).
 
I have no clue what you are doing, but if you have followed Burt's and my suggestions with a resistor ladder of 1k resistors, you should end up with 10 steps approximately equally spaced between 0 and 1023. If you don't get similar results, it means you don't have things connected like you think you do. Not that that's a big surprise.

I don't know exactly what you've done, but you've managed to crowd all the values into less than half the ADC range, meaning you may have problems with drift. I have found that unexpected results will come back to haunt you unless you figure out why the results aren't as expected.

I suspect you have an error in the location of the 10k resistor, putting it in series with the rest of the ladder, which would compress your results to less than half scale.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…