Strange ADC behaviour on 20X2

pmulvey

New Member
This is my program:

#Picaxe 20X2
#Terminal 9600
#No_Table
#No_Data

symbol PotA = b.1 ;ADC2
symbol PotB = b.2 ;ADC4

symbol ValueA = b25
symbol ValueB = b24
symbol ValueC = b23

let adcsetup = %000000000010100

Test2:
readadc PotA, ValueA
readadc B.1, ValueB
readadc PotB, ValueC
pause 100
SerTxd(" PotA=",#ValueA," B.1=",#ValueB," PotB=",#ValueC, CR, LF )
goto Test2

I am getting a different value when I use the symbol PotA instead of B.1. Also, instead of reading B.2 (PotB) I seem to be picking up the B.1 value!!
Screen shot of terminal attached.
ADCProb.png
 

pmulvey

New Member
Thanks Hippy. It just seems so strange that this anamoly in how the compiler treats symbols in the readadc is left unresolved. There is probably a real good reason for it !?!
 

SAborn

Senior Member
There is probably a real good reason for it !?!
Im just wondering what that good reason is?

Perhaps a bug fix for PE 6.0 if we ever get to live long enough to see PE 6.0, as its a looooooooooooooooong time coming.
 

Technical

Technical Support
Staff member
There is no bug or anomaly to fix.

The X2 parts, by design, use ADC channel numbers which are not the same as the pin number. This is just the way Microchip designed the silicon.
Hence you should ideally always use the channel number regardless.
http://www.picaxe.com/BASIC-Commands/Analogue-InputOutput/readadc/

Code:
symbol PotA = 2        ;ADC2
readadc 2, ValueB
readadc PotA, ValueB
If you use a symbol such as 'PotA = B.2' all the compiler sees when the 'readadc PotA' command is processed is the value of the B.2 constant, which in this case is 2. This is legal from the compiler's point of view, but actually points to ADC channel 2, not the ADC channel on pin B.2!

The reason this doesn't matter so much on M2 parts is that the channel numbers are exactly the same as the pin number constants, so by using the pin number you are already using the channel number and vice versa.
 
Last edited:
Top