mshrestha789
Junior Member level 1
- Joined
- Dec 29, 2010
- Messages
- 17
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 1,283
- Activity points
- 1,392
Hello friends,
Recently I've been working on dspic30f2010. I've written a code and displayed it in Terminal. But I am not getting the correct value. Even when I give 0v at the adc input pin, I get digital value around 10 instead of 0. Please help me regarding this.
I am posting initialization code of ADC. Here I have configure ADC for 1MSPS.
Any help regarding this will be highly appreciated.
Recently I've been working on dspic30f2010. I've written a code and displayed it in Terminal. But I am not getting the correct value. Even when I give 0v at the adc input pin, I get digital value around 10 instead of 0. Please help me regarding this.
I am posting initialization code of ADC. Here I have configure ADC for 1MSPS.
Code:
void ADC_Init(void){
unsigned char val=0;
ADCON1bits.FORM = 0x0;//signed fractional format
ADCON1bits.SSRC = 0x7;//enable auto convert option
ADCON1bits.ASAM = 0x1;//enable automatic sampling
ADCON1bits.SIMSAM = 0;//enabble sequential sampling
ADCON2bits.SMPI = 0x01;//Interrupts at the completion of conversion for each 2nd sample/convert sequence
ADCON2bits.CHPS = 0x01;//sample on 2 S/H channels - CH0 and CH1
ADCON3bits.SAMC = 0;//no Tad between start of sampling and start of conversion
val = (unsigned char)(ADCS_VAL + 0.5);//Here 0.5 is added to get the rounding number
ADCON3bits.ADCS = val;//configure A/D clock period
ADCHS = 0x0023;//Set up A/D Channel Select Register to convert AN3 on Mux A input of CH0 and CH1 S/H amplifiers
ADCSSL = 0x0000;//Channel Scanning is disabled. All bits left to their default state
ADPCFG = 0xFFFF;
TRISB |= (1<<3);//To set up AN3 as input
ADPCFGbits.PCFG3 = 0;//Set up channels AN3 as analog input and configure rest as digital
IFS0bits.ADIF = 0;//Clear the A/D interrupt flag bit
IEC0bits.ADIE = 1;//Set the A/D interrupt enable bit
ADCON1bits.ADON = 1;//Turn on the A/D converter
}
Any help regarding this will be highly appreciated.