Stop simulation block effect on aborting generated code execution.
2 views (last 30 days)
Show older comments
Hello,
I have a SIMULINK model that contains a STOP SIMULATION block which is activated for a certian condition. When I generated the C code for this model by embedded coder and did a SIL, I noticed that the condition was not called in the execution and the code kept running until the simulation time even the condition was true.
The question is: is STOP SIMULATION block affect in the generated code ? I mean that is it generated like interrupt or something that stops the execution and return to the main function? Or it is just useful in the MIL ?
0 Comments
Answers (1)
Poorna
on 2 Jun 2024
Hi Khaled,
It would be helpful if you can share the model that is causing the said issue. Stop Simulation block as per the documentation supports Code generation. When translated into code, this block operates through a boolean variable alongside a set of getter and setter functions. It's important to note that the Stop Simulation block will not halt the execution within the current active timestep. Instead, it completes the ongoing timestep's execution and prevents any further timesteps from being executed.
This behavior is mirrored in the code that's generated. Within the step function, the setter function is utilized to mark the boolean variable as true. However, the function doesn't terminate immediately but completes its planned execution. It is then the job of the main function to regularly check, via the getter function, whether the Stop Simulation boolean was set to true in the preceding run. Based on this check, the main function makes the decision on whether to proceed with invoking the step_function.
I recommend generating the code to examine the main.c and model.c files directly. This will allow you to see how the Stop Simulation functionality is implemented in practice.
Refer to the following documentation to know more about the Stop Simulation block:
Hope this Helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!