-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvending_machine.v
More file actions
98 lines (82 loc) · 1.66 KB
/
Copy pathvending_machine.v
File metadata and controls
98 lines (82 loc) · 1.66 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
`timescale 1ns/1ps
module vending_machine(
input clk,
input rst,
input coin5,
input coin10,
output reg dispense,
output reg change
);
parameter S0 = 3'b000;
parameter S5 = 3'b001;
parameter S10 = 3'b010;
parameter S15 = 3'b011;
parameter S20 = 3'b100;
reg [2:0] state;
reg [2:0] next_state;
// State Register
always @(posedge clk or posedge rst)
begin
if (rst)
state <= S0;
else
state <= next_state;
end
// Next-State Logic
always @(*)
begin
case(state)
S0:
begin
if (coin5)
next_state = S5;
else if (coin10)
next_state = S10;
else
next_state = S0;
end
S5:
begin
if (coin5)
next_state = S10;
else if (coin10)
next_state = S15;
else
next_state = S5;
end
S10:
begin
if (coin5)
next_state = S15;
else if (coin10)
next_state = S20;
else
next_state = S10;
end
S15:
next_state = S0;
default:
next_state = S0;
endcase
end
// Output Logic
always @(*)
begin
dispense = 0;
change = 0;
case(state)
S15:
begin
dispense = 1;
change = 0;
/*if (coin10)
change = 1;*/
end
S20:
begin
dispense = 1;
change = 1;
end
endcase
end
endmodule