-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpes_ptvm.v
More file actions
123 lines (97 loc) · 1.35 KB
/
pes_ptvm.v
File metadata and controls
123 lines (97 loc) · 1.35 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
///1ps
module pes_ptvm(
input clk,
input rst,
input [1:0]in,
output reg out
);
parameter s0 = 2'b00;
parameter s1 = 2'b01;
parameter s2 = 2'b10;
reg [1:0]c_state; reg [1:0]n_state;
always @(posedge clk)
begin
if(rst)
begin
c_state = 0;
n_state = 0;
end
else
begin
c_state = n_state;
case(c_state)
s0: if(in == 0)
begin
n_state = s0;
out = 0;
end
else if(in== 2'b01)
begin
n_state = s1;
out = 0;
end
else if(in == 2'b10)
begin
n_state = s2;
out = 0;
end
s1: if(in == 0)
begin
n_state = s0;
out = 0;
end
else if(in== 2'b01)
begin
n_state = s2;
out = 0;
end
else if(in == 2'b10)
begin
n_state = s0;
out = 1;
end
s2: if(in == 0)
begin
n_state = s0;
out = 0;
end
else if(in== 2'b01)
begin
n_state = s0;
out = 1;
end
else if(in == 2'b10)
begin
n_state = s0;
out = 1;
end
endcase
end
end
endmodule
/*
//testbench
//'include "vending.v"
module pesptvending_machine_tb;
reg clk;
reg rst;
reg [1:0]in;
wire out;
pes_ptv_machine uut(
.in(in),
.clk(clk),
.rst(rst),
.out(out)
);
initial begin
$dumpfile("ticketvending.vcd");
$dumpvars(0,vending_machine_tb);
rst = 1;
clk = 0;
#6 rst = 0;
in = 1;
#19 in = 2; #10;
end
always #5 clk = ~clk;
endmodule
*/