Skip to Main Content Skip to Search
Product Documentation

Design Considerations for Mealy Charts

Mealy Semantics

To ensure that output is a function of input and state, Mealy state machines enforce the following semantics:

Design Rules for Mealy Charts

To conform to the Mealy definition of a state machine, you must ensure that a Mealy chart computes outputs every time there is a change on the input port. As a result, you must follow a set of design rules for Mealy charts.

Compute Outputs in Condition Actions Only

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.

Do Not Use State Actions or Transition Actions

You cannot use state actions or transition actions in Mealy charts. This restriction enforces Mealy semantics by:

Restrict Use of Data

You can define inputs, outputs, local data, parameters, and constants in Mealy charts, but other data restrictions apply:

Restrict Machine-Parented Data to Constants and Parameters.   Machine-parented data is data that you define for a Stateflow machine, which is the collection of all Stateflow blocks in a Simulink model. 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, you can define only constants and parameters at the machine level.

Do Not Define Data Store Memory.  You cannot define data store memory (DSM) in Mealy charts because DSM objects can be modified by objects external to the chart. A Stateflow chart uses data store memory to share data with a Simulink model. Data store memory acts as global data that can be modified by other blocks and models in the Simulink hierarchy that contains the chart. Mealy charts should not access data that can change unpredictably.

Restrict Use of Events

Limit the use of events in Mealy charts as follows:

Do:Do Not:

Use input events to trigger the chart

Broadcast any type of event

Use event-based temporal logic to guard transitions

You can use event-based temporal logic in Mealy charts because it behaves synchronously (see Operators for Event-Based Temporal Logic). Think of the change in value of a temporal logic condition as an event that the chart schedules internally. Therefore, at each time step, the chart retains its notion of state because it knows how many ticks remain before the temporal event executes.

    Note   In Mealy charts, the base event for temporal logic operators must be a predefined event such as tick or wakeup (see Keywords for Implicit Events).

Use local events to guard transitions

You cannot use local events in Mealy charts because they are not deterministic. These events can occur while the chart computes outputs and, therefore, violate Mealy semantics that require charts to compute outputs whenever input changes.

Calculate Output and State Using One Time Base

You can use one time base for clock and input, as determined by the Simulink solver (see Solvers). 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.

Example: Mealy Vending Machine

The following chart uses Mealy semantics to model a vending machine.

Opening the Model

To open the model of a Mealy vending machine, click sf_mealy_vending_machine or type sf_mealy_vending_machine at the MATLAB command prompt.

Logic of the Mealy Vending Machine

In this example, the vending machine requires 15 cents to release a can of soda. The purchaser can insert a nickel or a dime, one at a time, to purchase the soda. The chart behaves like a Mealy machine because its output soda depends on both the input coin and current state, as follows:

When initial state got_0 is active.  No coin has been received or no coins are left.

In active state got_nickel.  A nickel was received.

In active state got_dime.  A dime was received.

Design Rules in Mealy Vending Machine

This example of a Mealy vending machine illustrates the following Mealy design rules:

  


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