The counter in the sequential logic post always moved to + 1, so we built it with adders, and its output was the state itself. This time, let’s decide the next state and the outputs ourselves. Our example is the traffic light at an intersection where two roads meet. Cars going north–south and cars going east–west take turns, and the two directions must never be green at the same time.
The traffic light has four states. A drawing with states as circles and arrows for where the clock takes us is called a state diagram.
Current state: 0
Press Clock. The state goes around 0 → 1 → 2 → 3 → 0.
First, forget the clock and build a combinational circuit that takes the current state (S1·S0) and gives the next state and the lights to turn on. If a decoder spreads the current state onto one line, everything else is ORs.
Set S1·S0 to 00, 01, 10, and 11. In each state, the lights that turn on and the next state match the state diagram. In any state only one decoder output is 1, so the two directions can never be green at the same time.
Let’s draw this combinational circuit as a single “Traffic Light” box. Store the current state in two registers and feed it into the box, then send the next state the box gives (N1·N0) back into the registers, and the state moves on with every clock.
Change CLK to 1 and back to 0, over and over. The lights change in the same order as the state diagram above.
The traffic light is a sequential circuit made of a register that holds the state, a circuit that decides the next state, and a circuit that decides the outputs. A machine viewed in terms of its states and the transitions between them is also called a state machine. Vending machines, elevators, and washing machines, which work through a fixed sequence, are mostly state machines.
The traffic light ran through a fixed order with no outside input. How do we build a machine whose next state depends on what a person presses? In the next post, let’s build a door lock that opens only when buttons are pressed in the right order.
We extend the traffic light to 8 states (a 3-bit register and a 3-to-8 decoder) to show north–south green for 3 clocks, north–south yellow for 1, east–west green for 3, and east–west yellow for 1, in that order. If only two-input ORs are allowed, at least how many ORs does 'north–south red' need? Answer with a number.