ADC DNE on 20X2

chopperwalker

New Member
I added and LM34DZ for temperature to ADC9 (C.1) on my 20X2. I tried it on ADC1 (B.0) first and got an error which I didn't resolve and resulted in the move. I have since added another LM34DZ sensor and only have one ADC left (ADC1 - B.0). Ofcourse the error is back

readadc10 Therm2,CurTemp
^

Error: ADC channel 0 does not exist!
The carrot above is actually off the right of CurTemp (paste issue)

My relevant code up thru the error:

Symbol Therm2 = B.0 'Thermometer input
...
let adcsetup = %0000001000000010 'set ADC9 and ADC1
...
readadc10 Therm2,CurTemp
Oddly the error says ADC channel 0 DNE, but im trying to use ADC1. I also noticed that the manual doesn't show a ADC0 for the 20X2. I assume this might be related. Has anyone seen this before? Couldn't find anything in the threads about it.
 

ol boy

Member
Have you assigned your input and output ports and then assign your ADC channels? Without assigning I/O ports then the ADC the manual states the ADC won't work well.

manual #2 pg.25 ADCsetup
 

hippy

Ex-Staff (retired)
This is an issue with ADC pin referencing on the X2 parts where it differs from non-X2 parts. When using READADC/10 for X2's, what used to be the pin number becomes the ADC channel number, so, to read pin B.0, ADC 1, use "READADC 1", so in this case ...

Symbol Therm2 = 1 ' ADC 1, pin B.0 - Thermometer input

ReadAdc10 Therm2,CurTemp
 
Last edited:

hippy

Ex-Staff (retired)
I just knew you were going to ask that :)

That one comes down to just good fortune. In reality, all the names of pins "B.0", "C.1" etc represent pin numbers; you can see those by SERTXD("B.0=",#B.0,CR,LF) etc. So pin numbers on X2 can be 0 to 31, but not in any guaranteed grouping which is why we don't recommend pin number use.

For the 20X2, B.0 to B.7 = 0 to 7, C.0 to C.7 = 8 to 15 - The good fortune here is that C.1 ( value 9 ) just happens to be the right number and the same pin as ADC 9. In most cases you wouldn't be so lucky, the code would likely compile but you'd be reading a different ADC channel than expected. That's what happened earlier; B.0 ( value 0 ) indicates ADC 0 and in this case the compiler knows that ADC 0 doesn't exist so errored out with its reference to ADC 0.

There's no easy way to automatically map name.number to ADC channel numbers so that either can be used in source code as ADC channels are 'randomly' distributed across the ports and pins. It may be possible to give an error if name.number used ( similar to errors give with "HIGH pin0" ) and I'll make a note of looking into that.
 
Last edited:
Top