CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PWM Timer Calculations Spreadsheet

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

View user's profile Send private message Send e-mail Visit poster's website

PWM Timer Calculations Spreadsheet
PostPosted: Sat Jun 12, 2010 3:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 03, 2010 10:13 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jul 03, 2010 5:14 pm     Reply with quote

Thanks for the feedback.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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