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 Duty problem

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



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

PWM Duty problem
PostPosted: Wed Feb 20, 2019 1:26 am     Reply with quote

Timer 2 define the period of PWM.

set_pwm1_duty((int16)420); After that %50 ON %50 OFF signal of PWM one cycle pulse.

Then, I changed Timer2 frequency so, PWM period changed. Afterwords,set_pwm1_duty((int16)420); was not create %50 percent duty. I saw that pulse ON length is exactly same both frequency (T2). Only changing occurred at OFF cycle of PWM. I think same problem compiler side.
sraiderk



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

PostPosted: Wed Feb 20, 2019 1:27 am     Reply with quote

CCS C Version 5.076
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Feb 20, 2019 2:18 am     Reply with quote

Not a compiler problem.

If you change the frequency, you have to change the numbers used for
given duty cycles:

setup_timer_2(T2_DIV_BY_1, NN, Y);

The second value here 'NN', is the 'PR2' value (it is called this in some of
the data sheets).

The value needed for a particular 'duty', is:

(PR2+1)*4*duty

So if PR2 was set to '209', then the value needed for 50%, would be

(210+1)*4*0.5 = 420

If you change your PR2 value to give twice the frequency, so PR2 = 104,
then to get 50% the duty value would need to change to:

(104+1)*4*0.5 =210

You have to calculate the value needed for a particular percentage on
time, dependant on the clock rate you are selecting.
sraiderk



Joined: 09 Feb 2005
Posts: 48

View user's profile Send private message

PostPosted: Wed Feb 20, 2019 4:13 am     Reply with quote

Perfect explanation. Thank you...Sorry for I said the compiler problem...
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