Good afternoon,
I am using an STM32G474VE board to control a synchronous buck converter. My initial goal is to implement an open-loop voltage controller and measure the buck converter’s current and voltage signals.
I designed my controller in PLECS and successfully flashed it onto the STM32G474. However, I am encountering issues when using the External Mode to modify duty cycle values in real time. When I enable External Mode and flash the microcontroller, the communication fails, and I receive the following error message:
“Communication error for system ‘BUCK_BO’: Wrong port or no response from target.”
Last week, I performed several tests on the ADC, DAC, and HRTIMER with a switching frequency of 20 kHz, and everything worked perfectly.
For my actual application, I increased the HRTIMER frequency to 136 kHz (with a system clock of 170 MHz). At this frequency, External Mode fails to connect, and the DAC is no longer updated in real time.
Do you have any insights into why these communication and update issues occur at frequencies above 20 kHz?
BUCK_BO.plecs (73.4 KB)
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:
- Opening the Trigger tab of the HRTIM Master and changing the Repetition counter setting setting from the default value of
1 to N.
- 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)