In phase 5 of this workflow, you decide how to trigger the chart.
To implement the triggers yourself, work through the exercises in this section. Otherwise, open the supplied model to see how the triggers should appear in the chart. Enter this command at the MATLAB® prompt:
addpath(fullfile(docroot, 'toolbox', 'stateflow', 'gs', 'examples')) Stage5Trigger
A Simulink® model can wake up a Stateflow® chart by
Sampling the chart at a specified or inherited rate
Using a signal as a trigger
Using one Stateflow chart to drive the activity of another
A signal trigger works best for the Air Controller chart because it needs to
monitor the temperature of the physical plant at regular intervals. To meet this
requirement, you will use a periodic signal to trigger the chart. The source is a
square wave signal called
CLOCK, provided by a Signal Builder
block in the Simulink model, described in How the Stateflow Chart Works with the Simulink Model. To harness the
signal, you will set up an edge trigger event that wakes the chart at the rising or
falling edge of
The rationale for using an edge trigger in this case is that it uses the regularity and frequency of the signal to wake up the chart. When using edge triggers, keep in mind that there can be a delay from the time the trigger occurs to the time the chart begins executing. This is because an edge trigger causes the chart to execute at the beginning of the next simulation time step, regardless of when the edge trigger actually occurred during the previous time step. The Air Controller can tolerate this delay, as long as the edge occurs frequently enough. (For more information about triggering Stateflow charts, see Implement Interfaces to Simulink Models in the Stateflow User's Guide.)
Recall that you already defined one edge-triggered event,
SWITCH, to guard the transitions between
PowerOn. You will now define
a second edge-triggered event,
CLOCK, to wake up the
To define the
CLOCK event, follow these steps:
Open the model
Stage4Transitions — either the
one you created in the previous exercises or the supplied model for stage
To open the supplied model, enter the following command at the MATLAB prompt:
addpath(fullfile(docroot, 'toolbox', 'stateflow', 'gs', 'examples')) Stage4Transitions
Save the model as
Stage5Trigger in your local work
Stage5Trigger, double-click the Air Controller block
to open the Stateflow chart.
From the Stateflow Editor, in the Modeling tab, under Design Data, click Event Input.
In the Event properties dialog box, edit the following fields:
|Property||What to Specify|
|Name||Change the name to |
SWITCH event you created in Adding Events to Guard Transitions was assigned to trigger port
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.
Click OK to record the changes and close the dialog box.
Stage5Trigger, but leave it open for the next
You need to connect the edge-triggered events to the Simulink input signals in a way that
Associates each event with the correct signal
Indexes each signal into an array that can be received by the Air Controller trigger port
Stage5Trigger, notice that the two input signals
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:
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 model should look like this:
Where to go next. Now you are ready to simulate your chart. See Setting Simulation Parameters and Breakpoints.