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

PWM

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



Joined: 07 Oct 2003
Posts: 66
Location: England

View user's profile Send private message

PWM
PostPosted: Mon Jan 12, 2004 9:47 am     Reply with quote

Hi all!

Having not used the Pic PWM module before is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps.
I fear I may not get the resolution I require maybe 128 is more realistic!
Iwould be running the clock at 20mhz.
Thanks.

Dave
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: PWM
PostPosted: Mon Jan 12, 2004 10:24 am     Reply with quote

davt wrote:
Hi all!

Having not used the Pic PWM module before is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps.
I fear I may not get the resolution I require maybe 128 is more realistic!
Iwould be running the clock at 20mhz.
Thanks.

Dave


20mhz. is 5M IPS (instructions cycles per second)
You can setup timer2 to overflow every 250 instructions cycles.

setup_timer_2 ( T2_DIV_BY_1, 250, 1);

5M / 250 = 20K frequency
The PWM putput will toggle at overflow.
pwm1_duty is the count of timer2 that toggles the PWM output.

set_pwm1_duty (125)

will give 50% duty cycle.


Last edited by Neutone on Mon Jan 12, 2004 12:45 pm; edited 1 time in total
Ttelmah
Guest







Re: PWM
PostPosted: Mon Jan 12, 2004 10:29 am     Reply with quote

davt wrote:
Hi all!

Having not used the Pic PWM module before is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps.
I fear I may not get the resolution I require maybe 128 is more realistic!
Iwould be running the clock at 20mhz.
Thanks.

Dave

Go to the Microchip website, and get AN539, and AN564. They describe the options and limits for the PWM very well.
You can get 8bit at 40KHz OK (the limit is about 8.9 bits for this frequency), in hi-resolution mode.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 12, 2004 10:55 am     Reply with quote

Quote:
is it possible to produce a frequency of 40 khz whose duty cycle is variable in 255 steps. I fear I may not get the resolution I require


Piclist has a chart, and also a forumula that lets you calculate
the number of bits of resolution for a given frequency.
http://www.piclist.com/techref/microchip/pwmrescalc.htm
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