-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathedge_cnt_tb.sv
79 lines (73 loc) · 1.81 KB
/
edge_cnt_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Testbench for edge_cnt module
module edge_cnt_tb();
// Define parameter and inputs/outputs of DUT (device under test)
localparam EDGES = 10;
logic clk;
logic rst_n;
logic in;
logic out;
// Instantiate DUT - use gold for my version, other for yours
edge_cnt_gold
//edge_cnt
#(
.EDGES(EDGES)
)
dut
(
.clk(clk),
.rst_n(rst_n),
.in(in),
.out(out)
);
always begin
clk = 1;
#5;
clk = 0;
#5;
end
// For loop signal
integer i;
// Used to track the behavior of the module at a tb level
integer edge_cnt;
logic in_prev;
// For tb
initial begin
// reset sequence
rst_n = 1;
in = 0;
@(negedge clk);
rst_n = 0;
@(negedge clk);
rst_n = 1;
edge_cnt = 0;
in_prev = 0;
in = 0;
// Now do a ton of iterations, checking the results
// It may be helpful to uncomment some of these displays
// for debbugging purposes
for(i = 0; i < 1000000; i++) begin
@(posedge clk);
//$display("IN WAS: %b, IN IS NOW: %b", in_prev, in);
if((in == 1) && (in_prev == 0)) begin
edge_cnt++;
$display("DETECTED POSEDGE ON IN");
//$display("EDGE COUNT NOW: %d", edge_cnt);
if(edge_cnt == EDGES) begin
$display("OUT SHOULD BE 1: out: %b", out);
edge_cnt = 0;
if(out == 0) begin
$display("ASSERTION FAILED! Quitting...");
$finish;
end
end
end
in_prev = in;
@(negedge clk)
// Generate random next input
in = $random % 2;
end
// If you make it here, it's safe to say you're good.
$display("PASSED!");
$finish;
end
endmodule