# PIC16F877 adc oscillation in 4 channels

Status
Not open for further replies.

#### Doglao

##### Newbie level 2

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)
if(L == 2)
if(L == 3)
if(L == 4)
//disable_interrupts(GLOBAL);
delay_ms(20);

switch (L){
case  1:
cont_concreto++;
if(cont_concreto >= 20){
cont_concreto = 0;
}
break;
case 2:
cont_torque++;
if(cont_torque >= 20){
cont_torque = 0;
}
break;
default:
}
else{
}
break;
}
if(L > 2){
lcd_gotoxy(10,L);
}
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.

#### Ave_Rapina

##### Full Member level 2
pic16f877

Hello,

How do you have your reference tensions defined in the microcontroller???

Any floating in the Vdd voltage of the micro???

Any problem with input impedance, remember that the micro is and and sample and hold and the serial impedance of your circuit can be very high.

Just some items to review to debug the problem.

Regards

#### Doglao

##### Newbie level 2

I have a internal reference now, and I make 1k samples of the A/D channel and stablish the value, thanks to repply.

#### yousafzai82

##### Member level 4
To Douglo

Can you please send me the corrected above coding with serial output....

Status
Not open for further replies.