| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| isv10 
 
 
 Joined: 29 Aug 2010
 Posts: 15
 
 
 
			    
 
 | 
			
				| problem with A/D 18f452 |  
				|  Posted: Sun Aug 29, 2010 2:09 pm |   |  
				| 
 |  
				| hello I use pic 16f877a in my project and I need 5 channel A/D in this. This project is worked really good. When I need to change and upgrade my program I forced with program memory to use 18f452. A/D in this pic is unstable but this program worked with 16f877a.
 Very stable. For example: when I read 86mv with 16f877a it read 86mv fixed, but 18f452 read (89-86-78-83..) and change read value each time reading and not fix.
 Part of this program:
 
  	  | Code: |  	  | #include <18F452.h>
 #fuses HS
 #device ADC=10
 #use delay(Clock=20000000)
 #define use_portd_lcd TRUE
 #include <lcd420.c>
 #include <math.h>
 
 void main(){
 float T_care,T_care1,T_care2,T_ch,P_ch,P_bo;
 
 lcd_init();
 output_c(0x00);
 setup_adc_ports(AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF );
 setup_adc(ADC_CLOCK_INTERNAL);
 
 while(true){
 set_adc_channel(0);
 delay_us(100);
 P_ch=READ_ADC();
 P_ch=(p_ch/17.9);
 delay_ms(5);
 
 set_adc_channel(1);
 delay_us(100);
 T_ch=read_ADC();
 T_ch=(T_ch*.97656)/1000;
 T_ch=((901*T_ch)/(5-T_ch));
 T_ch=ceil((T_ch-100)/0.385);
 delay_ms(5);
 
 set_adc_channel(2);
 delay_us(100);
 P_bo=READ_ADC();
 P_bo=(p_bo/17.9);
 
 if(P_bo>=3)
 output_bit(PIN_d3,0);
 else
 output_bit(PIN_d3,1);
 
 delay_ms(5);
 
 set_adc_channel(4);
 delay_us(100);
 T_care1=read_ADC();
 T_care1=(T_care1*.97656)/1000;
 T_care1=((901*T_care1)/(5-T_care1));
 T_care1=ceil((T_care1-100)/0.385);
 delay_ms(5);
 
 set_adc_channel(5);
 delay_us(100);
 T_care2=read_ADC();
 T_care2=(T_care2*.97656)/1000;
 T_care2=((901*T_care2)/(5-T_care2));
 T_care2=ceil((T_care2-100)/0.385);
 
 lcd_gotoxy(1,2);
 printf(lcd_putc,"T:1=%f",T_care1);
 
 lcd_gotoxy(8,2);
 printf(lcd_putc,"     ");
 
 lcd_gotoxy(10,2);
 printf(lcd_putc,"2=%f",T_care2);
 
 lcd_gotoxy(15,2);
 printf(lcd_putc,"   ");
 
 lcd_gotoxy(1,1);
 printf(lcd_putc,"T:ch=%f",T_ch);
 
 lcd_gotoxy(9,1);
 printf(lcd_putc,"    ");
 
 lcd_gotoxy(1,3);
 printf(lcd_putc,"P:bo=%f",P_bo);
 
 lcd_gotoxy(1,4);
 printf(lcd_putc,"P:ch=%f",P_ch);
 delay_ms(500);
 }
 }
 | 
 Please help me!
  |  |  
		|  |  
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun Aug 29, 2010 4:13 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | setup_adc(ADC_CLOCK_INTERNAL); 
 | 
 Read the A/D converter section of the 18F452 data sheet:
 http://ww1.microchip.com/downloads/en/devicedoc/39564c.pdf
 Look at this table in that section:
 
  	  | Quote: |  	  | TABLE 17- 1: TAD vs. DEVICE OPERATING FREQUENCIES 
 | 
 It shows that you're supposed to use a clock divisor of 32 when you
 have a 20 MHz oscillator.  So your setup statement should really be:
 
  	  | Code: |  	  | setup_adc(ADC_CLOCK_DIV_32); 
 | 
 This will probably fix most of your stability problems.
 |  |  
		|  |  
		| isv10 
 
 
 Joined: 29 Aug 2010
 Posts: 15
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Aug 31, 2010 12:15 am |   |  
				| 
 |  
				| hi When i fix it clock like as table 17-1(clock div 32), its really better, but not very good like as 16f877a. Thanks for your useful idea. I am really thanks.
 Are you can help me to complete solve this problem. I waiting to help more......
        |  |  
		|  |  
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Aug 31, 2010 3:18 pm |   |  
				| 
 |  
				| Describe the external circuit that is providing the analog voltage. Give the details, including component values.   The maximum impedence
 of the circuit driving the analog pins should be 2.5K ohms.   That value
 comes from the PIC data sheet.   If it's greater than 2.5K, you will get
 less accuracy.
 
 Also, you have the ADC configured to use external Voltage References,
 for both Vref+ and Vref-.  What circuits do you have connected to those
 pins ?   What are the voltages on those pins ?
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |