STM32G474 External Mode issue

This is a classic CPU overrun issue. In the initial model the CPU’s base task interrupt was 20 kHz. In your updated model it increases to 136 kHz (~7x increase). At the higher frequency CPU cannot complete all the required calculations in the time you have allocated.

See this Support Solutions article for a more comprehensive discussion. Note that some of the diagnostic features mentioned in this article are not available for STM32 target yet.

In your model there is no need to update the control loop at such a high frequency. All protections are done through high-speed analog comparators and everything else is driven by user-interaction via the external mode.

You can decouple the CPU Base Task frequency from the PWM frequency. This is done by:

  1. Opening the Trigger tab of the HRTIM Master and changing the Repetition counter setting setting from the default value of 1 to N.
  2. Change the Discretization step size in the Coder + Coder options + Scheduling tab from it’s current value of 1/136e6 to N/136e6.

Since 20 kHz previously worked, one can assume an initial value of N=7 for a 19.4 kHz base task interrupt. The resulting CPU load is ~30%. The switching frequency is still 136 kHz.

BUCK_BO_BL.plecs (75.7 KB)