Main Content

Conditionally Execute Referenced Models

A conditionally executed referenced model, or conditional model, allows you to control its execution with an external signal. The external signal, called the control signal, is attached to the control input port. Conditional models are useful when you create complex model hierarchies that contain components whose execution depends on other components.

Conditional Models

You can set up referenced models to execute conditionally, similar to conditional subsystems. For information about conditional subsystems, see Conditionally Executed Subsystems Overview.

Simulink® software supports these conditional model types:

Conditional ModelDescription
Enabled

An enable port executes a referenced model at each simulation step for which the control signal has a positive value. To add an enable port to a Model block, insert an Enable block in the referenced model.

Simple enabled referenced model

For an example of an enabled subsystem, see Implement Control Algorithm Using Enabled Subsystem. A corresponding enabled referenced model uses the same blocks as are in the enabled subsystem.

Triggered

A trigger port executes a referenced model each time a trigger event occurs. To add a trigger port to a Model block, insert a Trigger block in the referenced model.

Simple triggered referenced model

Triggered and Enabled

A Model block can have both trigger and enable ports. If the enable control signal has a positive value at the time step for which a trigger event occurs, a triggered and enabled model executes once.

Function-Call

A function-call port executes a referenced model each time a function-call event occurs. To add a function-call port to a Model block, insert a Trigger block in the referenced model. Then, open the Block Parameters dialog box and set the Trigger type to function-call.

A Stateflow® chart, a Function-Call Generator block, a Hit Crossing block, or an appropriately configured custom S-function can provide function-call events. See Using Function-Call Subsystems.

Simple function-call referenced model

For an example of a function-call model, see Model Reference Function-Call.

Requirements for Conditional Models

Conditional models must meet the requirements for:

Conditional models must also meet the requirements specific to each type of conditional model.

Conditional ModelRequirements
Enabled
  • Multi-rate enabled models cannot use multi-tasking solvers. 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.

  • 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.

Triggered

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.

Triggered and EnabledSee requirements for triggered models and enabled models.
Function-Call
  • A function-call model cannot have an output port driven only by Ground blocks, including hidden Ground blocks inserted by Simulink. To meet this requirement, do the following:

    1. Insert a Signal Conversion block into the signal connected to the output port.

    2. Enable the Exclude this block from 'Block reduction' optimization option of the inserted block.

  • The parent 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 parent 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.

  • 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.

Modify a Referenced Model for Conditional Execution

  1. At the root level of the referenced model, insert one of the following blocks:

    Type of ModelBlocks to Insert

    Enabled

    Enable

    Triggered

    Trigger

    Triggered and Enabled

    Trigger and Enable

    Function-Call

    Trigger

    For an enabled model, go to Step 3.

  2. For the Trigger block, set the Trigger type parameter:

    Type of ModelTrigger Type Parameter Setting

    Triggered

    Triggered and enabled

    One of the following:

    • rising

    • falling

    • either

    Function-Call

    function-call

  3. Use the Model block ports to connect the referenced model to other ports in the parent model.

    • The top of the Model block displays an icon that corresponds to the control signal type expected by the referenced model. For a triggered model, the top of the Model block displays this icon.

      Model block with trigger port

See Also

| |

Related Topics