PIC24F: problem in AD1PCFG register

adcanalogpicregister

Im working ADC in PIC24FJ64GA002 microcontroller using proteus simulation. I've a doubt regards AD port configuration register. I've connected a potentiometer in AN12 pin and channel was selected. The problem is even i comment the below analog/digital mode selection config bit code, its working. I can able to get ADC value.

AD1PCFGbits.PCFG12 = 0;

Is not necessary to mention the analog or digital mode for the corresponding pins?

Code:

 void InitADC(void)
{
// *******************************
// 1. Configure the A/D module
// *******************************
// a) Select port pins as analog inputs(AD1PCFG<15:0>)
AD1PCFGbits.PCFG0  = 1; //PCFG(12-0) 1:Digital mode, 0:Analog mode
AD1PCFGbits.PCFG1  = 1; 
AD1PCFGbits.PCFG2  = 1; 
AD1PCFGbits.PCFG3  = 1; 
AD1PCFGbits.PCFG4  = 1;
AD1PCFGbits.PCFG5  = 1; 
AD1PCFGbits.PCFG9  = 1;
AD1PCFGbits.PCFG10 = 1; 
AD1PCFGbits.PCFG11 = 1; 
AD1PCFGbits.PCFG12 = 1; <== **here i set 1**.
AD1PCFGbits.PCFG15 = 1;

enter image description here

Thanks.

Best Answer

In most PIC micros, analog mode for a pin is turned on at power-on, i.e., you don't need to do anything to use a pin as analog input (given it is capable of it). Set PCFG to 1 and ADC will stop reading your pot.