Real-Time Simulation Results Differ from Offline

SST.plecs (373.0 KB)

I’m currently working on a simulation project and encountered an issue I hope someone can help with. My offline simulation results are acceptable and behave as expected. However, when I run the same setup in real-time, the waveform output is completely different.

I’m trying to understand what could cause such a discrepancy and how to start debugging this. Any suggestions on what to check first—timing issues, data handling, hardware constraints, etc.—would be greatly appreciated.

Thanks in advance!

There are a few ways to improve this model. There’s a few minor RT Box improvements, but the big issues are on the C2000 control and sensing side.

From the RT Box side, the main issue is that your multi-tasking approach introduced additional latency where the PWMs were sampled in another task and then communicated to the powerstages through inter-processor communication. The attached model uses newer RT Box features including Nanostep implementations for the DAB and PFC stages. Since you are using an RT Box 3, you can also improve the model performance by using the FlexArray solver.

Another major issue in the model is that the sensor scaling is inappropriate. For the AC voltage there is only +/-10 mV from peak-to-peak. When sensed by the C2000 12-bit ADC this measurement is quantized to 0.8 mV so the voltage measurement has a lot of quantization noise. This is true for all of your signals. The RT Box also has quantization effects, which you can minimize by choosing the best analog output range (0-5 V in your case. Was originally -10-10 V).

I corrected the scaling for the output voltage but not the other measurements, which need to be corrected. You can look at the “vac iac vdc vdab_out” analog output in the PLECS top-level schematic to see how small the actual change in output voltage is. You can actually also configure the ADC offline model to represent quantization. Another minor thing is I changed out the PLL with a block from the On-Board Charger demo model, which better handles DC offsets in the AC voltage measurement due to calibration error.

Your C2000 subsystem has a base task interrupt of 50 kHz, which is likely too high for the low-powered 28069. Connecting to the external mode halts the MCU execution. You can slow down the interrupt using the InterruptScalar parameter added. The model also has an excessive number of scopes for real-time observation. There’s further optimizations possible, for example reducing the number of sin/cos calculations in your transformations by calculating sin/cos once and re-using throughout the model. There also is no anti-winding or saturation for any controls or integrator blocks.

Anyways, with these changes you at least can now connect to the external mode of your MCU and debug you controls further.

SST_BL.plecs (302.2 KB)

Hi Bryan! Appreciate your reply. Thank you for the corrected model and suggestions.