An input event occurs outside a Stateflow® chart but is visible only in that chart. This type of event enables other Simulink® blocks, including other Stateflow charts, to notify a specific chart of events that occur outside it. To define an input event:
Add an event to the Stateflow chart, as described in Define Events in a Chart.
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.
An input event can activate a Stateflow chart through a change in a control signal (an edge trigger) or a function call from a Simulink block.
To specify an edge-triggered input event, set the Trigger property to one of these options:
Rising
Falling
Either
To specify a function-call input event, set the Trigger property to
Function call
.
You cannot mix edge-triggered and function-call input events in the same Stateflow chart. Mixing these input events results in an error during parsing and simulation.
For more information, see Synchronize Model Components by Broadcasting Events.
An edge-triggered input event causes a Stateflow chart to execute during the current time step of simulation. With this type of input event, a change in a control signal acts as a trigger.
In all cases, the value of the control signal must cross zero to be a valid edge trigger. For example, a signal that changes from -1 to 1 is a valid rising edge trigger. A signal that changes from 1 to 2 is not a valid rising edge trigger.
Use an edge-triggered input event to activate a chart when your model requires regular or periodic chart execution. For example, in this model, an edge-triggered input event activates the Edge to Function chart at regular intervals. For more information, see Schedule a Subsystem Multiple Times in a Single Step.
At any given time step, input events are checked in ascending order based on their port numbers. The chart awakens once for each valid event. For edge-triggered input events, multiple edges can occur in the same time step, waking the chart more than once in that time step. In this situation, the events wake the chart in ascending order based on their port numbers.
A function-call input event causes a Stateflow chart to execute during the current time step of simulation. With 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. For example, in this model, a function-call input event activates the Looping Scheduler chart. For more information, see Schedule a Subsystem Multiple Times in a Single Step.
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 is valid in a single time step.
When you define one or more input events in a chart, a single trigger port appears on the top side of the chart block. Multiple external Simulink blocks can trigger the input events through a vector of signals connected to the trigger port. The Port property of an input event specifies the index into the control signal vector that connects to the trigger port.
By default, Port values appear in the order that you add input events. You can change these assignments by modifying the Port property of the events. When you change the Port property for an input event, the Port values for the remaining input events automatically renumber.
For multiple input events to a trigger port, all signals must have the same data
type. Using signals of different data types as input events results in an error
during simulation. For example, you can mux two input signals of type
double
to use as input events to a chart.
You cannot mux two input signals of different data types, such as
boolean
and double
.