Mealy machines are finite state machines in which transitions occur on clock edges. In Mealy charts, output is a function of input and state. At every time step, a Mealy chart wakes up, evaluates its input, and then transitions to a new configuration of active states, also called its next state. The chart computes its output as it transitions to the next state. Mealy semantics are not supported in standalone Stateflow® charts in MATLAB®.
To ensure that output is a function of input and state, Mealy state machines enforce these semantics:
Outputs do not depend on the next state.
The chart computes outputs only in transitions, not in states.
The chart wakes up periodically based on a system clock.
A chart provides one time base for input and clock (see Calculate Output and State by Using One Time Base).
To conform to the Mealy definition of a state machine, ensure that every time there is a change on the input port, the chart computes outputs.
You can compute outputs only in the condition actions of outer and inner transitions. A common modeling style for Mealy machines is to test inputs in conditions and compute outputs in the associated action.
You cannot use state actions or transition actions in Mealy charts. This restriction enforces Mealy semantics by:
Preventing the chart from computing output without considering changes on the input port.
Ensuring that output depends on the current state and not the next state.
In Mealy charts, these data restrictions apply:
Restrict Machine-Parented Data. Machine-parented data is data that you define for a Stateflow machine. The Stateflow machine is the highest level of the Stateflow hierarchy. When you define data at this level, every chart in the machine can read and modify the data. To ensure that Mealy charts do not access data that can be modified unpredictably outside the chart, do not use machine-parented data.
Do Not Define Data Store Memory. You cannot define data store memory (DSM) in Mealy charts because objects external to the chart can modify DSM. A Stateflow chart uses data store memory to share data with a Simulink® model. Data store memory acts as global data. In the Simulink hierarchy that contains the chart, other blocks and models can modify DSM. Mealy charts must not access data that can change unpredictably.
Limit the use of events in Mealy charts:
Use input events to trigger the chart.
Use event-based temporal logic to guard transitions.
The change in value of a temporal logic condition behaves like an event that the Mealy chart schedules internally. At each time step, the number of ticks before the temporal event executes depends only on the state of the chart. For more information, see Temporal Logic Operators.
In Mealy charts, the base event for temporal logic
operators must be a predefined event such as
tick (see Implicit Events Based on Data and States).
You cannot broadcast an event of any type.
You cannot use local events to guard transitions. Local events violate Mealy semantics because they are not deterministic and can occur while the chart computes its outputs.
You cannot use implicit events such as
You can use one time base for clock and input, as determined by the Simulink solver. The Simulink solver sets the clock rate to be fast enough to capture input changes. As a result, a Mealy chart commonly computes outputs and changes states in the same time step. For more information, see Compare Solvers (Simulink).