Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877 adc oscillation in 4 channels

Status
Not open for further replies.

Doglao

Newbie level 2
Joined
May 25, 2007
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,294
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:

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!!!!!
 

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
 

pic16f877 adc

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

To Douglo

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

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top