2025-02-05 03:58 AM - last edited on 2025-02-05 06:43 AM by Sarra.S
I am using the STM32H562ZGT to generate center-aligned PWM with TIM1.
Since I also want to use TIM1 for 20kHz periodic interrupts, I set the Period so that overflow/underflow occurs every 40kHz and set the Repetition Count to 1. This ensures that UEV occurs at the underflow timing every 20kHz, which I confirmed to be working as expected by combining an oscilloscope and GPIO Output.
Here, I want to set the center alignment of the PWM to High based on the overflow timing (which is offset by 40kHz from the above interrupt) rather than the underflow timing. However, when I used PWM mode 2 and observed the PWM output on the oscilloscope, the High period was 0.6-0.7 microseconds earlier than expected.
For example, with TIM1 generating 40kHz using 6249 counts at 250MHz, if I specify CH1 to be active at 3124 counts or more, the time from the underflow interrupt to PWM active was 11.8 microseconds. Ideally, this should be around 12.5 microseconds, which is almost 50% Duty.
If you have any insights into potential oversights or causes of this issue, or any other ideas for achieving center alignment, please let me know.
2025-02-05 07:16 AM
> time from the underflow interrupt to PWM active was 11.8 microseconds
Did you take into account the interrupt latency?
JW