| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| jgschmidt 
 
 
 Joined: 03 Dec 2008
 Posts: 184
 Location: Gresham, OR USA
 
 
			        
 
 | 
			
				| PWM Timer Calculations Spreadsheet |  
				|  Posted: Sat Jun 12, 2010 3:34 pm |   |  
				| 
 |  
				| While working on a PWM application I struggled with datasheets, application notes and forum topics to arrive at the correct parameters for the CCS statements that control the PWM hardware. I also wanted to capture what I learned since I would probably forget it by the time I needed it again, so I developed a spreadsheet that produces the actual statements you need to include in your program. This was featured in the June 2010 issue of Servo Magazine. The article and spreadsheet are on my website at www.jgscraft.com/ledpwm. 
 Here is an example of the code the spreadsheet produces for a PWM frequency of 16KHz on a midrange PIC running at 8MHz.
 
  	  | Code: |  	  | setup_timer_2(T2_DIV_1, 124, 1 ); setup_ccp1( CCP_PWM );
 set_pwm1_duty( 250L ); // square wave output - 50% duty
 | 
 The spreadsheet assumes 4 clocks per instruction cycle.
 
 Enjoy.
 |  | 
	
		|  | 
	
		| TYSCSTOM 
 
 
 Joined: 03 Jun 2010
 Posts: 8
 Location: Houston
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat Jul 03, 2010 10:13 am |   |  
				| 
 |  
				| Great work! I plan on using this for several projects in the future.
 Having run through several scenario, it looks accurate to me.
 |  | 
	
		|  | 
	
		| jgschmidt 
 
 
 Joined: 03 Dec 2008
 Posts: 184
 Location: Gresham, OR USA
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Sat Jul 03, 2010 5:14 pm |   |  
				| 
 |  
				| Thanks for the feedback. |  | 
	
		|  | 
	
		|  |