Documentation

Perform Computations in Function-Call Subsystems

When to Use Function-Call Subsystems for Computations on Event-Based Signals

In some situations, the most appropriate way to implement a numerical computation involving event-based signals is to place the computational blocks inside the Function-Call Subsystem block. When using this block, set the Sample time type parameter of the Trigger block to triggered.

How to Set Up Function-Call Subsystems for Computations

  1. From the Ports & Subsystems library, copy the Function-Call Subsystem block from the Simulink® into your model.

  2. Open the Function-Call Subsystem block by double-clicking it. Initially, the subsystem contains:

    • An Inport block connected to an Outport block. The Inport block represents an input signal that provides data but does not cause the subsystem to execute.

    • A block labeled "function". This block represents a function-call signal that causes the subsystem to execute.

  3. In the empty Function-Call Subsystem window, create the contents of the subsystem. Use Inport blocks to represent input from outside the subsystem that provides data but does not cause the subsystem to execute. Use Outport blocks to represent external output. To learn which blocks are suitable for use inside the subsystem, see Blocks Inside Subsystems with Event-Based Inputs.

  4. At the upper level of your model hierarchy, create or identify the function-call signal that causes the subsystem to execute. To create this signal, you might need to do any of the following:

    • Create a function-call signal that indicates the occurrence of signal-based events or entity departure events. Use the Time-Based Function-Call Generator, Signal-Based Function-Call Generator or Entity Departure Function-Call Generator block.

    • Create a union of function-call signals using the Mux block.

    • Convert a function-call signal that originates from a block in the Simulink library set into an event-based function-call signal, using the Timed to Event Function-Call block.

  5. Connect data signals to the ports that correspond to the Inport blocks inside the subsystem. Connect the function-call signal to the port labeled function().

Behavior of Computations in Function-Call Subsystems

When a Function-Call Subsystem block has event-based input signals, it behaves as follows:

  • The initial value of each output signal of the subsystem comes from the Initial output parameter of the corresponding Outport block inside the subsystem. Even if there is no function call to invoke the subsystem at T = 0, the Outport block creates a sample time hit for the initial value.

  • The subsystem executes whenever the function-call input signal has a function call. Sample time hits of the data input signals of the subsystem do not cause the subsystem to execute and do not cause sample time hits of the output signals.

  • Whenever the subsystem executes, all the blocks in the subsystem execute once, using the current values of their input signals. The sequence in which the blocks in the subsystem execute depends on the sorted order that the application determines.

  • At any given value of the simulation clock, conditions that cause the subsystem to execute can occur zero, one, or multiple times. Such flexibility and aperiodicity are characteristic of discrete-event simulations.

Refine the Behavior

Initial Value of the Subsystem Output

To change the initial value for an output signal of the subsystem, change the Initial output parameter of the corresponding Outport block.

Timing of Function Calls Versus Signal Updates

If your function-call signal executes the Function-Call Subsystem block before all the data signals are up to date, try prioritizing the function-call signal. By doing so, you defer the subsystem execution relative to other simultaneous events, such as signal updates. To prioritize a function-call signal, insert a Signal-Based Event to Function-Call Event block and configure it as in Generate a Function Call with an Event Priority.

Suppress Computations Selectively

To prevent certain function calls in the function-call signal from executing the Function-Call Subsystem block, use the techniques in Conditionalize Events.

Was this topic helpful?