I am trying to read the voltage at a specific AN pin through the ADC however I am not sure if my ADC is set up correctly.
I tried
void ADC_Initialize() { ADCON0 = 0b10010100; // ADC on, Clock set in ADCLK, right justified. ADCLK = 0b00000011; // Clock is Fosc/8. ADCON1 = 0b00000000; // Fancy sh*t off. ADCON2 = 0b00000000; ADCON3 = 0b00000000; //ADC Error Calculation Mode First derivative of single measurement(bit 6 to 4). ADREF = 0b00000010; //Internal reference voltage is selected } int ADC_Read(int8_t AnChannel) { ADPCH &= 0b00000000; // Clearing the Channel Selection Bits ADPCH |= AnChannel; // Setting the required Bits __delay_ms(1); // Acquisition time to charge hold capacitor ADCON0bits.ADGO = 1; while(ADCON0bits.ADGO); return ((ADRESH<<8)+ADRESL); // Returns Result }
Now if I do ADC_Read(1), I get 1023.0 as a result however, at pin 1, I have 2.4V,
Is there something off with the configuration for the ADC?
P.S. I am using HFINTOSC with OSCFRQ= 32 MHz and CDIV = 1:1