-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcounter_tb.sv
65 lines (57 loc) · 1.53 KB
/
counter_tb.sv
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
//////////////////////////////////////////////////////////////////////////////////
// Filename: counter_test.sv
//////////////////////////////////////////////////////////////////////////////////
module counter_tb ();
logic clk, rst, inc, load;
logic [7:0] din, cnt;
// instance counter
counter counter_inst(.clk(clk), .rst(rst), .inc(inc), .load(load), .din(din), .cnt(cnt));
// Free running Clock
initial begin
clk = 0;
forever #5 clk = ~clk;
end
// Counter test inputs
initial begin
#50 rst = 1;
load = 0;
inc = 0;
din = 0;
repeat(10) @(negedge clk);
rst = 0;
for (int i = 0; i < 10; i = i + 1) begin
repeat(6) @(negedge clk);
inc = 1;
@(negedge clk);
inc = 0;
end
@(negedge clk);
load = 1;
din = 8'h5a;
@(negedge clk);
load = 0;
for (int i = 0; i < 10; i = i + 1) begin
repeat(6) @(negedge clk);
inc = 1;
@(negedge clk);
inc = 0;
end
@(negedge clk);
rst = 1;
for (int i = 0; i < 10; i = i + 1) begin
repeat(3) @(negedge clk);
inc = 1;
@(negedge clk);
inc = 0;
end
@(negedge clk);
rst = 0;
for (int i = 0; i < 10; i = i + 1) begin
repeat(6) @(negedge clk);
inc = 1;
@(negedge clk);
inc = 0;
end
$stop;
end
endmodule