CS281: Introduction to Systems
Lab: Finite State Machines -- Garage Opener
- Purpose
- Learn to specify and implement a more complex finite state machine.
- Method
- Design and build a simulation of a garage door controller.
Represent a finite state machine using a state diagram, truth tables, and logic
circuits.
- Files to Use
-
- What to Hand In
-
- state transition diagram
- truth tables
- completed circuit
garage.circ
- extra credit: demonstrate breadboard circuit
Specifications
Working in teams of two, you are to design a controller for a garage door opener with the
following specifications.
Inputs
- top (T)
- When the door is at the top, this input is true.
- bottom (B)
- When the door is at the bottom, this input is true.
- eye (E)
- There is a light beam across the doorway with an electric eye.
When the electric eye detects the light beam, this input is true. If
the light beam is blocked, such as by a small child standing in
the doorway, then this input is false.
- go (G)
- When the button on the remote control is pressed, this input
becomes true. When the button on the remote control is released, this
input becomes false.
Outputs
- up (U)
- When this output is true, the motor moves the door upward to open
it.
- down (D)
- When this output is true, the motor moves the door downward to
close it.
If both U and D are false, then the motor will be stopped. The U
and D outputs should never both be true at the same time to avoid
damaging the motor.
Operation
The input from the button on the remote control (G) will be
processed by a one-shot circuit (given to you in the provided Logisim circuit), which happens to be a finite state
machine. This circuit prevents the G input from staying true for more
than one clock cycle, even if the button is held down for a long
period of time.
- Assume that the clock rate is 10 Hz so that the controller will
respond to changes in the inputs within one tenth of a second, quickly
enough to avoid causing injury or damaging the motor.
- If the door is closed, pressing the button (G = 1) causes the
door to begin opening.
- If the door reaches the top (T = 1) while opening,
the motor will stop.
- If the door is open, pressing the button (G = 1) causes the
door to begin closing.
- If the door reaches the bottom (B = 1) while closing,
the motor will stop.
- If the electric eye detects that the light beam has been
interrupted (E = 0) while the door is closing, the door will reverse
direction and begin opening. This is an important safety feature, so
the electric eye should take priority over the other inputs in this
situation.
- If the light beam is interrupted (E = 0) while the door is
opening then the door continues opening.
- Pressing the button (G = 1) while the door is opening causes the
door to stop. Pressing the button again (G = 1) causes the door to
begin closing.
- Pressing the button (G = 1) while the door is closing causes the
door to reverse direction and immediately begin opening.
Procedure
- Draw a state transition diagram for this finite state machine.
Use four states numbered as follows: closed (11), opening (00), open
(01), and closing (10). Each transition (edge) should be labeled
with the values of the inputs (TBEG) for which it is taken.
Use X to indicate "don't care" for input values when appropriate. Also note any inputs/values that should be considered "impossible" from the given state. Within each state circle, there should be three lines: the state assignment value, given above, the logical name of the state, also given above, and, underneath a line, the output that should be asserted when the finite state machine is in this state. Note that this is different from the FSM built in the last lab. In that lab, the FSM (a Meally machine) expressed outputs on the transitions, so outputs were a function of both the current state _and_ the inputs. In this lab, you are building a Moore machine, in which the outputs are only determined by the current state. This has the advantage, for us, of making it easy to have the outputs only change on clock changes, since it is only the current state that determines the output.
- Construct a compressed truth table corresponding to your state
transition diagram. Use X to indicate "don't care" for input
values.These will be "wild cards" that match both 0 and 1. This table should be around a quarter of the size of the
full truth table. Use the tables in the file
garage.doc
or
garage.pdf
. Include lines for the "impossible" input combinations with X's in the next state bits. This is the equivalent of our don't cares in the BCD lab.
- Complete the full truth table corresponding to the state
transition diagram and the compressed truth table. The columns
in this table should be (from left to right): current state, T, B, E,
G, next state. There should be one line for each combination of
current state and input values (64 lines).
- Construct a full truth table for the output. The columns in this
table should be (from left to right): current state, U, D. There
should be one line for each combination of state values (4 lines). Note that it is here that we make use of having designed a Moore machine solution to this problem, and our outputs are only a function of the current state, and we have no columns in this truth table for TBE&G.
- While viewing the
NextState_0
circuit in the file
garage.circ
, select "Analyze
Circuit" from the "Project" menu. Complete the table using your
values from the full truth table, then click on the "Build Circuit"
button. Does the minimized circuit correspond to your compressed
truth table?
- Build the
Output_0
circuit in the same manner.
- Test the operation of the completed finite state machine with the
main
circuit in the file
main.circ
. Choose "Ticks
Enabled" from the "Simulation" menu. Observe the response to changes
of the input signals. Can you cause the state machine to visit every
state? Can you cause the state machine to follow every possible
transition? Demonstrate the working implementation for your instructor.
- For extra credit (10% of a single lab grade), implement the circuit on the breadboards. Keep organized, with portions of the circuit separated from one another.