yeolyi.comSeongyeol's CS

Sequence Door Lock

The traffic light ran through a fixed order with no outside input. But many machines must behave differently depending on what a person presses. Let’s build a door lock that opens only when the password 1, 0, 1 is pressed in order on a single button (X). Each time the clock comes, it reads X once.

State diagram

What the door lock must remember is how many digits of the password have been pressed correctly so far. There are four states.

0101010, 10123
Input so far
Nothing yet

Current state: 0
Locked

Press 0 and 1. Pressing 1, 0, 1 in order reaches state 3 and opens the lock.

If another 1 comes in state 1, the lock stays in state 1 instead of going back to the start, because the 1 just pressed may be the first digit of the password.

From state diagram to circuit

As with the traffic light, forget the clock and build the combinational circuit first. This time, feeding in the current state (S1·S0) and the input X gives the next state and Open. Since the arrows carry inputs, we make “in this state and X has this value” with ANDs and combine them with ORs.

Set S1·S0 to 01 (state 1) and change X to 0 and 1. The next state splits into 10 (state 2) and 01 (state 1), just like the arrows in the state diagram.

Adding the clock

Draw the combinational circuit as a single “Door Lock” box, then attach two registers and a clock.

  1. Change X to 1, 0, 0 in turn, changing CLK to 1 and back to 0 after each one. The second 0 sends it back to the start.
  2. Then feed X = 1, 0, 1. Open becomes 1 on the last clock.

Wrapping up

The traffic light and the sequence door lock are both state machines made only of remembering circuits and gates. But for each machine, we drew up a state table and wired a new circuit. Even changing the password means redesigning the circuit. Is there a way to avoid redesigning the circuit every time the job changes? Let’s find out in the next post.

Challenge

We feed X = 0, 1, 1, 0, 1 into the post's door lock (five clocks). On which clock does Open first become 1? Answer with a number.