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.
- scheduling a sequence of tasks or steps for a system
- defining , isolation, and recovery logic
- supervising how to switch between different modes of operation
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.
examples and how to
software reference
see also: control logic, state machine, control systems, embedded systems