-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestbench_decoder.sv
46 lines (36 loc) · 970 Bytes
/
testbench_decoder.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
module testbench_decoder();
logic center;
logic [7:0] sides;
logic nexton, nexton_exp;
logic ph1, ph2;
logic [31:0] vectornum, errors;
logic [9:0] testvectors[500:0];
//10-bit testvector format: {center, sides[7:0]}_nexton
decoder dut(center, sides, nexton);
initial $readmemb("decoder.tv", testvectors);
initial vectornum = 0;
initial errors = 0;
always begin
ph1 = 0; ph2 = 0;
#1; ph1 = 1;
#4; ph1 = 0;
#1; ph2 = 1;
#4; ph2 = 0;
end
always @(posedge ph1) begin
#1; {center, sides, nexton_exp} = testvectors[vectornum];
end
always @(posedge ph2) begin
if (nexton !== nexton_exp)
begin
$display("Error: inputs = %b; %b", center, sides);
$display("outputs = %b (%b expected)", nexton, nexton_exp);
errors = errors + 1;
end
assign vectornum = vectornum + 1;
if (testvectors[vectornum] === 10'bx) begin
$display("Finished: %d vectors with %d errors", vectornum, errors);
$finish;
end
end
endmodule