What are the correct pin numbers?

hbl2013

Senior Member
I get confused all the time in using old and new pin designations of chips. In this case, I want to use the A.0 analog input on the 28X2 (Pin 2) with an Sharp analog IR sensor and entered the following code


symbol dist = w0

'------------------------------------------------
'Activate - ADC0 = Pin 2

let adcsetup = %0001 'ADC 01

main:

ReadAdc10 A.0, dist


I get the following error Error: Valid ADC channels are 1-11 only!

Which pins is the compiler talking about? And where can I find a "translation" of these Pin designations?
And finally, is my code above written correctly?
 

hippy

Technical Support
Staff member
Which software and version are you using ? Your "ReadAdc10 A.0, dist" code compiles without any errors for me using PE6 6.0.8.11
 

rossko57

Senior Member
Note that ReadAdc10 requires a "channel" number, not a pin number - see
http://www.picaxe.com/BASIC-Commands/Analogue-InputOutput/readadc10/
Referring to manual page 11
http://www.picaxe.com/docs/picaxe_manual1.pdf
shows that on a 28X2 leg 2 , aka digital pin A.0, is also ADC channel 0 (zero)

Your adcsetup is correct, but actually enabling ADC0
Your readasdc10 should point at channel 0, not a pin number

Note that internally PE converts pin numbers to ordinary numbers, so specifying a pin number instead of a cchannel with a readadc can look okay, but it might not always work the way you expect
 

hippy

Technical Support
Staff member
Note that internally PE converts pin numbers to ordinary numbers, so specifying a pin number instead of a channel with a readadc can look okay, but it might not always work the way you expect
That should work as expected. Except on an X2 device when the pin number is specified as a name through a SYMBOL definition. In this case there should not be an error, is not when I test it.
 

hbl2013

Senior Member
(Partial)
http://www.picaxe.com/docs/picaxe_manual1.pdf
shows that on a 28X2 leg 2 , aka digital pin A.0, is also ADC channel 0 (zero)

Your adcsetup is correct, but actually enabling ADC0
Your readasdc10 should point at channel 0, not a pin number
Then I understand it correctly. That is what I wanted, except that my comment line in the statement let adcsetup = %0001 'ADC 01 should have read " 'ADC 00 ",
and the statement ReadAdc10 A.0, dist should be ReadAdc10 0, dist to use the analog pin2 as intended, correct?

BTW @hippy - I used the older Editor 5
 

hippy

Technical Support
Staff member
BTW @hippy - I used the older Editor 5
Your code as is compiles okay for me using PE6 and PE5. What version on PE5 do you have ?

You should be able to use "ReadAdc10 A.0, dist" or "ReadAdc10 0, dist". With the error you are getting it seems unlikely the second would resolve the issue as that should also generate a "Valid ADC channels are 1-11 only" error.

My guess would be you are using an out of date version of PE5 or you do not have a 28X2 chip selected.

Do you get the error on a Syntax Check or only when downloading ? If only on download; what is the firmware version of your 28X2 ?
 

Technical

Technical Support
Staff member
The error message shown is a 20X2 error msg, so we suspect 20X2, not 28X2 , has been accidentally selected as the target PICAXE type.
 
Top