Skip to content

Finite-State Machines

A Finite State Machine is a machine with a finite number of states ๐Ÿ’€. FSMs are a way of thinking about a process where:

  • There is a series of inputs.
  • We need to produce a series of outputs.
  • The state store some information.
  • The inputs can change the state and the outputs.

FSMs. come up all the time in programming and hardware design. They're great for controlling single multiple-step procedures.

Take for example, a ceiling fan. Its' states can be off, high, medium, and low. The input is the chain and the output is the motor. When you pull the chain, it changes state.

alt text

At any point in time, the input (chain) can be either pulled or not-pulled.

alt text

This is the state transition diagram.

We can represent this with... A TRUTH TABLE!!! (and store the states in a latch)

alt text

But... we need bits. so let off mean 00, high mean 01, med mean 10, low mean 11, 0 mean not pulling, and 1 means pulling.

alt text

Now, we can do two K-maps to find an optimal circuit because we need to split each bit up.

alt text

We will store the previous state in registers or in programming, use if's and switches.

For the outputs, our fan controller has to control the motor. We can make a table showing the output(s) for each state.

alt text

We can now represent our outputs in the state machine, make a table, get k-maps, and make circuits.

alt text

This is a sequential circuit since the state changes over time. But the state transition and output tables are just combinational. Here is a general organization of any Moore FSM circuit:

alt text

Creating a State Machine

  1. Understand the problem.
  2. Represent all possible states and transitions.
  3. Encode the states.
  4. Implement the machine.

Let's do another example. Let's take an espresso machine where each espresso costs 15ยข ๐Ÿ’€. The machine takes 5ยข and 10ยข. It also gives no change back.

alt text

Let's make a FSM and table.

alt text

Encode the states.

alt text

And do some K-map magic! Also, make the circuit.

alt text

alt text

alt text

Combine everything together.

alt text

Next Page โ†’