-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvending_machine_tb.v
107 lines (84 loc) · 2.11 KB
/
vending_machine_tb.v
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
module vending_machine_tb();
reg clk,rst;
reg [1:0] in;
wire product,change;
vending_machine dut(in,clk,rst,product,change);
parameter IDLE=3'b000,RS1=3'b001,RS2=3'b011,PRODUCT=3'b101, CHANGE=3'b111;
reg exp_prod,exp_change;
/////////////task for inserting coin //////////////////////
task insert(input [1:0] coin);
begin
@(negedge clk) in=coin;
end
endtask
//////////////////////task for reset////////////////////
task reset();
begin
@(negedge clk)
rst=1'b1;
exp_prod=0;
exp_change=0;
in=2'bxx;
@(negedge clk)rst=1'b0;
end
endtask
/////task to check product state correct values ///////////
task product_check();
begin
exp_prod=1;
exp_change=0;
@(negedge clk)
if (product==1 && change==0)
$display("Product state is verified\n Product=%d\t Change=%d\t",product,change);
else
$display("False product state\n Product=%d\t Change=%d\t",product,change);
end
endtask
/////////task to check change state correct values ///////
task change_check();
begin
exp_change=1;
exp_prod=1;
@(negedge clk)
if ((product==exp_prod) && (change==exp_change))
$display("Change state is verified\n Product=%d\t Change=%d\t",product,change);
else
$display("False change state\n Product=%d\t Change=%d\t",product,change);
end
endtask
//////////////clock /////////////////////
initial begin
clk=1'b1;
forever #5 clk=~clk;
end
///////////////stimulus//////////////////
initial begin
reset();
insert(1); insert(2);
product_check;
reset();
insert(2); insert(2);
change_check();
reset();
insert(1);
change_check();
product_check();
reset();
insert(1);insert(1);reset(); insert(2); insert(2);
change_check;
insert(1);
insert(0);
repeat(14)begin @(negedge clk); end
insert(2);
product_check();
reset();
insert(2);
insert(0);
repeat(14)begin @(negedge clk); end
insert(2);
product_check();
insert(1);
insert(1);
#20 $finish;
end
endmodule