***20M PICAXE Ohmmeter Issues***

Thread Starter

Kian Nikzad

Joined Apr 5, 2018
I've built a circuit that is supposed to shine certain number LEDs depending on the resistance of a resistor in the circuit (R1). I did this by setting up a voltage divider and measuring the output voltage (Vout) using readadc.

The LED's aren't lighting up properly (some of them light up for some resistors, but there is no clear pattern). When I simulate on PICAXE editor, for both low and high ADC values the LEDs light up, which doesn't make any sense. When ADC is low, there should be more LEDs lit up than when it is high.

- My equation for R1 using a voltage divider is R1 = (Vin*R2 - Vout*R2)/(Vout)

- R2 = 10,000 ohms

- Vin = 4.8 (24/5)

- I divide at the end of statements to minimize data lost from the integer rounding down PICAXE does. Wherever you see multiplying and dividing by 100 in the code I am trying to minimize data loss as well (ex. .90 rounds down to zero, while 90 is untouched). The multiplying by 100 should cancel in the statement w3/w0.



My code is below:

readadc 1,b1

w0=100*b1*24/5/255 ;output voltage, converts readadc to voltage * 100
w1=24*10000/5 ;first term numerator, see R1 equation below
w2=10000*w0/100 ;second term numerator, divided to rid of 100 in w0
w3=w1-w2*100 ;numerator total * 100
w4=w3/w0 ;total (the 100s cancel)

if w4>0 then
high B.3
if w4>500 then
high B.4
if w4>1000 then
high B.5
if w4>1500 then
high B.6
if w4>2000 then
high B.7