Try adding
ADCON2.7 = 1
ADCON1 = %00001100
TRISA = %00000111
Try adding
ADCON2.7 = 1
ADCON1 = %00001100
TRISA = %00000111
Dave
Always wear safety glasses while programming.
after adding that none of the adc works. let me post the actual code im using not the base code, i will include the code you posted
Code:DEFINE ADC_BITS 10 ' A/D number of bits DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us ADCON2.7 = 1 ADCON1 = %00001100 TRISA = %00000111 TRISD = %00000000 ' PORTD is output LCDOUT $FE, 1 ' Clear LCD PAUSE 500 ' Wait 0.5sec for LCD to initialize SETT Var Word ' A/D converter result in 10bit READT var word AGAIN: ADCIN 0, READT ' Read Channel 0 data ADCIN 1, SETT ' Read Channel 0 data ReadT = ReadT / 13 'this may change depending on thermostat SETT = SETT / 1024 'Output = 0 - 63 readT = (((readT / 10) * 9) / 5) + 33 'Convert ANA0 to Farent. setT = sett + 40 ' Temp Range will be 40 - 103 LCDOUT $FE, 2 LCDOUT $FE, $80 LCDOUT "Set Temp = ", DEC setT , $DF , "F " LCDOUT $FE, $C0 LCDOUT "Temp = ", DEC READT , $DF , "F " pause 100 GOTO AGAIN ' Repeat
Not sure what is going on with your setup, I do not see the problem.
I dug out a board with an 18F2550 and ran the below code to make sure it works. I only have the ADC on channels 1 and 2 as I have a LED soldered on channel 2. Other than that it should all be the same.
Code:'<FL_PIC18F2550>' '<FL_PBPL>' DEFINE OSC 48 #CONFIG __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H __CONFIG _CONFIG2L, _PWRT_ON_2L & _VREGEN_ON_2L __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L #ENDCONFIG CNT VAR BYTE ADCON2.7 = 1 ADCON1 = %00001101 TRISA = %00000011 DEFINE ADC_BITS 10 DEFINE ADC_SAMPLEUS 50 ADC_0 VAR WORD ADC_1 VAR WORD START: CNT = CNT + 1 Serout2 PORTC.6, 16572, ["TEST ",DEC3 CNT, $d, $a] Serout2 PORTC.6, 16572, ["ADC_0 ",DEC4 ADC_0, $d, $a] Serout2 PORTC.6, 16572, ["ADC_1 ",DEC4 ADC_1, $d, $a] TOGGLE PORTA.2 PAUSE 1000 GOSUB GET_ADC GOTO START GET_ADC: ADCIN 0, ADC_0 ADCIN 1, ADC_1 RETURN
Dave
Always wear safety glasses while programming.
I got it to work by leaving off the adcon.7 code, heres what I am using for 2 ADC, it works great, if I change the adcon.7 it wont even compile
Code:DEFINE ADC_BITS 10 ' A/D number of bits DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us ADCON1 = %10000000 TRISA = %00000011 'PORTA 0&1 is input SETT Var Word ' A/D converter result in 10bit READT var word ' A/D converter result in 10bit AGAIN: ADCIN 0, READT ' Read Channel 0 data ADCIN 1, SETT ' Read Channel 1 data
ADCON.7 will not compile because it is a wrong command. You need to use ADCON2.7=1
Dave
Always wear safety glasses while programming.
Bookmarks