i'm using the 12 bit ADC in PIC24FV16KA301.
I power the PIC with 5V, and I set the ADC registers to work eith AN0 channel with 0-5V range input.
When I try to sample the AN0 channel with input 5V i get 1024, if 1V I get 200, and so (3V = 600).
It seems that is working as 10 bit ADC instead of 12 bit.
Even if one bit is for the sign (ADC on this PIC is very complex), there is one bit more for the positive range.
Here is the code:
Code: Select all
void main()
{
int count = 0;
unsigned int adc_value;
int i;
ANSA = 0;
ANSB = 0;
OC1CON1 = 0;
OC2CON1 = 0;
SPI1STAT = 0;
SPI2STAT = 0;
I2C1CON = 0;
I2C2CON = 0;
RCFGCAL = 0;
CTMUCON1 = 0;
TRISB.RELE = 0;
CM1CON = 0;
TRISA.ADC = 1;
TRISA.ADC_AMP = 1;
//AD1CON1 = 0X8074;
AD1CON1 = 0X8174;
//AD1CON2 = 0X1800;
AD1CON2 = 0X800;
//AD1CON3 = 0X1F10;
AD1CON3 = 0X9F3F;
AD1CON5 = 0;
AD1CHS = 0;
UART1_Init(2400); // Initialize UART module at 9600 bps
Delay_ms(1000); // Wait for UART module to stabilize
while (1)
{
UART1_Write_Text("ADC: ");
adc_value = ADC1BUF0;
for (i=11;i>=0;i--)
{
if ((adc_value & (1 << i)) != 0)
UART1_Write_Text("1");
else
UART1_Write_Text("0");
}
//sprintf(txt, " = %d\r", adc_value);
UART1_Write_Text("\r");
Delay_ms(2000);
}
}