View previous topic :: View next topic |
Author |
Message |
sraiderk
Joined: 09 Feb 2005 Posts: 48
|
PWM Duty problem |
Posted: Wed Feb 20, 2019 1:26 am |
|
|
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
|
|
Posted: Wed Feb 20, 2019 1:27 am |
|
|
CCS C Version 5.076 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed Feb 20, 2019 2:18 am |
|
|
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
|
|
Posted: Wed Feb 20, 2019 4:13 am |
|
|
Perfect explanation. Thank you...Sorry for I said the compiler problem... |
|
|
|