PWM Dutycycle calculation Formula

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi,

i want to generate pwm  for diffrent %of duty cycle.

I know the formula of dutycycle is 

                      dutycycle=100 x compare value/period.

But this formula is giving wrong results in som ecases.

For example.

    i want to generate a dutycycle of 50%  ,

then my settings are   compare value=1,set period=2ms ,input fequency is 1000HZ .According to the formula it has to give  50% duty cycle.

But in the configuration window it shows the wavesorm of 70% .

so,please help me to resolve the issue

Thanks in advance.

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You wrote

                      dutycycle=100 x compare value/period.

this is not quite correct

                      dutycycle=100 x compare value/period value

is better.

So the period value should be set to 19 (giving a period of 20 pulses) the input clock to 10kHz and the compare value to 10.

Always leave some room for adjustings, you could have choosen as well

Period value = 199, input clock 100kHz, compare value = 100.

This settings would allow for a 1% resolution setting of the duty cycle.

Bob

View solution in original post

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You wrote

                      dutycycle=100 x compare value/period.

this is not quite correct

                      dutycycle=100 x compare value/period value

is better.

So the period value should be set to 19 (giving a period of 20 pulses) the input clock to 10kHz and the compare value to 10.

Always leave some room for adjustings, you could have choosen as well

Period value = 199, input clock 100kHz, compare value = 100.

This settings would allow for a 1% resolution setting of the duty cycle.

Bob

0 Likes