TRISAbits.TRISA4 = 1; //RA4 = input
T0CON = 0x00; /* Shut off timer 0, since it could use T0CKI */
the ADC capture code:
ADCON0bits.ADON = 0; // Turn off ADC
ADCON1 = 0b00000100; // Vref=Vdd, AN2 enabled
ADCON2 = 0b10111001; // Right-justify, 20 TAD, TOSC=FOSC/8
ADCON0 = 0b00001000; // SEVTEN=0, CH = 2, still off
ADCON0bits.ADON = 1; // Turn ADC on
ADCON0bits.GO = 1;
while(ADCON0bits.NOT_DONE); //wait for result
adc = ReadADC(); //get ADC result
* ReadADC() is just the normal library function. At first I was strictly using library code to save time, but I've decomposed everything trying to track this problem down. I have also directly verified that ADRESH and ADRESL are both coming up 0.
* I'm using the extended instruction set.
* I've also tried configuring to read AN0,AN1, and they come up zero as well.
Help! If anyone has ideas, I will try them immediately and post the results.
Thanks in advance!
Updates: Just to be sure this was a problem with my code, I tried another 18F1330, same behavior. I'm using version 3.02 of the C18 compiler, and I noticed that there were some small fixes for this PIC in newer versions. However, I verified that the ADC-related registers all point to the right places. I'm not sure what else to try.
<message edited by jrpowers on Tuesday, January 30, 2007 8:06 AM>
I have a PIC18F1330 running at 8MHz on the internal oscillator, and I'm trying to read analog values on the RA4/T0CKI/AN2/Vref+ pin. Vdd is 3.7 volts, and the pin is connected to 3.3 volts, yet the readings I get are consistently '0'!