|On this page…|
You can set up referenced models so that they execute conditionally, similar to conditional subsystems. For information about conditional subsystems, see Conditional Subsystems.
You can use the following kinds of conditionally executed referenced models:
Enabled and triggered
Use an Enable block to insert an enable port in a model. Add an enable port to a model if you want a referenced model to execute at each simulation step for which the control signal has a positive value.
Use a Trigger block to insert a trigger port in a model. Add a trigger port to a model if you want to use an external signal to trigger the execution of that model. You can add a trigger port to a root-level model or to a subsystem.
This section focuses on models that contain a trigger port with an edge-based trigger type (rising, falling, or either).
To view a model that illustrates how you can use trigger ports in referenced models, see the Introduction to Managing Data with Model ReferenceIntroduction to Managing Data with Model Reference example. In that example, see the "Top Model: Scheduling Calls to the Referenced Model" section.
A triggered and enabled model executes once at the time step for which a trigger event occurs, if the enable control signal has a positive value at that step.
Simulink® allows certain blocks to control execution of a referenced model during a time step, using a function-call signal. Examples of such blocks are a Function-Call Generator or an appropriately configured custom S-function. See Create a Function-Call Subsystem for more information. A referenced model that you can invoke in this way is a function-call model.
Use a similar approach for each kind of conditionally executed referenced model for these tasks:
Each kind of conditionally executed model has some model creating requirements. For details, see Requirements for Conditional Models.
To create a conditional model:
At the root level of the referenced model, insert one of the following blocks:
|Kind of Model||Blocks to Insert|
Triggered and Enabled
Trigger and Enable
For an enabled model, go to Step 3.
For the Trigger block, set the Trigger type parameter, based on the kind of model:
|Kind of Model||Trigger Type Parameter Setting|
Triggered and enabled
One of the following:
Create and connect other blocks to implement the model.
Enabled model example:
Triggered model example:
Function-call model example:
Ensure that the model satisfies the requirements for a conditional model. See the appropriate section:
To create a reference to a conditional model:
Add a Model block to the model that you want to reference the triggered model. See Create a Model Reference for details.
The top of the Model block displays an icon that corresponds to the kind of port used in the referenced model. For example, for a triggered model, the top of the Model block displays the following icon.
For enabled, triggered, and triggered and enabled models, go to Step 3.
For a function-call model, connect a Stateflow® chart, Function-Call Generator block, or other function-call-generating block to the function-call port of the Model block. The signal connected to the port must be scalar.
Create and connect other blocks to implement the parent model.
Use Normal, Accelerator, or Rapid Accelerator mode to simulate a conditional model.
You can run a standalone simulation of a referenced model. A standalone simulation is useful for unit testing, because it provides consistent data across simulations, in terms of data type, dimension, and sample time. In the Trigger or Enable block, in the Signal Attributes pane of the Block Parameters dialog box, specify values to lock down the signal data type, dimension, and sample time.
To run a standalone simulation of a conditional model, specify the inputs using the Configuration Parameters > Data Import/Export > Input parameter. The following conditions apply when you use the Input parameter for trigger and enable port inputs:
Use the last data input for the trigger or enable input. For a triggered and enabled model, use the last data input for the trigger input.
If you do not provide any input values, the simulation uses zero as the default values.
For details about how to specify the input, see Techniques for Importing Signal Data.
You can log data to determine which signal caused the model to run. For the Trigger or Enable block, in the Main pane of the Block Parameters dialog box, select Show output port.
You can build model reference Simulink Coder™ and SIM targets for referenced models that contain a trigger or enable port. You cannot generate standalone Simulink Coder or PIL code. For information about code generation for referenced models, see Reusable Code and Referenced Models and Generate Code for Referenced Models.
Conditional models must meet the requirements for:
Conditional subsystems (see Conditional Subsystems)
Referenced models (see Simulink Model Referencing Requirements)
In addition, conditional models must meet the requirements described below.
Multi-rate enabled models cannot use multi-tasking solvers. You must use single-tasking.
For models with enable ports at the root, if the model uses a fixed-step solver, the fixed-step size of the model must not exceed the rate for any block in the model.
The signal attributes of the enable port in the referenced model must be consistent with the input that the Model block provides to that enable port.
The signal attributes of the trigger port in the referenced model must be consistent with the input that the Model block provides to that trigger port.
A function-call model cannot have an outport driven only by Ground blocks, including hidden Ground blocks inserted by Simulink. To meet this requirement, do the following:
Insert a Signal Conversion block into the signal connected to the outport.
Enable the Exclude this block from 'Block reduction' optimization option of the inserted block.
The referencing model must trigger the function-call model at the rate specified by the Configuration Parameters > Solver 'Fixed-step size' option if the function-call model meets both these conditions:
It specifies a fixed-step solver
It contains one or more blocks that use absolute or elapsed time
Otherwise, the referencing model can trigger the function-call model at any rate.
A function-call model must not have direct internal connections between its root-level input and output ports. Simulink does not honor the None and Warning settings for the Invalid root Inport/Outport block connection diagnostic for a referenced function-call model. It reports all invalid root port connections as errors.
If the Sample time type is periodic, the sample-time period must not contain an offset.
The signal connected to a function-call port of a Model block must be scalar.