Skip to Main Content Skip to Search
Product Documentation

Overview of Mealy and Moore Machines

Semantics of Mealy and Moore Machines

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
uRepresents inputs

In this context, Mealy and Moore machines each have well-defined semantics.

Type of MachineSemanticsApplications
MealyOutput is a function of inputs and state:

Clocked synchronous machines where state transitions occur on clock edges
MooreOutput 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.

Running a Demo of Mealy and Moore Machines

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:

  1. At the MATLAB prompt, type:

    demo simulink stateflow

    The Help browser shows a list of demos you can access.

  2. Click the demo titled Sequence Recognition Using Mealy and Moore Charts.

The Default State Machine Type

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.

What Is State?

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.

Availability of Output

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 InitializationMealy Computes Outputs at:Moore Computes Outputs at:
Enabledt = 0t = 1
Disabledt = 1t = 2

Advantages of Mealy and Moore Charts Over Classic Stateflow Charts

Mealy and Moore charts offer the following advantages over Classic Stateflow charts:

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS