| Contents | Index |
| On this page… |
|---|
Semantics of Mealy and Moore Machines Running a Demo of Mealy and Moore Machines The Default State Machine Type Advantages of Mealy and Moore Charts Over Classic Stateflow Charts |
Mealy and Moore are often considered the basic, industry-standard paradigms for modeling finite-state machines. Generally in state machine models, the next state is a function of the current state and its inputs, as follows:
![]()
In this equation:
| X(n) | Represents the state at time step n |
| X(n+1) | Represents the state at the next time step n+1 |
| u | Represents inputs |
In this context, Mealy and Moore machines each have well-defined semantics.
| Type of Machine | Semantics | Applications |
|---|---|---|
| Mealy | Output is a function of inputs and state:
| Clocked synchronous machines where state transitions occur on clock edges |
| Moore | Output is a function only of state:
| Clocked synchronous machines where outputs are modified at clock edges |
You can create charts that implement pure Mealy or Moore semantics as a subset of Stateflow chart semantics (see Creating Mealy and Moore Charts). Mealy and Moore charts can be used in simulation and code generation of C and HDL.
Note To generate HDL code from Stateflow charts, you must use HDL Coder™ software, which is available separately. |
Stateflow software ships with a model that shows how to use Mealy and Moore machines for sequence recognition in signal processing. To run the demo:
At the MATLAB prompt, type:
demo simulink stateflow
The Help browser shows a list of demos you can access.
Click the demo titled Sequence Recognition Using Mealy and Moore Charts.
When you create a Stateflow chart, the default type is a hybrid state machine model that combines the semantics of Mealy and Moore charts with the extended Stateflow chart semantics (see Stateflow Chart Semantics). This default chart type is called Classic.
State is a combination of local data and chart activity. Therefore, computing state means updating local data and making transitions from a currently active state to a new state. State persists from one time step to another. In a Classic Stateflow chart, output behaves like state because output values persist between time steps. However, unlike state, output is available outside the chart through output ports. By contrast, output in Mealy and Moore charts does not persist and instead must be computed in each time step.
Mealy machines compute output on transitions, while Moore machines compute outputs in states. Therefore, Mealy charts can compute output earlier than Moore charts — that is, at the time the chart's default path executes. If you enable the chart property Execute (enter) Chart At Initialization, this computation occurs at t = 0 (first time step); otherwise, it occurs at t = 1 (next time step). By contrast, Moore machines can compute outputs only after the default path executes. Until then, outputs take the default values.
The following summary describes the earliest time at which Mealy and Moore charts can compute outputs:
| Execute (enter) Chart at Initialization | Mealy Computes Outputs at: | Moore Computes Outputs at: |
|---|---|---|
| Enabled | t = 0 | t = 1 |
| Disabled | t = 1 | t = 2 |
Mealy and Moore charts offer the following advantages over Classic Stateflow charts:
You can verify the Mealy and Moore charts you create to ensure that they conform to their formal definitions and semantic rules. Error messages appear at compile time (not at design time).
Moore charts provide a more efficient implementation than Classic charts, both for C and HDL targets.
![]() | Building Mealy and Moore Charts | Creating Mealy and Moore 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 |