Documentation

Activate a Stateflow Chart Using Input Events

What Is an Input Event?

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.

Activate a Stateflow Chart Using Edge Triggers

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.

When to Use an Edge-Triggered Input Event

Use an edge-triggered input event to activate a chart when your model requires chart execution at regular (or periodic) intervals.

How to Define an Edge-Triggered Input Event

To define an edge-triggered input event:

  1. Add an event to the Stateflow chart, as described in Define Events.

    Note

    You must add an input event to the chart and not to one of its objects.

  2. 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.

  3. Set the Trigger property to one of these edge triggers.

    Edge Trigger Type

    Description

    Rising

    Rising edge trigger, where the control signal changes from either zero or a negative value to a positive value.

    Falling

    Falling edge trigger, where the control signal changes from a positive value to either zero or a negative value.

    Either

    Either rising or falling edge trigger.

    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.

Example of Using an Edge-Triggered Input Event

The 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 Schedule One Subsystem in a Single Step.

Activate a Stateflow Chart Using Function Calls

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.

When to Use a Function-Call Input Event

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.

How to Define a Function-Call Input Event

To define a function-call input event:

  1. Add an event to the Stateflow chart, as described in Define Events.

    Note

    You must add an input event to the chart and not to one of its objects.

  2. 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.

  3. Set the Trigger property to Function call.

Example of Using a Function-Call Input Event

The 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 Schedule One Subsystem in a Single Step.

Association of Input Events with Control Signals

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.

Data Types Allowed for Input Events

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.

Behavior of Edge-Triggered Input Events

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.

Behavior of Function-Call Input Events

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.

Was this topic helpful?