readadc10 question schematic and code

I want to read values (W1) between about 10 and 500. I setup the circuit on a breadboard but would like some input before I power it. My primary concern is the values of R5, R6, and R3.
The code is:
Code:
Symbol Dly=W0
readadc 0,W1 
Dly=w1/10 min 10
And the schematic is in the pdf attached.
 

Attachments

womai

Senior Member
Hi,

I looked through your schematic.

- I think Diode D1 is there for protection of the Picaxe? Noble thought, but it will negatively affect your ADC measurements because the Picaxe takes its supply voltage VCC as reference (VCC being 100%), and your diode introduces a voltage drop of about 0.7V from the 5V supply. That drop will change with temperature and with supply current, and be somewhat different from one diode to the next. I recommend removing D1 altogether.

- Add a 0.1uF ceramic capacitor between Picaxe pin1 (reset) and ground.

- Add a resistor (about 180 Ohms) between the SEROUT pin and the connectors - this will protect the output against accidental short circuits.

- the impedance of your voltage divider is close to the maximum allowed (10 kOhm) for accurate measurements - its effective source impedance is somewhere between 5kOhm (slider on the very bottom) and close to 10 kOhm (slider close to top). You may want to think about making all three resistors smaller by 10x, or at least make R3 10k instead of 100k (the latter is the better solution if your circuit is battery powered and you want to minnimize current drain). You can use one of those multi-turn trimmers (instead of single turn) to make accurate adjustments easily.

- I've just re-read your post - you say you want to get values between 10 and 500. Why not simply use the full ADC range (0 to 1023) and change the scaling. In that case a single potentiometer would do, i.e. remove R5 and R6 completely and make R3 = 10 kOhm. Then change the code to

Symbol Dly=W0
readadc 0,W1
Dly=w1/2 min 10
Your current schematic will give you values of approx. 500 to 550, which your code would reduce to 50 to 55 - nor quite what you intend to do.

Wolfgang
 
Last edited:

wapo54001

Senior Member
My coding is pretty crude, but I think these two options will work for you (depending on what you want to read -- full range or limited 10~500

In the first code I'm assuming you really want the output to read between 10 and 500 from a full range input. Input can be full range, 0~5V, see simple schematic attached, and a straight line formula will convert the 0~1023 input to a 10~500 output.

This is the formula that will convert a full range input to a 10~500 output:

m= 34/71 and b=10

so I think this will work

Code:
'w1 = input readADC10
'w2 = output

'main program
main:

'read input potentiometer
readADC10 0,w1

'convert full range input to limited 10~500 output
w2 = w1 * 34 / 71 + 10

'output to computer monitor
sertxd (" Input: ",#w1)
sertxd ("   Output: ",#W2,cr,lf)

goto main
If you want to read an input of 10~500 and output the same (untranslated) value, then use a 10K pot and a 10K fixed resistor in series from ground to +5. That will give you an adjustable input of approximately 0~512 range.

Then use this code:

Code:
'w1 = input readADC10
'w2 = output

'main program
main:

'read input potentiometer
readADC10 0,w1

'limit value to 10~500 output
W1 = W1 MIN 10
w2 = w1 MAX 500

'output to computer
sertxd (" Input: ",#w1)
sertxd ("   Output: ",#W2,cr,lf)

goto main
 
Thank you for the very thorough replies Wolfgang and Wapo.
I will try on a breadboard the different approaches suggested .
Andres
 
Last edited:
Top