#### catalina

##### New Member
Trying to programme an 08M to read a varying adc input using readadc10 four times at 0.5 second intervals and if the value at each reading <778 (which corresponds to a particular voltage) place it in a variable, eg b1 b2 b3 b4, for each reading. After the 4th reading, if the sum of the variables b1 to b4 = 3112 (778x4) then go to another routine. I'm trying to ascertain when the varying input becomes constant for 2 sec. My programme reads,

main:
if b1<778 then check1 'if b1 less than 778 then go to check1
if b1,b2,b3,b4 = 3112 then wakeup 'if the sum of variables b1- 'b4 = 3112 then go to wakeup

check1:
pause 500
if b2<778 then check2

check2:
pause 500
if b3<778 then check3

check3:
pause 500
if b4<778 then return

The syntax checker reports an error on the 3rd line in main. I've tried changing this line to read "if b1+b2+b3+b4 = 3112 then wakeup" but the error is still there. Note- wakeup routine not listed

Is it correct to assume rapid readings of the same adc input can be placed in different variables? If, so how can these variables be added?

#### BeanieBots

##### Moderator
Therefore, you need to use word variables because bytes can only hold a max of 255. word max = 65535
Similarly, your tests are on byte values against values larger than 255.
Also, remember, each word uses two bytes. eg w0 uses b0 & b1

#### Michael 2727

##### Senior Member
Read the picaxe_manual2.pdf on both the above.

Also read the above manual on, Variables - Mathematics.

#### hippy

##### Technical Support
Staff member
- if b1,b2,b3,b4 = 3112 then wakeup

- if b1+b2+b3+b4 = 3112 then wakeup

Neither are valid syntax. in PICAXE Basic one can only compare a single variable with another variable or constant. Taking into account teh change needed to go from bytes to word for use with READADC10, you'll need something like ...

- w0 = w1 + w2 + w3 + 24
- if w0 = 3112 then wakeup

I'm not sure if all the code you are using is in what you posted but it doesn't look like it to me.

As your readings may not be absolutely spot-on for any particular volatge you will probably want to wakeup on a range. How narrow that range is will have to be determined by experimentation -

- w0 = w1 + w2 + w3 + 24
- if w0 >= 3110 and w0 <= 3114 then wakeup

#### jonphenry

##### New Member
Compounding on hippys advice youd be looking at something like this

main:

if w0<778 then gosub check1
let w4=w0+w1+w2+w3
if w4>=3105 and w4<=3119 then wakeup
goto main

check1:
pause 500
if w1<778 then check2
goto main

check2:
pause 500
if w2<778 then check3
goto main

check3:
if w3<778 then return endif
goto main

wakeup:
high 3
pause 2000
low 3
goto main

#### catalina

##### New Member
Many thanks to all for your responses.

The problem lay with the expression in line 3. Changing this to read

let b5 = b1+b2+b3+b4

proved ok and the programme now checks ok for syntax and runs ok.

I've taken on board the comments regarding word and byte variables as well as the desirability of a voltage range.