| Contents | Index |
| On this page… |
|---|
Using Edge Triggers to Activate a Stateflow Chart |
An input event occurs outside a chart but is visible only in that chart. This type of event allows other Simulink blocks, including other Stateflow charts, to notify a specific chart of events that occur outside it.
You can activate a Stateflow chart via a change in control signal (an edge-triggered input event) or a function call from a Simulink block (a function-call input event). The sections that follow describe when and how to use each type of input event.
Note You cannot mix edge-triggered and function-call input events in a Stateflow chart. If you try to mix these input events, an error message appears during simulation. |
An edge-triggered input event causes a Stateflow chart to execute during the current time step of simulation. This type of input event works only when a change in control signal acts as a trigger.
Use an edge-triggered input event to activate a chart when your model requires chart execution at regular (or periodic) intervals.
To define an edge-triggered input event:
Add an event to the Stateflow chart, as described in How to Define Events.
Set the Scope property for the event to Input from Simulink.
A single trigger port appears at the top of the Stateflow block in the Simulink model.
Set the Trigger property to one of these edge triggers.
In all cases, the signal must cross 0 to be a valid edge trigger. For example, a signal that changes from -1 to 1 is a valid rising edge, but a signal that changes from 1 to 2 is not valid.
The demo model sf_loop_scheduler shows how to use an edge-triggered input event to activate a Stateflow chart at regular intervals. For information on running this model and how it works, see Scheduling One Subsystem in a Single Time Step.
A function-call input event causes a Stateflow chart to execute during the current time step of simulation.
Note When you use this type of input event, you must also define a function-call output event for the block that calls the Stateflow chart. |
Use a function-call input event to activate a chart when your model requires access to output data from the chart in the same time step as the function call.
To define a function-call input event:
Add an event to the Stateflow chart, as described in How to Define Events.
Set the Scope property for the event to Input from Simulink.
A single trigger port appears at the top of the Stateflow block in the Simulink model.
The demo model sf_loop_scheduler shows how to use a function-call input event to activate a Stateflow chart. For information on running this model and how it works, see Scheduling One Subsystem in a Single Time Step.
When you define one or more input events for a chart, a single trigger port to the chart block appears. External Simulink blocks can trigger the input events via a signal or vector of signals connected to the trigger port. The Port property of an input event associates the event with a specific element of a control signal vector that connects to the trigger port (see Port).
The number of the port that you assign to the input event acts as an index into the control signal vector. For example, the first element of the signal vector triggers the input event assigned to input port 1, the fourth element triggers the input event assigned to input port 4, and so on. You assign port numbers in the order in which you add the events. However, you can change these assignments by setting the Port property of an event to the index of the signal that you use to trigger the event.
For multiple input events to a trigger port, the data types of all signals must be identical. If you use signals of different data types as input events, an error message appears when you try to simulate your model.
For example, you can mux two input signals of type double to use as input events to a chart.

However, you cannot mux two input signals of different data types, such as boolean and double.

At any given time step, input events are checked in ascending order based on their port numbers. The chart awakens once per valid event. For edge-triggered input events, multiple edges can occur in the same time step, which wake the chart more than once in that time step. In this situation, events occur (and wake the chart) in an ascending order based on their port numbers.
For function-call input events, only one trigger event exists. The caller of the event explicitly calls and executes the chart. Only one function call can be valid in a single time step.
![]() | Setting Properties for an Event | Controlling States When Function-Call Inputs Reenable Charts | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |