Syntax Error for a symbol

rjandsam

Member
Hi the following code comes up with a syntax error, but when I replace sensor1 for d.6 it compiles.
Any ideas or is this an editor problem?

Thanks
Rich

#picaxe 40x2
Symbol Sensor2=d.7
Symbol Sensor1=d.6

main:
readadc10 Sensor1, b1
goto main


ERROR MESSAGE
readadc10 Sensor1, b1
^
Syntax error on line 6 at/before position 10

Error: Valid ADC channels are 0-27 only!
 

hippy

Technical Support
Staff member
This is because X2 devices expect to see an ADC channel number in READADC and READADC10 commands. While the compilers can automagically determine what the ADC channel number is from a port.pin reference within the command, it cannot do that when a symbol defined as port.pin is used.

On a 40X2, pin D.6 is ADC Channel 26 and pin D.7 is ADC Channel 27, so this should work -

Code:
#picaxe 40x2
Symbol Sensor1 = 26 ; Pin D.6 / ADC 26
Symbol Sensor2 = 27 ; Pin D.7 / ADC 27

main:
readadc10 Sensor1, w1
readadc10 Sensor2, w2
goto main
You may also want to change your 'b1' variable to a word variable ( as in the above code ) when using a READADC10 which returns a 10-bit value which cannot be stored in an 8-bit byte variable.
 

rjandsam

Member
Hi Hippy,

Thank you for the fast response and solution, sorry I forgot to put a word variable in it is actually in my code I just typed up a quick example of my problem.

Although your solution works fine I did notice that anything up to d.3 does compile ok.

Thanks

Rich

#picaxe 40x2
Symbol Sensor2=d.3
Symbol Sensor1=d.2

main:
readadc10 Sensor1, w1
readadc10 Sensor2, w2
goto main
 

lbenson

Senior Member
This is because d.2 has a value of 26, which is a valid ADC channel (though it's associated with pin D.6), and d.3 has a value of 27, also valid, though associated with D.7. D.7 has a value of 30, which is not a valid ADC channel number. The following code run in the simulator will show you the numeric value of D.2, D.3, and D.6:

#picaxe 40x2
sertxd(#d.2," ",#d.3," ",#d.6)
 
Top