There isn’t enough information here to assist you. For a well implemented real-time model, the root cause is likely something in your model that differs between offline and real-time.
For example:
Your model already includes a slow error build-up that is only visible for extended simulation runs.
Introducing noise or DC offset into a control algorithm leads to different results.
A sensor or signal is incorrectly mapped between the real control hardware and RT Box while it works fine in a model.
Some events are perfectly synchronous in an offline simulation but differ when executed in real-time due to different clocks (i.e. RT Box and controller do not share a common clock).
I read you’ve an idea of what I am working on from our previous interactions. While I consider the points you highlighted here, see a more merged plot for more info if that clarifies stuffs a little more.
I am looking at the last point that you made, “Some events are perfectly synchronous in an offline simulation but differ when executed in real-time due to different clocks (i.e., RT Box and controller do not share a common clock).” I noticed that I don’t get PWM 3 and PWM 4, that is, the inverter leg B, don’t output correctly as shown here:
I’ve tried different things, from adjusting Ts for the plant through Ts_controller, etc. Do you have further suggestions based on the plot attached now?
Well the PWM3 and 4 duty cycle is clearly wrong, but determining why is an open-ended question that requires a systematic debugging process.
One can investigate if discretizing the RT Box or controller model is an issue by using CodeGen simulation offline on your PC to see the discrete-time behavior of the model. See the Simulation Mode parameter which you can configure for your RT Box and TI C2000 subsystems.
The other steps would be systematically debugging from open loop simulation and then progressively adding in more complexity.
For example:
Test analog measurements without closed loop control. Do measurements and scaling make sense? Do they differ from your offline model?
Test any phase-locked loops.
Test open-loop modulation scheme.
Sequentially verify control loops from inner-most to outer-most loops.