## represent event-driven systems in simplified graphic form

a state machine (or finite state machine) is a representation of an event-driven, reactive system that transitions from one state to another if the condition that controls the change is met. state machines were conventionally used to describe computing systems, but they have been expanded to model complex logic in dynamic systems such as aircraft, automobiles, robots, and mobile phones.

examples of operations containing complex logic include:

- scheduling a sequence of tasks or steps for a system
- defining fault detection, isolation, and recovery logic
- supervising how to switch between different modes of operation

there are many ways of expressing a state machine, although a graphical approach is most common. a state transition diagram, also known as a state diagram, is a diagram showing a finite number of states with rules that govern when transitions occur from one state to another.

for example, you can use a state diagram to represent a simplified version of a car’s automatic gear transmission. the state machine shown below has four operating states labeled `first`

, `second`

, `third`

, and `fourth`

. like the gears they represent, these states are exclusive, so only one state is active at a time. this state machine monitors the speed of the car and shifts to a different gear when the speed crosses the fixed threshold for the gear in operation.

*figure 1. state diagram of an automatic gear transmission system modeled using stateflow.*

there are two main types of state diagrams:

- mealy – state machine outputs depend not only on the states but also on inputs to the system, represented by defining machine outputs in the transitions as shown in figure 2
- moore – state machine outputs depend only on the state of the system, represented by defining machine outputs on the states as shown in figure 3

for more information on these semantics, see .

to create state machines that emulate a complex software component, the basic building blocks of state diagrams are not enough. the following additional capabilities are required to capture intricate details of the system efficiently:

**hierarchy**– introduces parent state(s) and further structures the design**parallelism or orthogonality**– allows for a single diagram to include multiple states operating simultaneously**event broadcasting**– allows for information exchange between two independent states or state machines

when these capabilities are coupled with state transition diagrams, the representations are called harel statecharts, or simply state charts.

*figure 4. *

for more information on these capabilities, see state diagram and state chart.

**state machines 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.

you can use matlab^{®} to execute standalone state charts as matlab objects, or simulink^{®} to simulate state charts as simulink blocks.

### examples and how to

### software reference

*see also:
control logic,
state diagram,
control systems,
embedded systems
*