Using Function-Call Subsystems

A Function-Call Subsystem block is a conditionally executed subsystem that runs each time the control signal has a function-call event. A Stateflow® chart, Function-Call Generator block, or an S-function block can provide function call events.

A function-call subsystem is analogous to a function in a procedural programming language. Invoking a function-call subsystem executes the output methods of the blocks within the subsystem in sorted order. For an explanation of Function-Call Subsystem blocks parameters, see Subsystem, Atomic Subsystem, Nonvirtual Subsystem, CodeReuse Subsystem

Creating a Function-Call Subsystem

To create a function-call subsystem:

  1. Add an Function-Call Subsystem block to your model.

    • Copy a block from the Simulink Ports & Subsystems library to your model.

    • Click the model diagram, start typing function-call, and then select Function-Call Subsystem.

  2. Set initial and disabled values for the Outport blocks. See Conditional Subsystem Initial Output Values and Conditional Subsystem Output Values When Disabled.

  3. Set how subsystem states are handled when executed.

    Open the subsystem block, and then open the block parameters dialog box for the Trigger block. From the States when enabling drop-down list, select:

    • held — States maintain their most recent values.

    • reset — States set to their initial conditions.

    • inherit — Use the held or reset setting from the parent subsystem initiating the function-call.

    For nested subsystems whose Function-Call Subsystem blocks have different parameter settings, the settings for the child subsystem override the settings inherited from the parent subsystem.

  4. Attach a function-call initiator to the function-call input port.

    If you attach an Inport block, open the block, select the Signal Attributes pane, and then select the Output function call check box.

You can also create a function-call subsystem from scratch. First, add a Subsystem block in your model, and then add a Trigger block in the subsystem. Next, open the Trigger block dialog box and set the Trigger type to function-call.

Sample Time Propagation in a Function-Call Subsystem

Configure a Function-Call Subsystem block by setting the Sample time type of its Trigger port block to triggered or periodic.

  • A triggered function-call subsystem can execute zero, one, or multiple times during a time step.

    If a function-call subsystem is triggered by a root Inport block with a discrete sample time, multiple function-calls during a time step are not allowed. To allow multiple function-calls, set Sample time to -1.

    You must set the sample time for all the blocks in a triggered function-call subsystem to inherited (-1).

  • A periodic function-call subsystem executes once during a time step and must receive periodic function-calls. If the function-calls are aperiodic, the simulation stops and an error message is displayed.

    You can specify a noninherited sample time or inherited (-1) sample time. All blocks that specify a noninherited sample time must specify the same sample time. For example, if one block specifies 0.1 as the sample time, all other blocks must specify a sample time of 0.1 or -1. If function-calls are at a rate that differs from the sample time specified by the blocks in the subsystem, the simulation stops and an error message is displayed.


During range checking, the minimum and maximum parameter settings are back-propagated to the actual source port of the function-call subsystem, even when the function-call subsystem is not enabled.

To prevent this back propagation:

  1. Add a Signal Conversion block and a Signal Specification block after the source port.

  2. Set the Output of the Signal Conversion block to Signal copy.

  3. Specify the minimum and maximum values for the Signal Specification block instead of specifying them on the source port.

See Also


Related Examples

More About

Was this topic helpful?