Main Content

Configure Time-Based Scheduling

When you are ready to generate code from a model, consider adjusting the model solver configuration. A solver computes the states of a model during simulation and in generated code by applying numerical methods to solve the set of ordinary differential equations (ODEs) that represent the model. The solver determines the time at which the next step occurs.

Solvers can be variable step or fixed step. Unless you are generating code for a model configured for a simulation target, you must use a fixed-step solver.

This topic focuses on configuring fixed-step solvers. For models from which you intend to generate code for safety-critical applications, see these high-integrity system modeling guidelines:

If you have a Simulink® Check™ license, you can use these code generation Model Advisor checks to check for compliance with the guidelines:

For information about choosing and configuring a variable-step solver, see Choose a Solver and Variable Step Solvers in Simulink.

Configure Solver Type

Unless a model is configured to use a simulation target, such as the one for Simulink accelerator mode, set the model configuration solver parameter Type to Fixed-step. Fixed-step solvers maintain a constant step size and compute the next time hit as the sum of the current time and the step size.

Configure Solver

Set model configuration parameter Solver to a fixed-step solver. Fixed-step solvers solve a model by using the same time interval for each step from the beginning to the end of simulation or program execution. The default setting for Solver is auto (Automatic solver selection). The automatic solver selection chooses an appropriate solver based on the setting of the Type parameter and factors such as the system dynamics.

For guidance on choosing a fixed-step solver, see Choose a Solver, Fixed Step Solvers in Simulink, and Choose a Fixed-Step Solver.

Configure Model Fixed-Step Size

For models configured to use a fixed-step solver, you can specify a fixed-step size, the time interval in seconds that the solver uses for the step size. Configure the fixed-step size by using model configuration parameter Fixed-step size (fundamental sample time). By default, this parameter is set to auto, which means that the software engine determines the step size for you. To specify a different fixed-step size, set the parameter to a double-precision value. If you choose to specify a fixed-step size yourself, the value must be less than or equal to the smallest discrete sample time specified in the model, and the discrete sample times in the model must be evenly divisible by the specified step size.

For the rules that the software applies for determining the step size, see Fixed-step size (fundamental sample time).

Configure Periodic Sample Time Constraints

Configure periodic sample time constraints by using model configuration parameter Periodic sample time constraint. You can set the parameter to unconstrained, Ensure sample time independent, or Specified.

This table indicates the setting to choose based on model sample time requirements:

RequirementParameter Setting
You want the software to use sample times specified for blocks in the model. The solver uses the specified fixed step size (fundamental sample time) as the base rate of the model. If the fixed step size is set to auto, the base sample rate is the greatest common factor of sample times used in the model.unconstrained
You want to specify an offset and priority for each sample time period in the model as an n-by-3 matrix where n is equal to the number of discrete sample time periods in the model. For example, [[1,0,0];[2,0,1];] specifies two sample time periods, one with an offset of 0 and priority of 0 and one with an offset of 0 and a priority of 1. The software uses the first element of the matrix as the model base sample rate.Specified
You want reference models to inherit sample time from the context in which they are used.Ensure sample time independent
You want to detect sample time problems related to referencing models that have intrinsic sample time inside triggered or iterator subsystems. Ensure sample time independent
You want to be able to call the model_step function at various rates.Ensure sample time independent

For a hybrid system, the continuous and discrete parts of a model can execute at different rates only if the discrete part executes at the same or a slower rate than the continuous part and is an integer multiple of the base sample rate. For more information, see Sample Times in Systems and Subsystems

Configure Tasking Mode

For models configured to use a fixed-step solver, you can configure the tasking mode. The tasking mode specifies whether blocks that have periodic sample times execute in a single task or are grouped by rate in multiple tasks.

To specify the tasking mode, select or clear themodel configuration parameter Treat each discrete rate as a separate task. To use single-tasking mode, clear the parameter. To use multitasking mode, select the parameter.

This table lists special conditions and tasking behaviors.

ConditionTasking Behavior
You configure the model for single-tasking mode.The Simulink engine and code generator apply single-tasking mode.

You configure the model for multitasking mode (you select Treat each discrete rate as a separate task) and the model contains one of the following:

  • One sample time only

  • A continuous sample time and a discrete sample time and the fixed step size is equal to the discrete sample time

The Simulink engine and code generator apply single-tasking mode.

You configure the model for multitasking mode (you select Treat each discrete rate as a separate task) and the model contains multiple sample times.

The Simulink engine and code generator apply multitasking mode.

Configure Solver Diagnostic Behavior

Consider configuring solver diagnostic behavior by using these model configuration parameters:

For more information, see Configure and View Diagnostics.