Lecture 10 - State machines
Goals
- Learn how to build sequential circuits
Last time we looked at how we could take our basic memory units and make addressable memory
Today we will look at how we can incorporate memory with other circuits to get interesting behavior
The counter
We can exploit the repetitive nature of counting in binary to build a simple binary counter

Traffic Light
Imagine we have a four way intersection and we want to design a traffic light controller.
We are going to ignore being responsive to traffic – we are just going to cycle through the light states
We can simplify this to just two lights as well and assume that both the north and south traffic get the same lights and the east and west traffic get the same lights
The cycle will look something like this:
| step | NS lights | EW lights |
|---|---|---|
| 0 | red | red |
| 1 | green | red |
| 2 | yellow | red |
| 3 | red | red |
| 4 | red | green |
| 5 | red | yellow |
We could go through the same process we went through before, but we can also realize that there is no choice here, so our state registers can just be a counter
Then it is just a matter of figuring out when each light is on
| S2 | S1 | S0 | NS red | NS yellow | NS green | EW red | EW yellow | EW green |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
NS red = S2 + S1 XNOR S0
NS yellow = S2'S1S0'
NS green = S2'S1'S0
EW red = S2'
EW yellow = S2S1'S0
EW green = S2S1'S0'

Soda machine
imagine a simple soda machine it sells 15 cent sodas and only accepts nickels and dimes we will represent the nickels and dimes using a single variable D/N’, which inserts a dime when high and a nickel when low the machine will have one output, which goes high when it has enough change to dispense a soda we want to think about the various combinations of change that you could insert into the machine to get your drink we can draw a state diagram to help us reason about it

We have a state for each quantity of money in the machine
The dark outline shows the states where we are asserting the soda output indicating that we are dispensing a soda
In the $0.20 state we are dispensing the soda, and there is a $0.05 credit in the machine
Since each arc represents adding a coin to the machine, we never actually return to the start state
To be continued…
Mechanical level
vocabulary
Skills