Documentation

Change of Stop Time

If you change the step size of a real-time application at run time, the real-time application sometimes executes for fewer steps than you expect. The number of execution steps is:

floor(stop time/step size)

When you compile code for a model, Simulink® Coder™ calculates the number of steps based on the current step size and stop time. If the stop time is not an integral multiple of the step size, Simulink Coder adjusts the stop time to an integral multiple. If you change the step size without rebuilding the model, Simulink Real-Time™ uses the new step size and the previously adjusted stop time. The resulting model sometimes executes for fewer steps than you expect.

Suppose that a model has a stop time of 2.4 and a step size of 1. At compilation time, Simulink Coder adjusts the stop time of the model to 2. If you change the step size to 0.6 at run time but do not recompile the application, the expected number of steps is 4. The actual number of steps is 3 because Simulink Real-Time uses the previously adjusted stop time of 2.

To avoid this issue, check that the original stop time (as specified in the model) is an integral multiple of the original step size.

Was this topic helpful?