Stateflow User's Guide Previous page   Next Page

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.

  1. In the Stateflow diagram editor, from the Add menu, select Data.
  1. A pop-up menu of different event scopes appears.

  1. From the pop-up menu select Output to Simulink.
  1. The Event dialog appears with a default name of event and a Scope of Output to Simulink.

  1. In the Event dialog, in the Trigger field, select Function Call .
  2. Name the event appropriately and select OK to close the dialog.
  1. An output port with the name of the event you add appears on the right side of the Stateflow block.

  1. From the Simulink library browser Ports & Subsystems library, place a function-call subsystem in the Simulink model.
  1. You can also create a function-call subsystem by adding a subsystem to the model and adding a Trigger port to the subsystem. In the Triggerport parameters dialog for the Trigger block, set the Trigger type field to function-call.

  1. Connect the output port on the Stateflow block for the Function Call trigger Output to Simulink event you add to the function-call trigger input port of the subsystem.
  1. You should avoid placing any other blocks in the connection lines between the Stateflow block and the function-call subsystem for Stateflow blocks that have feedback loops from a block triggered by a function call event.

  1. To execute the function-call subsystem, include an event broadcast of the function call output event in the actions of the Stateflow diagram as shown in the following example.

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:

  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.

Previous page  Defining a Continuous Stateflow Block Defining Edge-Triggered Output Events Next page

© 1994-2005 The MathWorks, Inc.