Clearly communicate complex software design in simplified graphic form
A state diagram or a state transition diagram is a graphical representation of a state machine‘s finite number of states, state transitions, and rules that govern the transitions. State diagrams are used as high-level starting points for complex software design because their simplicity allows clear communication of different modes of operation.
In a state diagram:
- Boxes represent states or different modes of operation
- Arrows indicate the transition from one state to another
- Text associated with each arrow represents the rule that governs the transition
A state machine’s outputs or actions are descriptions of the behavior of each system state. Two types of state machines—Moore and Mealy—are classified by where the machine output is defined.
Moore Implementation of a State Diagram
In this type of state machine, the outputs depend only on the state of the system and are defined as state actions. Regardless of how you enter a state, the state action remains the same. For example, in the state diagram in Figure 2, the output from Heating
remains the same regardless of whether the transition occurs from the Idling
or OFF
state.
Mealy Implementation of a State Diagram
In this type of state machine, the outputs depend not only on the state of the system, but also on inputs to the system. As shown in the state diagram in Figure 3, outputs in a Mealy implementation are defined at the transitions.
With the Mealy implementation, state diagrams can be reorganized and simplified with the addition of loops to update machine outputs. This is increasingly beneficial with more complex designs.
Both Mealy and Moore machines are popular for their simplicity and clarity, and the two styles are often mixed within the same state diagram.
State Charts: Enhanced State Diagrams
The basic building blocks of state diagrams are not enough for a single diagram to represent complex logical systems. You will need additional capabilities to capture intricate design details efficiently. State charts, also known as Harel charts, add capabilities including hierarchy, parallelism or orthogonality, and event broadcasting.
The hierarchy capability allows further design compartmentalization and can reduce the number of transition lines required between states. Parent states can be introduced to create hierarchy within state machines. For example, in the state chart in Figure 5, the parent state of Baking
includes the substates of Heating
and Idle
and the associated state diagram.
Parallelism or orthogonality capabilities allow for a single state chart to include multiple states operating simultaneously. For example, in the state chart in Figure 6, Oven
and Oven_Light
can be thought of as two independent state machines operating simultaneously. The chart represents the overall system in a single graphic containing two parallel state machines.
Event broadcasting capabilities expand the functionality of the system by allowing information exchange between two independent states or state machines. In the previous case, the two state machines were independent, as the oven light’s operation did not depend on the oven’s heating system. With event broadcasting, a feature that turns off the oven light when baking is complete can be added using a simple command within the Oven
state’s logic, as highlighted in the state chart in Figure 7.
State charts with hierarchy, parallelism, and broadcasting capabilities help to represent complex system functionalities without cluttered state diagrams.
State Diagrams and State Charts with Stateflow
Stateflow® is a graphical programming environment based on finite state machines. Using Stateflow, you can start from simple state diagrams and build out state charts to model complex logic in dynamic systems, including automatic transmissions, robotic systems, mobile phones, and more. Applications of this complex logic include:
If you need the logic created to control a software component, you can use the automatic code generation capabilities from Simulink to convert the state chart into C, HDL, or PLC code for deployment.
For more information on modeling state diagrams, including these advanced techniques, see Stateflow and Simulink. The example, Modeling a Security System, demonstrates hierarchy, parallelism, and event broadcasting in Stateflow.
Examples and How To
Software Reference
See also: control logic, state machine, control systems, embedded systems