| Stateflow User's Guide |
 |
Sending a Trigger Event to the Stateflow Chart
You define a trigger event for the Controller diagram in Adding a Trigger Event to the Stateflow Diagram. The Controller block in Simulink now has a trigger port for the event event. To update the Controller diagram, the Simulink model must send a signal to the trigger port to trigger the event in the Controller diagram.
You defined the trigger event event with an Either trigger (either rising or falling) for the Controller diagram. This event occurs when a control signal attached to the trigger port for the Controller diagram rises or falls in value as it passes through zero. In the following steps, use a manual switch to provide a control signal from Simulink that rises or falls to trigger the event event in the Controller diagram.
- In the Simulink window, click-drag the Controller block down and to the right as shown.

- From the Simulink View menu, select Library browser.
- The Simulink Library Browser window opens with the Simulink node expanded.

- Under the Simulink node, select the Sources node.
- The right pane of the Simulink Library Browser window displays the block members of the Sources library.

- From the right pane of the Simulink Library Browser window, click-drag the Constant block to the left of the Stateflow block in the Simulink model.
- Add another Constant block to the left of the Controller as shown.

- Double-click the bottom Constant block.
- In the resulting Block Parameters dialog, in the Constant value field, enter a value of -1 and click OK to close the dialog.
- In the Simulink Library Browser window, select the Signal Routing node.
- From the contents of the Signal Routing library in the right pane of the Simulink Library Browser window, click-drag a Manual Switch block to the right of the Constant blocks as shown.

- Connect the Constant blocks to the poles of the Manual Switch as shown.

- Connect the output of the Manual Switch to the Controller block trigger port as shown.

- During testing, you change the pole position of the Manual Switch (from -1 to 1 or from 1 to -1). This sends a rising or falling signal to the Controller diagram that crosses zero. Because you defined the event
event in the Controller diagram with an Either trigger, either signal is recognized by the Controller diagram as the event event, and the diagram executes.
- Save the model (as
SFcontrol1).
| Adding a Trigger Event to the Stateflow Diagram | | Simulating a Stateflow Diagram |  |
© 1994-2005 The MathWorks, Inc.