PWM Pre scaler is not showing consistent behaviour

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

cross mob
Mrinal
Level 4
Level 4
First solution authored 50 replies posted 25 replies posted

I am using two PWM modules both driven by the same clock.

   

PWM1 period = 99

   

PWM2 period = 9

   

Therefore in each cycle of PWM1, there are 10 cycles of PWM2. Everything works just perfect till here and the oscilloscope shows perfectly alligned outputs as expected.

   

Now, when I prescale PWM1 by 2x in the initial property window, PWM2 should complete 20 cycles in each one cycle of PWM1. It indeed does, BUT there is a phase shift of one clock period between PWM1 and PWM2. It doesn't end here. Instead of setting the prescaler to 2x in the initialization window, if I use the SetPrescaler() function in the code, the phase shift disappears!

   

In short, the PWM module works differently depending upon whether the Prescaler value has been set in the components initialization window  or whether it is set through programming.

   

Why is this happening?

   

Thank you...

0 Likes
3 Replies