-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_machine_tb.v
99 lines (85 loc) · 2.12 KB
/
state_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
`timescale 1ns / 1ps
module tb_ee354_2048;
// Inputs
reg Clk;
reg Reset;
reg up;
reg down;
reg left;
reg right;
// Outputs
wire q_I, q_Wait, q_Up, q_Down, q_Right, q_Left, q_Win, q_Lose;
// Instantiate the Unit Under Test (UUT)
ee354_2048 uut (
.Clk(Clk),
.Reset(Reset),
.up(up),
.down(down),
.left(left),
.right(right),
.q_I(q_I),
.q_Wait(q_Wait),
.q_Up(q_Up),
.q_Down(q_Down),
.q_Right(q_Right),
.q_Left(q_Left),
.q_Win(q_Win),
.q_Lose(q_Lose)
);
// Clock generation
always #100 Clk = ~Clk;
// Task to display board
task display_board;
integer i, j;
begin
$display("Board State:");
for (i = 0; i < 4; i = i + 1) begin
for (j = 0; j < 4; j = j + 1) begin
$write("%d\t", uut.board[i][j]);
end
$display(""); // Move to the next line after each row
end
$display(""); // Extra line for better readability
end
endtask
// Initial setup and test sequence
initial begin
// Initialize Inputs
Clk = 0;
Reset = 1;
up = 0;
down = 0;
left = 0;
right = 0;
// Reset the system
#1000;
Reset = 0;
// Wait for initial setup
#1000;
display_board(); // Display initial board
// Simulate UP movement
up = 1;
#200;
up = 0;
#1000;
display_board(); // Display board after UP
// Simulate DOWN movement
down = 1;
#200;
down = 0;
#1000;
display_board(); // Display board after DOWN
// Simulate LEFT movement
left = 1;
#200;
left = 0;
#1000;
display_board(); // Display board after LEFT
// Simulate RIGHT movement
right = 1;
#200;
right = 0;
#1000;
display_board(); // Display board after RIGHT
end
endmodule