I'm new to PIC programming, and I'm lost on how to set the ADCON registers for my PIC. I am using PIC18F4685 and it have ADCON0, 1 and 2. I have set my ADCON base on the PIC datasheet.
ADCON0 = 0b00000001; // Set RA0 as analog input
ADCON1 = 0b00000000; // Bit5 as AVss Bit4 as AVdd
ADCON2 = 0b10101101; /* Bit7 as Right Justified
Bits5-3 I don't know how to select the TAD
Bits2-0 Fosc/8, I am using __XTAL_FREQ 8000000 */
At ADCON0, I have turned on the ADC and select channel0 (RA0). But what if I want to select other channels since my PIC have 8 analog channels.
At ADCON1, reference voltage is the supplied voltage (bits 5 and 4). And the port conf bits are all analog input (bits 3 to 0). Bits 7 and 6 are unimplemented.
At ADCON2, this part is where I am confused. Bit 7 is right justified and Bit 6 is unimplemented.
Bits 5 to 3 is set to 101 or 12TAD, I have search to google and the minimum TAD for a 10bit ADC is 12TAD. How to know what TAD to choose? At the datasheet, A/D clock period minimum is at 0.7us and maximum is at 25us.
Bits 2 to 0 is set to 101 or FOSC/16. Can I choose anything? I am using a crystal oscillator at 8MHz.
Please do correct me if I'm wrong. I am still new to this and need some guidance.