Stateflow User's Guide Previous page   Next Page

Adding Multiple Trigger Events to a Stateflow Chart

In Adding Event Triggers to Transitions, you use the names of the events to specify event triggers for transitions that execute only with the occurrence of one of these events. To use these event triggers, you must also define the events that enable them for the Controller Stateflow diagram.

Define the two events on_switch and off_switch for the Controller Stateflow diagram with the following steps:

  1. In the Stateflow diagram editor, from the Add menu, select Event.
  2. In the resulting submenu, select Input from Simulink.
  1. The Event dialog for a new event, event1, appears.

    Notice that the middle Port field is set to a value of 2.

  1. In the Name field, enter off_switch.
  2. In the Trigger field, select Falling.
  3. Click OK to apply the changes and close the Event dialog.
  4. Repeat step 1 through step 5 to add the event on_switch with a scope of Input from Simulink, and a Rising trigger.
  1. You have now defined the events on_switch and off_switch in the Controller Stateflow diagram. The event off_switch has a Falling trigger and the event on_switch has a Rising trigger. The event off_switch occurs only when the control signal attached to the Stateflow block trigger port falls in value as it passes through zero. The event on_switch occurs only when that control signal rises as it passes through zero.

  1. In the Stateflow diagram editor, from the Tools menu, select Explore.
  1. The Model Explorer window appears, as shown.

    Model Explorer is a tool that lists nongraphical objects for all Simulink objects, including Stateflow objects. Events are nongraphical objects. Model Explorer is the only place to change or delete events.

    The left Model Hierarchy pane lists the Stateflow objects for the model SFcontrol2, which includes the model itself. To see some of these objects, you need to expand the Controller diagram that contains them. The right Contents pane lists the nongraphical objects owned by the highlighted object in the Model Hierarchy pane.

    The Controller diagram is highlighted in the Model Hierarchy pane and the Contents pane shows the events that you have added to it. These include the off_switch and on_switch events and the event event you added in the previous section. Notice that these events are indexed in the Port column in the order that they were added: (1) event, (2) off_switch, and (3) on_switch.

  1. In the Contents pane, click the row for the event event to highlight it.
  2. Press the Delete key.
  1. The row for the event event disappears and the event is deleted. Notice that the indexing for the remaining events is automatically adjusted from three to two elements: (1) off_switch, and (2) on_switch.


Previous page  Adding Event Triggers to Transitions Sending Multiple Trigger Events to a Stateflow Chart Next page

© 1994-2005 The MathWorks, Inc.