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

Two different PWM frequency ranges

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



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

Two different PWM frequency ranges
PostPosted: Fri Aug 17, 2012 9:49 am     Reply with quote

PIC: 18F4620
Crystal: 16,384,000 MHz

The following code generates a PWM of exactly 128kHz 50% duty on PWM 1:

setup_timer_2( T2_DIV_BY_1, 31, 1 );
set_pwm1_duty( 16 );


PWM 1 = 16384000
-----------
1 x (31+1) x 4

PWM 1 = 16384000
-----------
128

PWM 1 = 128 000

How would I go about if I want my PWM 2 to be a totally different PWM frequency that requires a different calculation?

For instance, above, the function setup_timer_2( T2_DIV_BY_1, 31, 1 ); values 31 and T2_DIV_BY_1 gives me 128kHz.

But if I want PWM 2 to be 64kHz? I'd have to change 31 to 63.... Do I use a different timer?

I've used two PWM's before but both were the same frequency since they were for servos and the only thing I had to change were their individual duty cycles.

Now it's two different frequencies. I will check the manual but if someone know, please post it!

Thanks!

Ben
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Aug 17, 2012 11:17 am     Reply with quote

The answer is for sure in the 4620 data sheet.
See table 15.1


You might try the 18f46K22
as it has 3 options in Timer see 14.3.3

The 46k22 may cost less $$ for more features as a bonus.
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