PDA

View Full Version : Incorrect adc channel bits generated



grahamg
- 6th February 2010, 18:17
I have been trying to get the following code to work using a pic18F24j11.
The code is compiled with PICbasicpro 2.50. I have stepped this code using mplab simulator and as one can see the incorrect analog channels are being generated. Is this a problem with the compiler?

' PICBASIC PRO program to READ 4 ANALOG VALUES
' 10-bit A/D conversion
' PIC=18F24J11
'
' Connect analog input to channel-0 (AN0) RA0
' Connect analog input to channel-1 (AN1) RA1
' Connect analog input to channel-2 (AN2) RA2
' Connect analog input to channel-3 (AN3) RA3
' Connect analog input to channel-4 (AN4) RA5
'
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

adval0 var word ' Create adval to store result
adval1 var word
adval2 var word
adval3 var word
adval4 var word


START:
ANCON0=%11100000 'analog 0 to 4
ANCON1=%11111111 'DIGITAL
ADCON0=%00000001
ADCON1=%10000010 ' Set right justify result
TRISA=%00011111

'adcon0 CHS VALUES
mainloop: ADCIN 0, adval0 ' OXC1 = 0000 CHAN0
ADCIN 1, adval1 ' 0XC9 = 0010 CHAN2
ADCIN 2, adval2 ' 0XD1 = 0100 CHAN4
ADCIN 3, adval3 ' 0XD9 = 0110 CHAN6
ADCIN 4, adval4 ' 0XE1 = 1000 CHAN8
GOTO MAINLOOP

Graham

Darrel Taylor
- 6th February 2010, 18:31
See the first issue on this page.

http://melabs.com/support/pbpissues.htm
<br>

grahamg
- 6th February 2010, 18:56
Thanks for the quick reply Darrel. Will use workaround.