Products & Services Solutions Academia Support User Community Company

Learn more about Stateflow   

Implementing the Triggers

Build It Yourself or Use the Supplied Model

To implement the triggers yourself, work through the exercises in this section. Otherwise, open the supplied model Stage5Trigger to see how the triggers should appear in the chart.

Defining the CLOCK Event

To define the CLOCK event, follow these steps:

  1. Open the model Stage4Transitions — either the one you created in the previous exercises or the supplied model for stage 4 — and save it as Stage5Trigger in your local work folder.

  2. In Stage5Trigger, double-click the Air Controller block to open the Stateflow chart.

  3. In the Stateflow Editor, add an input event by selecting Event > Input from Simulink from the Add menu.

  4. In the Event properties dialog box, edit the following fields:

    PropertyWhat to Specify
    NameChange the name to CLOCK.
    TriggerSelect Either from the drop-down menu so the event can be triggered by either the rising edge or falling edge of a signal.

    Because the SWITCH event you created in Adding Events to Guard Transitions was assigned to trigger port 1, the CLOCK event is assigned to trigger port 2. Nevertheless, only one trigger port appears at the top of the Air Controller block to receive trigger signals. This means that each signal must be indexed into an array, as described in Connecting the Edge-Triggered Events to the Input Signals.

  5. Click OK to record the changes and close the dialog box.

  6. Save Stage5Trigger, but leave it open for the next exercise.

Connecting the Edge-Triggered Events to the Input Signals

You need to connect the edge-triggered events to the Simulink input signals in a way that

In Stage5Trigger, notice that the two input signals SWITCH and CLOCK feed into a Mux block where they are joined in an array to a single output. SWITCH is a pulse signal and CLOCK is a square wave. When you connect the Mux to the trigger port, the index of the signals in the array are associated with the like-numbered ports. Therefore, the SWITCH signal at the top input port of the Mux triggers the event SWITCH on trigger port 1. Likewise, the CLOCK signal at the second input port of the Mux triggers the event CLOCK on trigger port 2.

To connect the Mux to the trigger port, follow these steps:

  1. Click the Mux block, hold down the Ctrl key, and click the Air Controller block.

    The output signal of the Mux block connects to the input trigger port of the Stateflow block. Your chart should look like this:

  2. Save Stage5Trigger.

Where to go next.  Now you are ready to begin phase 6 of the workflow: Simulating the Chart.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS