2016-08-28

I am trying to control a H-bridge converter using one PWM generator for each diagonal (PWM1 and PWM4 in my case).
I want to be able to control both frequency and duty cycle.
To do so, I generate a trigger interrupt at the beginning of PWM4 period, and then update registers for period, phase and duty cycle for both PWM channels.
The problem is, when this update happens, there is some unexpected behaviour for one period or so. See picture:
PWM4 is cyan, PWM1 is magenta, and yellow toggles when trigger interrupt for PWM4 happens

It seems like PWM1 (magenta) updates to a slower frequency (as it should), but PWM4 keeps running on the old one for another period. Also PWM1 produces one more short impulse.
I measured the time it takes to update values for period, duty and phase registers, and it is around 1us so that shouldn't be a problem.
Here are PWM configurations:

They are set to independent mode, using master time base.

Now, I don't want to flood this question with too much code, but if you think that it might help, I will post more.

Show more