noel_t
Junior Member level 3
Please help me to identify the reason for unstable reading.
This is a multi-channel data acquisition system for solar panel. Three parameters can be read accurately without any issue. but for current sensing, even though i tried to use the precise current sensing amplifier which is advised for precise applications, but still have problem in reading. My knowledge is poor in understanding of Vref, Resolution, and generally ADC.
ADCON0=CHANNEL3; //CHANNEL1=0b10001001 //CHANNEL0 is for Temperature
lcd_goto(48);
read_adc(); ////It seems Reading the adc first ***important ////This function generates the average reading value of ADC
current=read_temp(); // reading value from sensor ***important ////This function stores the generated value by ADC into the variable "temp"
//current=0.074*current; // Last time used for ACS712 Hall Effect sensor and it worked
//current=(current-34);
current=(current/0.001*1000); //This is the part i am confused about and can't fix a coefficient to get the right value
current=(current*20);
dis_num(current); //show the value
send_char('.'); //this line is to show . to seprate desimal value from double value
dis_num(current%10); //show the double value
//current=temp;
send_char(' ');
send_char('A');
send_char(' ');
//==================subroutine ADC=========================
void read_adc(void) ////This function generates the average reading value of ADC
{
unsigned short i;
unsigned long result_temp=0;
for(i=2000;i>0;i-=1) //looping 2000 times for getting average value
{
ADGO = 1; //ADGO is the bit 2 of the ADCON0 register
while(ADGO==1); //ADC start, ADGO=0 after finish ADC progress
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC
result_temp+=result;
}
result = result_temp/2000; //getting average value
}
unsigned short read_temp(void) ////This function stores the generated value by ADC into the variable "temp"
{
unsigned short temp;
temp=result;
return temp;
}
This is a multi-channel data acquisition system for solar panel. Three parameters can be read accurately without any issue. but for current sensing, even though i tried to use the precise current sensing amplifier which is advised for precise applications, but still have problem in reading. My knowledge is poor in understanding of Vref, Resolution, and generally ADC.
ADCON0=CHANNEL3; //CHANNEL1=0b10001001 //CHANNEL0 is for Temperature
lcd_goto(48);
read_adc(); ////It seems Reading the adc first ***important ////This function generates the average reading value of ADC
current=read_temp(); // reading value from sensor ***important ////This function stores the generated value by ADC into the variable "temp"
//current=0.074*current; // Last time used for ACS712 Hall Effect sensor and it worked
//current=(current-34);
current=(current/0.001*1000); //This is the part i am confused about and can't fix a coefficient to get the right value
current=(current*20);
dis_num(current); //show the value
send_char('.'); //this line is to show . to seprate desimal value from double value
dis_num(current%10); //show the double value
//current=temp;
send_char(' ');
send_char('A');
send_char(' ');
//==================subroutine ADC=========================
void read_adc(void) ////This function generates the average reading value of ADC
{
unsigned short i;
unsigned long result_temp=0;
for(i=2000;i>0;i-=1) //looping 2000 times for getting average value
{
ADGO = 1; //ADGO is the bit 2 of the ADCON0 register
while(ADGO==1); //ADC start, ADGO=0 after finish ADC progress
result=ADRESH;
result=result<<8; //shift to left for 8 bit
result=result|ADRESL; //10 bit result from ADC
result_temp+=result;
}
result = result_temp/2000; //getting average value
}
unsigned short read_temp(void) ////This function stores the generated value by ADC into the variable "temp"
{
unsigned short temp;
temp=result;
return temp;
}
Attachments
Last edited: