Doglao
Newbie level 2
adc pic 16f877
Hi!
I have problems with my project, I try to read four analog inputs of a pic16f877 with this code in ccs:
The value oscillate frequently, if i set the input to read 5ma the value is 2.7 , 2.9, 3.2, 3.1, 3.3 the value that I want is 3.1 in this condiction. I using a AD620 to convert ma to volt and this work well with other circuit with a separated AD converter.
but with pic16f877 don't work.
please anybody can helpme!!!!!
Hi!
I have problems with my project, I try to read four analog inputs of a pic16f877 with this code in ccs:
Code:
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
Code:
while(intTela == 1){
if(L == 1)
canal_ad(1);
if(L == 2)
canal_ad(2);
if(L == 3)
canal_ad(4);
if(L == 4)
canal_ad(5);
//disable_interrupts(GLOBAL);
delay_ms(20);
ad_value = (float)read_adc();//*5.0/1023;
ad_value = (ad_value * 5.0)/1023.00;
switch (L){
case 1:
adVconcreto += ad_value;
cont_concreto++;
if(cont_concreto >= 20){
adVconcreto =adVconcreto/cont_concreto;
CONCRETO = adVconcreto * 10;
cont_concreto = 0;
adVconcreto = 0;
}
break;
case 2:
adVtorque += ad_value;
cont_torque++;
if(cont_torque >= 20){
adVtorque = adVtorque/cont_torque;
TORQUE = adVtorque * 80;
cont_torque = 0;
adVtorque = 0;
}
break;
default:
if(ad_value <= 2.5){
ad_value = ad_value - 2.5;
ad_value = (ad_value * 12);
}
else{
ad_value = ad_value - 2.5;
ad_value = (ad_value * 12);
}
break;
}
if(L > 2){
lcd_gotoxy(10,L);
printf(lcd_putc,"%2.1f ",ad_value);
}
else{
lcd_gotoxy(10,L);
if(L == 1)
printf(lcd_putc,"%2.1f ",CONCRETO);
else
printf(lcd_putc,"%2.1f ",TORQUE);
lcd_gotoxy(18,L);
lcd_putc("Bar");
}
L++;
if(L>4)
L=1;
if(!input(bt1)){
intTela++;
while(!input(bt1))
{
delay_ms(40);
}
}
}
}
The value oscillate frequently, if i set the input to read 5ma the value is 2.7 , 2.9, 3.2, 3.1, 3.3 the value that I want is 3.1 in this condiction. I using a AD620 to convert ma to volt and this work well with other circuit with a separated AD converter.
but with pic16f877 don't work.
please anybody can helpme!!!!!