EECS 31/CSE 31/ICS 151 Homework 7
View Questions Only
Problem
Question
Design a Polite & Stupid Elevator
Assumptions:
- There are three floors
- Door opens on every floor
- One button at any time
Solution
-
We assume there are 5 states as shown below. The inputs to the state diagram are the Button 1, 2, 3 or no button pressed. F1, F2 and F3 represent the elevator's destination is 1, 2, 3 floor. F2D represent the elevator passing floor 2 when it goes down from third floor to first floor without pressing Button 2. F2U represent the elevator passing floor 2 when it goes up from first floor to third floor without pressing Button 2. The outputs of this state diagram are directions of the elevator, which indicating the elevator is going up or going down.
-
Based on the above state diagram, we can get the next-state table on different button inputs:
Present State |
Next State |
Button 1 |
Button 2 |
Button 3 |
No Button |
F1 |
F1 |
F2 |
F2U |
F1 |
F2 |
F1 |
F2 |
F3 |
F2 |
F2U |
F3 |
F3 |
F3 |
F3 |
F2D |
F1 |
F1 |
F1 |
F1 |
F3 |
F2D |
F2 |
F3 |
F3 |
We encode these 5 states with F1 = 010, F2 = 100, F2U = 001, F2D = 000, F3 = 110. Then we can represent these 5 states by using three D flip-flops. Let Q2, Q1,and Q0 represent the outputs of these D flip-flops. For the input button, we use B1, B0 to represent which button is pressed. Hence, the above table can be transformed to:
Present State |
Next State |
Button 1 |
Button 2 |
Button 3 |
No Button |
Q2Q1Q0 |
B1B0 = 01 |
B1B0 = 10 |
B1B0 = 11 |
B1B0 = 00 |
F1 = 010 |
F1 = 010 |
F2 = 100 |
F2U = 001 |
F1 = 010 |
F2 = 100 |
F1 = 010 |
F2 = 100 |
F3 = 110 |
F2 = 100 |
F2U = 001 |
F3 = 110 |
F3 = 110 |
F3 = 110 |
F3 = 110 |
F2D = 000 |
F1 = 010 |
F1 = 010 |
F1 = 010 |
F1 = 010 |
F3 = 110 |
F2D = 000 |
F2 = 100 |
F3 = 110 |
F3 = 110 |
-
We can draw the K-maps for the next-state table as following. There are 5 variables, the output of the 3 D flip-flops Q2, Q1 and Q0 and the input button B1, B0. Each value in a square represent the next-state value corresponding to the next-state table. For those square not defined in the next-state table, we use an 'X' to indicating a "don't care" occasion.
Replacing F1, F2, F3, F2U and F2D with the values of Q2, Q1 and Q0, we can get 3 K-Maps for Q2(next), Q1(next) and Q0(next), as shown below:
Q2(next) = Q0 + Q2B1 + Q2B0' + Q1B1B0'
Q1(next) = Q2'Q1' + Q2'B1' + Q1B1'B0' + Q2B1B0 + Q2Q1'B0
Q0(next) = Q2'Q1B1B0
-
Similarly, we can get the output equations based on the following K-Maps:
Down = Q2'Q1'Q0' + Q2B1'B0 + Q2Q1B1B0'
Up = Q0 + Q2'Q1B1 + Q2Q1'B1B0
-
Finally, we can draw the schematic based on the next-state and output equations: