| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| pvol 
 
 
 Joined: 10 Oct 2008
 Posts: 46
 Location: GREECE
 
 
			    
 
 | 
			
				| strange problem on 18f4620 |  
				|  Posted: Tue Dec 30, 2008 3:23 pm |   |  
				| 
 |  
				| this program runs ok on 877 but not on 18f4620 
 
  	  | Code: |  	  | #include <18f4620.h> #fuses HS,NOWDT,PUT,NOBROWNOUT,NOLVP
 #device ADC=10
 #use delay (clock=10000000)
 #byte portb=6
 #byte porta=5
 #byte portc=7
 #use RS232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
 
 
 int c=0;
 int16 value=0;
 int flag=0;
 #int_rtcc
 void rtcc_isr(){
 
 set_RTCC(125);
 output_low(pin_b7);
 set_adc_channel(0);
 
 value = read_ADC();
 output_high(pin_b7);
 printf ("A %ld\n",value);
 
 
 
 }
 
 void main(){
 
 set_tris_a(0x1f);
 set_tris_b(0x00);
 set_tris_c(0x00);
 setup_adc_ports( all_analog);
 setup_adc(ADC_CLOCK_DIV_32);
 setup_counters(RTCC_internal,RTCC_div_16);
 set_RTCC(125);
 enable_interrupts(INT_RTCC);
 enable_interrupts(global);
 PORTA=0x00;
 PORTB=0x00;
 PORTC=0x00;
 
 while(1)   {
 
 }
 }
 
 | 
 I tested on a oscilloscope
 and result is :
 on 16f877 I have one conversion every 0.8ms almost
 (periodic)
 
 But on 18f4620 I cannot measure when goes to interrupt!!
 The oscilloscope confuses!!!
 Very strange things!!
 I can't explain more.
 
 What can I do for this?
 maybe some changes at code?
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 3:37 pm |   |  
				| 
 |  
				| Start with the fact that you are using hardware port addresses. These are different on 18 family chips. You need to adjust these. Acessing addresses at the bottom of memory on the 18, will overwrite the system storage area used for the interrupt temporary store...
 
 Best Wishes
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 3:42 pm |   |  
				| 
 |  
				| Download the 18F4620 data sheet: http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
 Look in this section to find the correct addresses for the PortA, B, and C
 registers for your PIC.
 
  	  | Quote: |  	  | 5.3.4 SPECIAL FUNCTION REGISTERS | 
 
 A better way is to use the CCS functions to set the port addresses,
 such as output_a(), output_b(), and output_c().   Let the compiler handle
 setting the TRIS for you.   Don't try to set it yourself.    If you use those
 CCS functions, problems like this will not happen.
 |  | 
	
		|  | 
	
		| pvol 
 
 
 Joined: 10 Oct 2008
 Posts: 46
 Location: GREECE
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 3:46 pm |   |  
				| 
 |  
				| thanks for reply !!! 
 
 can you be more clearly? (my english are not so good to understand u
  ) what must  i look?
 is there a problem on code?
 ....................................................
 
 to be honest i did not check this!!
 thanks a lot both or you!!!
 |  | 
	
		|  | 
	
		| treitmey 
 
 
 Joined: 23 Jan 2004
 Posts: 1094
 Location: Appleton,WI   USA
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 3:54 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | #byte portb=6 #byte porta=5
 #byte portc=7
 this is for the 16F877a
 
 | 
 
 
  	  | Quote: |  	  | should be  for the 18F4620
 #byte porta=0xF80
 #byte portb=0xF81
 #byte portc=0xF82
 #byte portd=0xF83
 #byte porte=0xF84
 
 | 
 page 62 of spec
 http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
 
 Last edited by treitmey on Tue Dec 30, 2008 3:56 pm; edited 1 time in total
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 3:55 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | #include <18f4620.h> #fuses HS,NOWDT,PUT,NOBROWNOUT,NOLVP
 #device ADC=10
 #use delay (clock=10000000)
 #byte portb=6
 #byte porta=5
 #byte portc=7
 #use RS232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
 | 
 The lines shown in bold must be changed.  The addresses of 5, 6, 7
 are not correct for the 18F4620.
 
 Download the 18F4620 data sheet:
 http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
 Look in this section to find the correct addresses for the PortA, B, and C
 registers for the 18F4620:
 
  	  | Quote: |  	  | 5.3.4 SPECIAL FUNCTION REGISTERS | 
 |  | 
	
		|  | 
	
		| pvol 
 
 
 Joined: 10 Oct 2008
 Posts: 46
 Location: GREECE
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 4:09 pm |   |  
				| 
 |  
				| i very thank you!! 
 i change them as you say
 but the problem continues
 look..
 i have the probe at PINB7
 and the scale on osciloscope at 1ms and sometime 0.5ms
 and the only thing i see is logic "1'
 !!!!!!!!!!!!!!! no change at this pin!!!
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Dec 30, 2008 4:55 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | I have the probe at PINB7 and the only thing i see is logic "1' | 
 
 The pin is only low for about 2 or 3 micro-seconds.   The functions shown
 in bold execute in 2-3 us.    Then pin B7 is set high, and it stays high
 during the printf(), which takes several milli-seconds.    Pin B7 will appear
 to always be high on the oscilloscope.
 
  	  | Quote: |  	  | #int_rtcc void rtcc_isr(){
 
 set_RTCC(125);
 output_low(pin_b7);
 set_adc_channel(0);
 
 value = read_ADC();
 output_high(pin_b7);
 printf ("A %ld\n",value);
 }
 | 
 
 My advice is to start with a more simple program.
 |  | 
	
		|  | 
	
		| pvol 
 
 
 Joined: 10 Oct 2008
 Posts: 46
 Location: GREECE
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Dec 31, 2008 1:45 am |   |  
				| 
 |  
				| i change my program and put output_high(PIN_B7) after printf
 so, i see that pulses wasn't steady
 i mean ,on 877  shows like a "train" pulse!!
 on 4620 i have one pulse even .... i don't know !!!
 i can't "catch" this wave .. i try to see in all scales on time division
 on hyperterminal seems too work but very-very-very slow
 even on 115200!!!!
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 |  | 
	
		|  | 
	
		| pvol 
 
 
 Joined: 10 Oct 2008
 Posts: 46
 Location: GREECE
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Dec 31, 2008 3:16 am |   |  
				| 
 |  
				| well, after a few changes i conclude that the program don't like RTCC very much
 
 i write interrupt alone and the ADC at while (1)
 and runs just fine!!!
 
 #int_rtcc
 void rtcc_isr(){
 set_RTCC(125);
 }
 void main()   {
 setup_adc_ports( all_analog);
 setup_adc(ADC_CLOCK_DIV_64);
 setup_counters(RTCC_internal,RTCC_div_64);
 set_RTCC(125);
 enable_interrupts(INT_RTCC);
 enable_interrupts(global);
 while(1)   {
 output_high(pin_b7);
 set_adc_channel(0);
 value = read_ADC();
 output_low(pin_b7);
 printf ("A %ld\n",value);
 }
 }
 
 now, i can see clearly PINB7 goes up and down!
 i want to ask a few questions more..
 how can i achieve the fastest A/D conversion on this PIC???
 notice that i change fuses ..i put H4 with 10MHz crystal
 and the delay clock becomes 40MHz
 what else must i change >?
 maybe this?setup_adc(ADC_CLOCK_DIV_64)?
 data sheet can't tell me clearly.
 thanks a lot
 and i wish you to have a very happy and healthy 2009!
 |  | 
	
		|  | 
	
		|  |