Manoj wrote:What do you exactly mean by end of the cycle?
Do you mean to update it at the end of the while loop.
No. I mean right when the timer that the PWM peripheral is using has rolled over back to zero.
That is the "start" of the PWM cycle.
If you change the PWM at any other point in time, then you add jitter.
Also, if you don't reset the timer to zero when you update the PWM parameters, you risk setting a compare value that is smaller than the current timer count, which will give you one 100% cycle.
If you are just setting the PWM to keep outputting a static value, then you can be careless about precisely WHEN you set everything.
If you're trying to rapidly vary it "on the fly", then you need to understand precisely how it works, and make sure your changes are synchronised to the waveform.