-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter_test.v
More file actions
58 lines (48 loc) · 1.11 KB
/
counter_test.v
File metadata and controls
58 lines (48 loc) · 1.11 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
`include "counter.v"
module CounterTest;
integer i;
logic set, rst, mode, clk;
logic [7:0] a;
logic [7:0] out;
Counter#(.WIDTH(8)) ctr(.set(set), .rst(rst), .mode(mode), .clk(clk), .a(a),
.out(out));
initial begin
$display("Counter");
$monitor($time, " OUT=%x, MODE=%x, SET=%x, RST=%x, A=%x, CLK=%x",
out, mode, set, rst, a, clk);
set = '0; rst = '0; mode = '0; clk = '0; a = '0;
// Reset circuit
$display("Reset Test");
rst = 1;
#5
rst = 0;
assert(out == 8'h00);
#5
// Increment test
$display("Increment Test");
for(i = 1; i < 256; i++) begin
clk = 1; #5 clk = 0; #5;
assert(out == i);
end
// Increment test
$display("Decrement Test");
mode = 1;
for(i = 254; i > -1; i--) begin
clk = 1; #5 clk = 0; #5;
assert(out == i);
end
// Set test
$display("Set Test");
mode = 0;
a = 'h55; set = 1;
clk = 1;
#5 clk = 0;
#5 assert(out == 'h55);
set = 0;
clk = 0;
for(i = 0; i < 5; i++) begin
clk = 1; #5 clk = 0; #5;
end
assert(out == 'h5A);
end
endmodule