Skip to Main Content Skip to Search
Product Documentation

Conditional Referenced Models

Kinds of Conditional Referenced Models

You can set up referenced models so that they execute conditionally, similar to conditional subsystems. For information about conditional subsystems, see About Conditional Subsystems.

You can use the following kinds of conditionally executed referenced models:

Enabled Models

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.

To see an example of an enabled subsystem, see enablesub. A corresponding enabled referenced model would use the same blocks as are in the enabled subsystem.

Triggered Models

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 demo that illustrates how you can use trigger ports in referenced models, see the Introduction to Managing Data with Model Reference demo. In that demo, see the "Top Model: Scheduling Calls to the Referenced Model" section.

Triggered and Enabled Models

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.

Function-Call Models

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 Function-Call Subsystems for more information. A referenced model that you can invoke in this way is a function-call model.

For an example of a function-call model, see the sldemo_mdlref_fcncall demo.

Working with Conditional Referenced Models

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.

Create Conditional Models

To create a conditional model:

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

    Kind 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, based on the kind of model:

    Kind of ModelTrigger Type Parameter Setting

    Triggered

    Triggered and enabled

    One of the following:

    • rising

    • falling

    • either

    Function-Call

    function-call

  3. Create and connect other blocks to implement the model.

    Enabled model example:

    Triggered model example:

    Function-call model example:

  4. Ensure that the model satisfies the requirements for a conditional model. See the appropriate section:

Reference Conditional Models

To create a reference to a conditional model:

  1. Add a Model block to the model that you want to reference the triggered model. See Creating 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.

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

  3. Create and connect other blocks to implement the parent model.

  4. Ensure that the referencing model satisfies the conditions for model referencing. See Simulink Model Referencing Requirements and Model Referencing Limitations for details.

Simulate Conditional Models

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:

For details about how to specify the input, see Importing Signal Data in Simulink.

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.

Generate Code for Conditional Models

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.

Requirements for Conditional Models

Conditional models must meet the requirements for:

In addition, conditional models must meet the requirements described below.

Enabled Model Requirements

Triggered Model Requirements

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.

Function-Call Model Requirements

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS