# ADC on PIC24FJ64GB004 not working

I'm using the MPLAB X IDE v3.50 to type the code and download it in the PIC24FJ64GB004. It is successfully compiling but the ADC is not giving an appropriate value according to the Voltage(Vin1) received on the RC0 pin. Whether the pin gets 3.3V or 0V, the converted value is a constant 0.

#define ADC_CHANNEL_CH_1            ADC_CHANNEL_6 // Pin RC0

Static FILEIO_OBJECT myFile;
uint16 Ch1_Value = 0;
uint16 Ch1_SUM = 0;

{

Ch1_SUM  = Ch1_Value;
Ch1_Value = 0;

if (Ch1_SUM  < 20)
{
Ch1_SUM   = 20; //Minimum value of 20
}
Else
{
Ch1_SUM  = Ch1_SUM;
}


I'm exporting the ADC converted value using the USB port to an Excel sheet in the Thumbdrive.

When I changed the ADC input pin(Vin1) from RC0 to RC1 (AN7), it gave a correct value till 341(Vin1 = 2.2V). But when I continue to use the RC1 pin with a new second input(Vin2) and then I give the original input(Vin1) to RC0, RC1 behaves the same(gives correct converted value till 341) but RC0 now gives a constant value of 341, '01 0101 0101' in binary, whether Vin1 = 0v/3.3V.

#define ADC_CHANNEL_CH_2            ADC_CHANNEL_7 // Pin RC1

Static FILEIO_OBJECT myFile;

uint16 Ch1_Value = 0;
uint16 Ch2_Value = 0;
uint16 Ch1_SUM = 0;
uint16 Ch2_SUM = 0;

{

Ch1_SUM  = Ch1_Value;
Ch1_Value = 0;

if (Ch1_SUM  < 20)
{
Ch1_SUM   = 20; //Minimum value of 20
}
Else
{
Ch1_SUM  = Ch1_SUM ;
}

Ch2_SUM  = Ch2_Value;
Ch2_Value = 0;

if (Ch2_SUM  < 20)
{
Ch2_SUM   = 20; //Minimum value of 20
}
Else
{
Ch2_SUM  = Ch2_SUM ;
}


Where am I going wrong? Why am I getting a digital value of 0 when I'm using only RC0 and I get a constant value of 341, when I use RC1 and RC0, at the output of RC0? The ADC in the PIC24FJ64GB004 is 10-bit so it should give a digital value from 0 to 1023. Why doesn't it go above 341?

I'm not collecting the converted values from RC0 and RC1 simultaneously. I'm using RC3 pin to toggle between the outputs. So when RC3=1, RC0's converted value is exported and when RC3=0, digital converted value of RC1 is exported to ecxel sheet.

So basically,

1] Vin1 -> RC0, output = 0 (constant) [RC1 is not used]

2] Vin1 -> RC1, output = 0,122,250 .. 341 (It gives a correct value till Vin1 = 2.2V. Above 2.2V, it gives a constant digital value 341. RC0 is not used)

3] Vin1 -> RC0 and Vin2 -> RC1, output at RC0 = constant 341; output at RC1 = 0.. 341. (constant 341 when Vin2 > 2.2V)

4] Vin2 -> RC0, output = 0 (constant) [RC1 is not used]

I'm not sure what compiler you're using, but it seems that you're not calling the function that actually triggers the ADC conversion or setting up the ADC before you use it. Usually the process to use the ADC is: