Stateflow    

Defining Function Call Output Events

Use a function call output event from a Stateflow block to trigger the execution of a connected Simulink subsystem with the following procedure:

  1. Use Stateflow Explorer or the Add -> Data menu selection in the Stateflow diagram editor to add an Output to Simulink event.
  2. Select Function Call for the event's Trigger field the properties dialog for the event. See Defining Output Events).
  3. In Simulink, place a Trigger block in the subsystem you want to trigger from Stateflow.
  4. In the Triggerport parameters dialog for the Trigger block, set the Trigger type field to function-call.
  5. Connect the output port on the Stateflow block for the Function Call trigger Output to Simulink event to the function-call trigger input port of the subsystem.

You should avoid placing any other blocks in the connection lines between the two blocks for Stateflow blocks that have feedback loops from a block triggered by a function call.

Function Call Output Events Example

The following example demonstrates how Stateflow uses function call output events to call Simulink subsystems:

The control Stateflow block has one data input called pulse and two event Function Call outputs 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 control 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:

  1. State A exit actions execute and complete.
  2. State A is marked inactive.
  3. The transition action is executed and completed.
  1. In this case the transition action is a broadcast of 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.

  1. State B is marked active.
  2. State B entry actions execute and complete (x = x + y). The value of y is the updated value from the band pass filter1 block.
  3. The Stateflow diagram goes back to sleep, waiting to be awakened by another event.

  Defining a Continuous Stateflow Block Defining Edge-Triggered Output Events