| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| paivadaniel 
 
 
 Joined: 11 Mar 2011
 Posts: 3
 
 
 
			    
 
 | 
			
				| AD Converter 18f452 |  
				|  Posted: Fri Mar 11, 2011 10:24 am |   |  
				| 
 |  
				| Hello, I am working with the A / D converter of the PIC 18F452, I'm having trouble capturing a signal of 2.5 V measured by the A / D converter and printed on the screen. 
 In 18452.h is:
 device adc = 8
 
 In X.C file is:
 
  	  | Code: |  	  | void main ()
 {
 unsigned int x;
 
 setup_adc_ports (ALL_ANALOG);
 setup_adc (ADC_CLOCK_DIV_2);
 setup_psp (PSP_DISABLED);
 setup_spi (SPI_SS_DISABLED);
 setup_wdt (WDT_OFF);
 setup_timer_0 (RTCC_INTERNAL);
 setup_timer_1 (T1_DISABLED);
 setup_timer_2 (T2_DISABLED, 0.1);
 setup_timer_3 (T3_DISABLED | T3_DIV_BY_1);
 enable_interrupts (INT_RDA);
 enable_interrupts (GLOBAL);
 / / parameter not Setup_Oscillator selected from Intr Oscillator Config tab
 
 / / TODO: USER CODE!
 
 while (1) {
 set_adc_channel (7);
 delay_us (10);
 read_adc x = ();
 printf ("\ r% u \ n ", x);
 }
 
 
 }
 
 | 
 My voltage is from 0 to 5V (or FF) should be printing FF / 2 (V = 2.5), but printing is 255 instead of 127. Does anyone know why? I believe that is the problem ADFM.
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19966
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Mar 11, 2011 10:52 am |   |  
				| 
 |  
				| Several questions/comments: 1) Compiler version -always post this.
 2) What clock rate?. FOSC/2, for the ADC clock, is only legal for a maximum of 1.25MHz.....
 3) Are you using the RDA interrupt. Have you got a handler for this?. Code will not work properly without this, with the interrupt enabled.
 4) Change the SPI setup line, to setup_spi(FALSE). SPI_SS_DISABLED, _enables_ the SPI.....
 5) Er. Your read_adc line, is not right as posted. Syntax is:
 
 x=read_adc();
 
 This is probably the main problem.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| paivadaniel 
 
 
 Joined: 11 Mar 2011
 Posts: 3
 
 
 
			    
 
 | 
			
				| ops... answer |  
				|  Posted: Fri Mar 11, 2011 11:51 am |   |  
				| 
 |  
				| The code is this, had copied wrong 
  	  | Code: |  	  | while (1) {
 set_adc_channel (7);
 delay_us (10);
 read_adc x = ();
 printf ("\ r% u \ n ", x);
 }
 | 
 
 I use the ccs, PCWHD, new version, the rda is already generated by it.
 
 pq psi should change?
 
 
 man, I think the answer is not ae, I believe that is the bit ADFM.
 |  | 
	
		|  | 
	
		| paivadaniel 
 
 
 Joined: 11 Mar 2011
 Posts: 3
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Mar 11, 2011 12:35 pm |   |  
				| 
 |  
				| why psi should change? |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 |  | 
	
		|  | 
	
		|  |