| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| acm45 
 
 
 Joined: 29 Dec 2008
 Posts: 18
 Location: Italy
 
 
			    
 
 | 
			
				| Pwm duty cycle strange behaviour! |  
				|  Posted: Fri Sep 09, 2011 1:34 pm |   |  
				| 
 |  
				| Hi there! 
 I'm doing a small motor control with the classic H bridge controlled by a 18F4550 pic (with 20MHz and HSPLL active).
 It works really well but, I noticed a strange behaviour, here's the code!
 
 
  	  | Code: |  	  | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_16_BIT); setup_timer_2(T2_DIV_BY_1,0xff,1);      //25.0 us overflow, 25.0 us interrupt per generare la portante PWM 46kHz
 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
 setup_ccp1(CCP_PWM);   // Configure CCP1 as a PWM
 setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H |CCP_SHUTDOWN_ON_INT0|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
 set_tris_d(0x1F);
 set_tris_d(0x02);
 set_pwm1_duty((int16)0x000F);
 | 
 
 The last instruction gives me a duty cycle of 0%!!!
 If I write values from 0x000C to 0x000F I obtain the same wrong duty cycle!!! Moreover if the last 4bits have a value between 0xC and 0xF, the duty cycle is always 0%!
 Writing 0x000A I obtain a duty cycle of 0.9% as expected!
 I see the pwm registers and seem all ok with the right value as described in the datasheet.
 Thank you in advance for your help!
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Sep 09, 2011 1:45 pm |   |  
				| 
 |  
				| What's your compiler version ? |  | 
	
		|  | 
	
		| acm45 
 
 
 Joined: 29 Dec 2008
 Posts: 18
 Location: Italy
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Sep 09, 2011 1:51 pm |   |  
				| 
 |  
				| The compiler version is: 4.114 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Sep 09, 2011 2:21 pm |   |  
				| 
 |  
				| I put this code in a standard small template with #include, #fuses, #use delay, and main(), and it doesn't compile with vs. 4.114.   The last
 parameter is not in the 18F4550.h file.  Therefore this is not real code.
 
  	  | Quote: |  	  | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_16_BIT);
 | 
 
 Please post real tested code, with the #include, #fuses, #use delay(),
 and main().
 
 
 
 
 -----
 Edit:  Corrected a typo.  I meant to say "not real code".
 
 Last edited by PCM programmer on Sun Sep 11, 2011 1:17 pm; edited 1 time in total
 |  | 
	
		|  | 
	
		| acm45 
 
 
 Joined: 29 Dec 2008
 Posts: 18
 Location: Italy
 
 
			    
 
 | 
			
				| SOLVED |  
				|  Posted: Sun Sep 11, 2011 2:39 am |   |  
				| 
 |  
				| sorry for the parameter RTCC_16_BIT, I defined it into my 18F4550.h file as a 0x00. Anyway, I find the problem in my own code, setting the pwm duty cycle I was setting also the reverse bridge control. Thank you for your help!
 |  | 
	
		|  | 
	
		|  |