This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Design Considerations for Mealy Charts

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 supported only in Stateflow® charts in Simulink® models.

Mealy Semantics

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.

    Note

    A chart provides one time base for input and clock (see Calculate Output and State by Using One Time Base).

Design Rules for Mealy Charts

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.

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:

  • 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.

Restrict Data Scope

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.

Restrict Use of Events

Limit the use of events in Mealy charts:

  • Valid Uses:

    • 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 Operators for Event-Based Temporal Logic.

      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).

  • Invalid Uses:

    • 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 chg(data_name), en(state_name), or ex(state_name).

Calculate Output and State by Using One Time Base

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 Solvers (Simulink).

Related Topics