Professional Documents
Culture Documents
Lecture 16 State Machines 2
Lecture 16 State Machines 2
• Note:
– The maximum dollar amount input is $1.20
Vending Machine State Machine
rec_coin
rec_coin
false rec_coin
But if it doesn’t, we
stay in the rec_coin
state.
Vending Machine State Machine
disp_quarter
money_in < 25
Vending Machine State Machine
return_money = ‘1’
money_in = 0 Now add the capability for the user to get
their money back without purchasing a
product, equivalent to the “coin return”
false disp_nickel
function on a real vending machine
money_in < 10
false
false disp_nickel
4
money_in < 10
false
Assigning
control signals
to outputs
2-process state
machine
consists of
register portion
(i.e., flip-flops)
vending_machine.vhd
vending_machine.vhd
Download
vend_input.csv
from Isidore
test_vending_machine.vhd
Simulation Results
Simulation Results
More on State Machines…
• The state machine is the heart and soul of a VHDL
logic module (VHDL synthesizable file)
• Any module of sufficient complexity should use a
state machine as its controller
– One state machine per VHDL module
• Because of the abstraction allowed in VHDL, the
state machine is an excellent way to make your
code readable (or unreadable, for that matter)
– So, name your states and control signals carefully
User Interface with Sequential Circuits
De-bouncing
switch_in switch_db
Circuitry
clk
debounce.vhd
input_change
in_follow
Lead FF Follow FF
switch_in in_lead
D Q D Q
D
clk Q clk Q
rst rst
reset
clk
debounce.vhd
vending_machine
design is a component
inside of vend_demo
hex_to_7_seg and
debounce are also
components of
vend_demo
constants: we can
use or not use debounce
circuitry, and we can
change the length of
time the LEDs turn on
D
Counters to keep track
of LED “on” time
De-bounced inputs
Instantiations of the
vending_machine
and hex_to_7_seg
components
Use of 2 generate
statements allow us the
flexibility to use the de-
bounce circuitry or not.
You should try both!
D
Edge detection circuitry
for 4 input switches
Processes will allow for LEDs to light up for 1 second
sec_count = 50,000,000
nickel
quarter count
count process
process
product
dime count
count process
process
Pin Assignments
product_out
reset
quarter_out, quarter_in,
out_seg_1, out_seg_0 dime_out, dime_in, return_money
nickel_out nickel_in
How to Operate
Displays current Turns on Turns on Turns on Lights up green for
money in vending for 1s for for 1s for for 1s for 1s when product is
machine as a hex each each dime each nickel dispensed
value quarter dispensed dispensed
dispensed
Toggle
once per Toggle Toggle once
quarter once per per nickel Initiates coin Resets vending
dime input input return. LEDs above quarter, machine to
input
($0.10) ($0.05) dime, nickel switches will state 0
($0.25)
illuminate for 1s per coin
Lab 11 Time
Compile and Simulate:
vending_machine.vhd,
test_vending_machine.vhd
debounce.vhd,
test_debounce.vhd