2019-06-10 07:32 AM
Hello, Community.
I am currently trying to control a power converter with a STM32F4 microcontroller. The thing is that the control variable is the frequency of the PWM. I have programmed a timer (TIM3) that generates an interruption every 100us. During this interruption, the MCU has to calculate the new frequency value of the PWM in order to switch the power MOSFET.
I tried two options but none of them work as I want.
case a) Modifying the ARR register on the fly.
If I do this, I have seen that many times, the PWM doesn't work and remains at high level during a certain time (400us or so). Please, kindly see the yellow pulses. It obviously has effects over the power converter.
case b) I thought that since the register is not updated inmediately, I could reset the counter of the PWM timer. This time, the PWM no longer remains high during a certain time but it provides strange pulses.
TIM8 -> CNT = 0;
TIM8->ARR = "calculated value";
I read about diferent registers to make the updates of the registers inmediately but I am not capable. I tried many things but they don't work.
Could you give me a hint? Thanks a lot.
2019-06-10 07:39 AM
The AUTO/PRELOAD impacts when the new values are loaded. You can also pay attention to the phase by checking the CNT register.
Seeing as the Update state is CNT==0, perhaps write ARR before CNT
2019-06-10 07:40 AM
Min and Max PWM frequency?
Is duty cycle constant? (on the scope it is not)
When the frequency change, should it be at the rise/fall edge of the pulse?
2019-06-10 07:48 AM
[del-already-answered]
2019-06-10 08:16 AM
i tried changing the order of the instructions and it works the same way.
Duty is not constant because it depends on the ARR.
I read about enabling ARPE and OC1PE but it doesn't work either.
2019-06-10 08:24 AM
I have tried one simple thing.
Every 100us I change the frequency of the PWM by modifying the ARR register just by adding or substracting 10 to the original value. And every time the microcontroller does the same as in picture 2. The very first 2 or 3 cycles, the pulses have wrong duty cycle.
2019-06-10 09:01 AM
Just came to mind... how does the timer react to prescaler change?
2019-06-10 09:05 AM
Get the interrupt on UEV and change immediately both the output compare and the overflow ARR values.
If this works, then use other timer HW assists.
2019-06-10 10:10 AM
Thank you. I have forced the update of the PWM and it works as it should. However, I have to keep working on it because I cannot have two pulses right away. My strategy of getting into the control loop every 100us is not suitable because it interferes with the behaviour of the power converter. I can only change the frequency of the PWM every 100us but ALSO the CNT register must be equal or close to ARR. This way, I would not have two consecutive pulses.
I only came up with the idea of:
while (TIM8->CNT < TIM8->ARR)
;
But this is very dangerous. I do not know how else I can do it.
2019-06-10 12:29 PM