| Stateflow User's Guide | ![]() |
Defining Function Call Output Events
This topic shows you how to trigger a function-call subsystem in Simulink with a Function Call output event in a Stateflow diagram. It assumes that you already have in place a programmed function-call subsystem and a Stateflow block in the Simulink model. Use the following steps to connect the Stateflow block to the function-call subsystem and trigger it during simulation.
| Note You cannot connect a function-call output event from Stateflow to a Simulink Demux block in order to trigger multiple subsystems. |
Function Call Output Events Example
The control Stateflow block has one data input called pulse and two function call output events called filter1 and filter2. A pulse generator provides input data to the control block. Each function call output event is attached to a subsystem in the Simulink model that is set to trigger by a function call.
Each transition in the control chart has a condition based on the size of the input pulse. When taken, each transition broadcasts a function call output event that determines whether to make a function call to filter1 or filter2. If the Output to Simulink function call event filter1 is broadcast, the band pass filter1 subsystem executes. If the Output to Simulink function call event filter2 is broadcast, the band pass filter2 subsystem executes. When either of these subsystems is finished executing, control is returned to the control Stateflow block for the next execution step. In this way, the Stateflow block controls the execution of band pass filter1 and band pass filter2.
Function Call Semantics Example
In this example the transition from state A to state B (in the Stateflow diagram) has a transition action that specifies the broadcast of event1. event1 is defined in Stateflow to be an Output to Simulink with a Function Call trigger type. The Stateflow block output port for event1 is connected to the trigger port of the band pass filter1 Simulink block. The band pass filter1 block has its Trigger type field set to Function Call.
This sequence is followed when state A is active and the transition from state A to state B is valid and is taken:
A exit actions execute and complete.
A is marked inactive.
event1. Because event1 is an event output to Simulink with a function call trigger, the band pass filter1 block executes and completes, and then returns to the next statement in the execution sequence. The value of y is fed back to the Stateflow diagram.
B is marked active.
B entry actions execute and complete (x = x + y). The value of y is the updated value from the band pass filter1 block.
| Defining a Continuous Stateflow Block | Defining Edge-Triggered Output Events | ![]() |
© 1994-2005 The MathWorks, Inc.