nexbie adc problem

cobber

New Member
Hello all,
I am suffering from a problem with adc compares.
I am reading an input on adc 0 into B0, reading a upper limit on adc1 (b1)and a lower linit on adc 2 (b3).
How do I compare the register values of the variables b0, b1 etc.
I have tried if B0 >= B1 then etc but this gives me a syntax error which means it is incorrect. I assume these variable registers contain the values read by the adc and are positive integers from 0 to 5 volts.
What am I doing wrong. The examples all show b0 variables being compared to 1 or another number and if I make b1 an integer it passes the syntax ok.
If b1 is equal to an integer then what is the register showing when the 2 variables are compared.
Would appreciate any help.
Cobber
;)
 

Jeremy Leach

Senior Member
Hi Cobber,

I think it would help to see your code if you could post it - sounds like a simple setback once we know exactly what you've done ;-)

The adc values are integers 0 to 255 and the if statements should work.
 

BCJKiwi

Senior Member
If the issue is monitoring the level of a single voltage and determining when it is too low or too high, then only 1 ADC pin needs to be monitored, the rest is handled in programming.

A ReadADC pin,var will leave the var, say b0, with a value between 0 and 255 representing the level of voltage on the ADC pin between 0V and PICAXE +V (usually 5V). So if the ADC is seeing 3V, on an 08M, ReadADC 1,b0 will contain 255/5*3 = 153, or, 3/5ths of 255
So the numbers will not be integers from 1 to 5, but from 0 to 255 or 0 to 1023. However this would cause a syntax error. We need to see the program to see what is happening.

If, however the command is ReadADC10, a word variable must be used as ReadADC10 will return 1023, not 255 at full supply voltage. so for 3V on ADC with a 5V supply, w0 will contain 3/5 of 1023 = 613.

The program, by monitoring the one ADC pin repeatedly, can determine when the voltage reaches the lower limit, or the higher limit.

Trust this helps. Check manual2 again, and if still having problems, post the code you have, the circuit you have, and a fuller description of the task.

Further help will, I'm sure be available then. Remember, while you understand what the task is, we do not, so the more info you can supply, the more helpful we can be.
ReadADC on 0,1 and 2 suggests an PICAXE 18 or better, which do you have?
 
Last edited:

hippy

Ex-Staff (retired)
"If b0 >= b1 Then" and so on does work so it's how you are trying to use that command which isn't quite right. Post your code and let people have a look at exactly what's causing the syntax error.
 

moxhamj

New Member
Yes, as hippy says, that is correct syntax, though the lines after might not be right. endif etc? Or all on one line Or a little character has accidentally slipped in somewhere - a , or a ' or a \ or something. Copy and paste code exactly as it is coz this should hopefully be a really quick thing to fix.
 

cobber

New Member
its always the obvious

Thanks everyone for your prompt replies.
It is always the obvious staring you in the face that traps you.
After reading yoiur replies I rewrote from scratch and it worked.
My eyesight must be bad. I stared at bo for so long and it did not register that it wasn't b0. This is really on the nose.

As they say " check it, check it and check it again."

thanks cobber
 

vk6bgn

New Member
... maybe if it was boo rather then just bo, it would of got your attention. ;) Boo!

Only joking Cobber! Been there, done that myself too.
 
Last edited:
Top