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 support@ccsinfo.com

how to set pic18f452 to its max pwm frequency

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lgeorge123



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

how to set pic18f452 to its max pwm frequency
PostPosted: Mon Jan 26, 2009 8:09 am     Reply with quote

using pic18f452 and crystal 20MHz , for the code :
setup_timer_2(T2_DIV_BY_1,255, 1) , I only get 20KHZ pwm frequency.
So how can I set to its max frequency ??????
Ttelmah
Guest







PostPosted: Mon Jan 26, 2009 10:09 am     Reply with quote

There is a balancing 'act', between the output frequency, and the available resolution steps. You code gives the maximum frequency, _supporting 1024 steps in the output_.
If you think about it, since the PWM 'steps' in single counts of the crystal, this will give:

20000000/1024 = 19531.25Hz

To go faster, you have to sacrifice accuracy. So for a PWM, supporting just ten steps say, you can get 2MHz as your output. The actual maximum, would be a PWM with:

setup_timer_2(T2_DIV_BY_1,0, 1);

giving just four counts of the master clock, per pulse (2.5MHz). However you only get 2bits of output resolution.

You need to decide on what PWM frequency you need, and then see if enough resolution will be available at this frequency. So if (for instance), you want 100000Hz, then this would be the master clock over 200, giving 200 possible output steps, and using:

setup_timer_2(T2_DIV_BY_1,49, 1);

wth allowable 'duty cycle' numbers from 0 to 199.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 26, 2009 6:38 pm     Reply with quote

Also see this thread for the PWM frequency formula:
http://www.ccsinfo.com/forum/viewtopic.php?t=17993

Related topics:
http://www.ccsinfo.com/forum/viewtopic.php?p=99719
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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