Hi Marco,
I see that you are integrating generated code from a Simulink model with external code. While doing so, it's important to configure the solver sample time and stop time in a way that aligns with the timing behavior of the external system.
Here is some input on how you can configure these parameters:
Sample Time Configuration : Depending upon your model, you might consider choosing a proper solver configuration.
- Fixed-step solver: Choose a fixed-step solver if your external system operates at a fixed rate. You can set the sample time to match the tick rate of the external system's scheduler.
- Variable-step solver: Although this is less common for code generation, as most real-time systems require a fixed-step execution. This is because they can change the step size during simulation to maintain accuracy, which is not predictable for real-time systems.However, if you're integrating with a system that can handle variable-step execution, you may choose a variable-step solver.
You can do this using the follwoing command:
set_param(model, 'Solver', 'FixedStepDiscrete');
set_param(model, 'FixedStep', 'sample_time_value');
Stop Time Configuration : You can try the following options
- Set to inf: If the generated code is to run indefinitely, as is typical in embedded systems, you can set the stop time to infinity.
- Set a specific value: If you're generating code for batch simulations, you might want to specify a stop time that corresponds to the desired length of the simulation.
Remember to always validate the generated code with your external system to ensure that the timing behavior is as expected.
You can also refer th the following links for references :
Hope this helps!