Moore machines are finite state machines in which output is modified at clock edges. In Moore charts, output is a function of the current state only. At every time step, a Moore chart wakes up, computes its output, and then evaluates its input to reconfigure itself for the next time step. For example, after evaluating its input, the chart can transition to a new configuration of active states. The chart computes its output before evaluating its input and updating its state. Moore semantics are not supported in standalone Stateflow® charts in MATLAB®.
To ensure that output is a function only of the current state, Moore state machines enforce these semantics:
Outputs do not depend on inputs.
Outputs do not depend on previous outputs.
Outputs do not depend on temporal logic.
To conform to the Moore definition of a state machine, ensure that every time that a Moore chart wakes up, it computes outputs from the current set of active states without regard to inputs.
To ensure that outputs depend solely on the current state, you can compute outputs in state actions, subject to these restrictions:
Combine Actions. In Moore charts, you can include only one action per state. The action can consist of multiple command statements. Stateflow evaluates states in Moore charts from the top level down. Active states in Moore charts execute the state action before evaluating the transitions. Therefore, outputs are computed at each time step whether an outer transition is valid or not.
Do Not Label State Actions. Do
not label state actions in Moore charts with any keywords, such as
exit. By default, Moore charts execute the
actions in the active states before evaluating inputs and updating
Transitions in Moore charts can contain condition and transition actions if
these actions do not introduce a dependency between output values and input
values. For example, in this chart, each transition tests the input
u in a condition and modifies the output
y in a condition action. Because the output value depends
on the value of the input, this construct violates Moore semantics and triggers
In Moore charts, outputs cannot depend on inputs. Using an input to contribute directly or indirectly to the computation of an output triggers an error.
In Moore 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 Moore 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 Moore charts because objects external to the chart can modify DSM objects. 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. Moore charts must not access data that can change unpredictably.
coder.extrinsicto Call Extrinsic Functions
You cannot call extrinsic functions with
Moore charts because it is not possible to enforce that the outputs of extrinsic
functions depend only on the current state. Calling an extrinsic function with
coder.extrinsic in a Moore chart triggers an
You cannot call custom code functions in Moore charts because it is not possible to enforce that the outputs of custom code functions depend only on the current state. Calling a custom code function in a Moore chart triggers an error.
You cannot use Simulink functions in Moore charts. This restriction prevents violations of Moore semantics during chart execution.
You cannot export functions in a Moore chart.
Moore chart semantics require inlining.
You cannot use super step semantics in a Moore chart.
You cannot use messages in a Moore chart.
Limit the use of events in Moore charts:
Use only one input event 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 Moore 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 Temporal Logic Operators.
In Moore charts, the base event for temporal logic
operators must be a predefined event such as
tick (see Implicit Events Based on Data and States).
You cannot broadcast an event of any type.
You cannot use local events to guard transitions. Local events violate Moore semantics because they are not deterministic and can occur while the chart computes its outputs.
You cannot use implicit events such as
In Moore charts, you cannot set the update method to
Continuous. For modeling systems with continuous time in
Stateflow, use Classic or Mealy charts.