1 Reply Latest reply on Feb 9, 2018 2:47 AM by user_1377889

    PWM Dutycycle calculation Formula




      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.

        • 1. Re: PWM Dutycycle calculation Formula

          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.