Hello
I am currently designing a closed-loop Grid-Forming (GFM) inverter in islanded mode using an HIL RT Box, where the plant is modeled on the RT Box and the closed-loop controller is implemented on an STM32G474RE. The closed-loop controller consists of a voltage control loop and a current control loop. The voltage control loop regulates the voltage at the PCC bus according to the desired reference voltage, which then generates a current reference used by the current controller to regulate the current injected into the PCC bus. However, in this model, I have not implemented a power synchronization control (PSC) such as droop control or a virtual synchronous generator (VSG). Instead, I simplified the model by removing the PSC and directly setting Vd_ref and θ (theta). The offline simulation results shown in Fig. 3 indicate that the PCC bus voltage can be properly regulated using the proposed closed-loop controller. In addition, I performed an HIL-to-HIL simulation, the results of the HIL-to-HIL simulation are shown in Fig. 4. However, when I implemented the controller on the STM32G474RE connected to the RT Box, the results became unusual compared to the offline and HIL-to-HIL simulations.
What could be the possible reasons for this discrepancy? Should I make adjustments to my closed-loop controller implementation, for example by applying a multitasking strategy or modifying the discretization step size configuration on the STM32?
Fig 1. Plant
Fig 2. Controller
Fig 3. Offline Simulation Result
Fig 4. HIL2HIL Simulation Result
Fig 5. RT Box and STM32 Result:
Here model that i am using for RT Box-STM32 :
Closed_Loop_GFM.plecs (224.0 KB)
1 Like
Hello
The issue can be resolved by pressing the reset button on the STM32 after build. However, the results remain unbalanced, and I am not sure what is causing this imbalance.
Mr @Bryan_Lieblick could you please take a look at this issue when you have time? I would really appreciate your insight.
1 Like
The issue here is due to pin conflicts between the STM32 Nucleo DAC channels and the RT Box / LaunchPad Nucleo interface board.
A few basic debugging steps would have revealed this:
- Run your model in open loop (fix V_{dq})
- Connect a PLECS Scope to the Analog In channels of the RT Box and note the signals are not as expected.
- Connect a hardware scope to the pins. Test with the Nucleo connected to the RT Box and with the Nucleo floating.
The G474 can only use PA4, PA5, and PA6 as DAC output channels as you have correctly chosen. The RT Box interface board wasn’t designed to support DAC connections to the RT Box (as the RT Box analog input connector isn’t part of the interface). A table of the pin functionalities and resulting issues are below.
| STM32 Function |
STM32 Pin |
RT Box Function |
Comments |
| DAC1_OUT1 |
PA4 |
AO2 |
Will always conflict based on analog out setting. Also used for V_{pcc\_out} phase b. |
| DAC1_OUT2 |
PA5 |
DI27 |
Functional. |
| DAC2_OUT1 |
PA6 |
DO1 |
Will always conflict. RT Box DO always 0 or 3.3V. |
One resolution would be to electrically isolate the channels that conflict - say by header connectors with clipped pins. In this case an alternative would be to use SPI communication to send the setpoint values to the RT Box. See the attached model.
Closed_Loop_GFM_SPI.plecs (140.6 KB)
Another issue in your model worth pointing out is the role of the integrator blocks generating an angle. Those should have wrapping enabled from 0-2*pi. The issue will manifest for longer runs due to round-off error when a very small value (increment) is added to a large value (integrator state). You also could use the same angle for all DQ transformations to be more computationally efficient.
Mr. @Bryan_Lieblick thank you for your feedback.
I apologize for not mentioning earlier that my model is not running on the LaunchPad Nucleo interface board, since I connected the STM32 and the RT Box separately using jumper cables.
The previous current imbalance was caused by an incorrect phase configuration of the PCC current signals (Ipcc), where phase B from the RT Box was connected to phase C on the STM32, and vice versa. After correcting the swapped phase configuration, the real-time simulation ran properly and produced good results.
I am interested in using SPI communication to transfer measurement data from the plant to the controller, which will be used for closed-loop control. However, I am still unsure how to configure the SPI communication between the RT Box and the STM32.
Are there any documentation files or demo models that I can study?
Thanks for the update Rizal. I’m glad you were able to diagnose the issue.
However, I am still unsure how to configure the SPI communication between the RT Box and the STM32. Are there any documentation files or demo models that I can study?
Please see the model I attached previously where the RT Box is the is the Peripheral device and the STM32 is the controller.