Académique Documents
Professionnel Documents
Culture Documents
Objectives
To design a Vending Machine Controller
Design the state diagram Design the state table Write the VHDL code
Simulate/test each module
8/18/2010
2 of 26
Design Description/Specifications
Vending Machine Controller
1. 2. The machine takes quarters only (Qi) The machine can dispense: 1. Water: 75 cents (W) 2. Cola: 50 cents (C) 3. Beer: 50 cents (B) The machine has a Coin Return button (Cr) Only one input may be active at a time A product can be dispensed in one clock cycle If more than 75 cents is inserted, the money is automatically returned If no inputs are active, the state machine stays in the current state Outputs: 1. CRo: Coin Return Out (all money in the machine) 2. Wo: Water Out 3. Co : Cola Out 4. Bo : Beer Out 5. Qo : Quarter Out
3. 4. 5. 6. 7. 8.
8/18/2010
3 of 26
3. 4. 5.
Develop the state table from the state diagram Decide on the number of state variables needed to represent all states
1. Minimize the number of states if possible
6.
8/18/2010
State Diagram
Reset
1. 2.
A
Qi
C
CRo
B
Qi
Cr Cr
3. 4. 5. 6. 7.
Cr
D E
Co
8.
Qi C B B
K
Qo
G
W Qi
F
Bo
The machine takes quarters only (Qi) The machine can dispense: 1. Water: 75 cents (W) 2. Cola: 50 cents (C) 3. Beer: 50 cents (B) The machine has a Coin Return button (Cr) Only one input may be active at a time A product can be dispensed in one clock cycle If more than 75 cents is inserted, the money is automatically returned If no inputs are active, the state machine stays in the current state Outputs: All produce a pulse that activates the release mechanism: 1. CRo: Coin Return Out (all money in the machine) 2. Wo: Water Out 3. Co : Cola Out 4. Bo : Beer Out 5. Qo : Quarter Out
H
Wo
I
Qo
J
Qo
8/18/2010
5 of 26
State Diagram
Reset
A
Qi
Will this work? If nothing has happened, or if the machine has been reset, the machine is in state A
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi C
K
Qo
G
W Qi
F
Bo
B B
H
Wo
I
Qo
J
Qo
8/18/2010
6 of 26
State Diagram
Reset
A
Qi
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi C
K
Qo
G
W Qi
F
Bo
B B
H
Wo
I
Qo
J
Qo
8/18/2010
7 of 26
State Diagram
Reset
If we input a quarter, the machine goes to state B (25 cents) We can now: Do nothing (stay in State B) Hit the Coin Return (Go to state C and return the money) Insert a quarter (Go to state D and wait)
A
Qi
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi C
K
Qo
G
W Qi
F
Bo
B B
H
Wo
I
Qo
J
Qo
8/18/2010
8 of 26
State Diagram
Reset
If the machine is in state D (50 cents) We can: Do nothing (stay in State D) Hit the Coin Return (Go to state C and return the money) Select a cola (go to state E, output a cola, then go to A) Select a beer (go to state F, output a beer, then go to A) Insert a quarter (75 cents - Go to state G and wait)
A
Qi
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi C
K
Qo
G
W Qi
F
Bo
B B
H
Wo
I
Qo
J
Qo
8/18/2010
9 of 26
State Diagram
Reset
If the machine is in state G (75 cents) We can: Do nothing (stay in State G) Hit the Coin Return (Go to state C and return the money) Select a cola (go to state K, return a quarter, and then go to state E, output a cola, then go to A) Select a beer (go to state J, return a quarter, and then go to state F, output a beer, then go to A) Insert a quarter (return the quarter too much money - Go back to state G and wait) Select a water (go to state H, output a water, then go to state A)
A
Qi
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi C
K
Qo
G
W Qi
F
Bo
B B
H
Wo
I
Qo
J
Qo
8/18/2010
10 of 26
State Diagram
Reset
It will work, but we have 3 different states (I, J, and K) that output a quarter. For a Moore machine, this is necessary, because each state then goes to a different state I ->G J->F K->E
A
Qi
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi C
K
Qo
G
W Qi
F
Bo
B B
H
Wo
I
Qo
J
Qo
8/18/2010
11 of 26
State Diagram
Reset
It will work, but we have 3 different states (I, J, and K) that output a quarter. For a Moore machine, this is necessary, because each state then goes to a different state But, if the input (B, C or Qi) is associated with state G as well as the output (Qo), as in Mealy Machines, then we do not need the three states (I, J, and K)
Cr
A
Qi
C
CRo
B
Qi
Cr
D E
Co
C C/Qo B B/Qo
Qi
G
W Qi/Qo
F
Bo
H
Wo
8/18/2010
12 of 26
3. 4. 5.
Develop the state table from the state diagram Decide on the number of state variables needed to represent all states
1. Minimize the number of states if possible
6.
8/18/2010
State Table
Reset
A
Qi
We have: 8 states (3 state bits) 5 inputs (Cr, Qi, C, B, or W) 5 outputs (CRo, Qo, Wo, Bo, and Co)
C
CRo
B
Qi
Cr Cr
D E
Co
Cr Qi
C C/Qo B B/Qo
G
W Qi/Qo
F
Bo
H
Wo
8/18/2010
14 of 26
3. 4. 5.
Develop the state table from the state diagram Decide on the number of state variables needed to represent all states
1. Minimize the number of states if possible
6.
8/18/2010
8/18/2010
16 of 26
8/18/2010
17 of 26
Simulation/Test
This is the 1st Test Bench
2 quarters in, buy a beer 2 quarters in, buy a cola 3 quarters in, buy water 1 quarter in, hit Coin Return
8/18/2010
18 of 26
Simulation/Test: Results
1st set of results
2 quarters in, buy a beer, a beer is dispensed 2 quarters in, buy a cola, a cola is dispensed 3 quarters in, buy water, a water is dispensed 1 quarter in, hit Coin Return, a quarter is returned
8/18/2010
19 of 26
Simulation/Test 2
This is the 2nd Test Bench
5 quarters in, buy a beer 4 quarters in, buy a cola 0 quarters in, buy water 0 quarter in, hit Coin Return
8/18/2010
20 of 26
Simulation/Test: Results 2
2nd set of results
8/18/2010
21 of 26
Simulation/Test: Results 2
2nd set of results
RED: 5 quarters in: after 3, they start being returned BLUE: Buy a beer: another quarter is returned and a beer is dispensed
8/18/2010
22 of 26
Simulation/Test: Results 2
2nd set of results
8/18/2010
23 of 26
Simulation/Test: Results 2
2nd set of results
RED: 4 more quarters in: after 3, they start being returned YELLOW: Buy a cola, a quarter is returned and a cola is dispensed
8/18/2010
24 of 26
Simulation/Test: Results 2
2nd set of results
Magenta: No quarters in: Buy water, nothing happens Green: Hit Coin Return, nothing happens
8/18/2010
25 of 26
Summary
In this topic we:
Designed a state machine that controls a vending machine
Designed the state diagram Designed the state table Wrote the VHDL code
Looked at two new keywords falling_edge after Xns Simulated and tested each module
8/18/2010
26 of 26