Skip to Main Content Skip to Search
Product Documentation

Debugging Mealy and Moore Charts

At compile time, informative diagnostic messages appear to help you:

For example, recall the Mealy vending machine chart described in Example: Mealy Vending Machine.

If you change the chart type to Moore and rebuild, you get the following diagnostic message:

Stateflow Moore chart cannot have condition or transition actions.

This indicates that you cannot define actions on transitions. Without actions, you cannot compute outputs on transitions in Moore charts (see Do Not Use Actions on Transitions). According to Moore semantics, you must instead compute outputs in state actions (see Design Rules for Moore Charts).

In the Mealy chart, each condition action computes output (whether or not soda is released) based on input (the coin received). Each state represents one of the three possible coin inputs: nickel, dime, or no coin. The Mealy chart computes the output as it transitions to the next state. When you move this logic out of transitions and into state actions in the Moore chart, you need more states. The reason is that in the Moore chart, each state must represent not only coins received, but also the soda release condition. The Moore chart must compute output according to the active state before considering input. As a result, there will be a delay in releasing soda, even if the machine receives enough money to cover the cost.

The equivalent vending machine, designed as a Moore chart, is as follows.

The semantics of the two charts differ as follows:

Mealy Vending MachineMoore Vending Machine
Uses 3 statesUses 5 states
Computes outputs in condition actionsComputes outputs in state actions
Updates output based on inputUpdates output before evaluating input, requiring an extra time step to produce the soda

For this vending machine, Mealy is a better modeling paradigm because there is no delay in releasing soda once sufficient coins are received. By contrast, the Moore vending machine requires an extra time step to pass before producing soda. Since the Moore vending machine accepts a nickel, a dime, or no coin in a given time step, it is possible that the soda will be produced in a time step in which a coin is accepted toward the next purchase. In this situation, the delivery of a soda may appear to be in response to this coin, but actually occurs because the vending machine received the purchase price in previous time steps.

  


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