-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvending_machine.py
More file actions
31 lines (24 loc) · 868 Bytes
/
Copy pathvending_machine.py
File metadata and controls
31 lines (24 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pyrtl
from fsm import FSM
input_wire = pyrtl.Input(bitwidth=1, name="input")
output_wire = pyrtl.Output(bitwidth=3, name="output")
vending_machine_states = ["WAIT", "TOKONE", "TOKTWO", "TOKTHREE", "DISP", "RFND"]
vending_machin_rules = [
"all + 0 -> RFND, 0",
"WAIT + 1 -> TOKONE, 1",
"TOKONE + 1 -> TOKTWO, 2",
"TOKTWO + 1 -> TOKTHREE, 3",
"TOKTHREE + 1 -> DISP, 4",
"DISP + all -> WAIT, 0",
"RFND + all -> WAIT, 0"
]
vending_machine = FSM(input_bitwidth=1, output_bitwidth=3, states=vending_machine_states, rulesList=vending_machin_rules)
vending_machine <<= input_wire
output_wire <<= vending_machine()[0]
sim_trace = pyrtl.SimulationTrace()
sim = pyrtl.Simulation(tracer=sim_trace)
sim_inputs = {
'input' : '111111101110111100000'
}
sim.step_multiple(sim_inputs)
sim_trace.render_trace(trace_list=['input', 'output'])