PIC16F1789 adc reading accuracy problem

Thread Starter

bhavitrajput

Joined Mar 5, 2018
2
i am using PIC16F1789 (internal osc 32MHz) controller to measure voltage using using 12bit ADC.
i generated circuit to measure 1860 mV but PIC do not giving accurate adc count value.
it is giving me adc count 1800 =1800mv because using 4.096V as reference voltage.
how can i get accurate adc count 1860 for 1860mv ?

Following code of adc initialization.
C:
void adc_init(){
        FVRCON=0x83;//Fixed Reference voltage 4.046
        ADCON1=0xE3;//Selection of fixed ref 4.096V as positive ref
        ADCON2=0x0F;//Select negative reference same as ADC Negative reference selected by ADNREF(Vss)
}


Following code of reading.
void adder_read(){
    do{
    ADCON0&=~0x03;
    ADCON0=0x0C;
    ADCON0|=0x01;
    __delay_us(50);
    ADCON0|=0x02;

        while((ADCON0&0x02)==0x02);     
           adder_average=0;
           adder_average=(ADRESH<<8)|ADRESL; 
         
           adc_adder_temp+=adder_average;
           r++;
    }
    while(r<500);       
      r=0;
      adc_adder=adc_adder_temp/500; 
      adc_adder_temp=0;
}
Moderators note : used code tags
 
Last edited by a moderator:

Picbuster

Joined Dec 2, 2013
1,057
Where did you measure the 1860 mV.? ( ground plane current causing an error?)
What DVM did you use to measure and how and when is it calibrated?

Picbuster
 

Ian Rogers

Joined Dec 12, 2012
1,136
This probably not a fault but ADRESH is a byte so to be sure you need to cast to an int..

adder_average = ((int)ADRESH)<<<8 | ADRESL;
 

MrChips

Joined Oct 2, 2009
34,630
1800 instead of 1860 is not bad. That is an error of 3%.
Take some readings covering the full range from 0V to 4V and maybe we can give you some recommendations.
 
Top