2025-03-17 11:58 AM
I am using an STM32L496ZG-P to create PWM signals for a switching power supply, and I need to precisely vary the frequency linearly over the course of a shot. My clock speed is 80MHz and I need 20ms long PWM pulses in the 10-20kHz range. To start, I am using TIM1 to create a PWM output with ARR = 35, and PSC of 100, and then using TIM17 to generate interrupts every 5ish ms. In the HAL_TIM_PeriodElapsedCallback(), I am calculating a new PSC value based on the amount of time elapsed since the start of the pulse and then using TIM1->PSC=newPSC to change the frequency. This works beautifully when increasing frequency, but when decreasing frequency (increasing PSC) TIM1 stops updating after the first change in frequency. Its as if the counter skips over the ARR value and counts on forever. This is confusing to me, because I am not changing the ARR, so
Following suggestions from other posts, I have made sure to enable ARPE.
If anyone has any insight on how to fix this, or better approaches for varying PWM frequency dynamically, that would be helpful!!
2025-03-17 3:21 PM
> TIM1 stops updating after the first change in frequency.
How do you know? What are the symptoms, exactly? What exactly do you do in the ISR?
Read out and check/post content of TIM registers when this happens.
JW