forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7442-tb.v
132 lines (116 loc) · 2.44 KB
/
7442-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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Test: BCD to decimal one-of-ten decoder
module test;
`TBASSERT_METHOD(tbassert)
`TBASSERT_2_METHOD(tbassert2)
localparam WIDTH_OUT = 10; // do not pass this to the module because
// it is not variable
localparam WIDTH_IN = $clog2(WIDTH_OUT); // do not pass this to the module because
// it is dependent value
// DUT inputs
reg [WIDTH_IN-1:0] A; // A is 4 bits
// DUT outputs
wire [WIDTH_OUT-1:0] Y;
// DUT
ttl_7442 #(.DELAY_RISE(5), .DELAY_FALL(3)) dut(
.A(A),
.Y(Y)
);
initial
begin
reg [WIDTH_OUT-1:0] Y_expected;
integer i;
$dumpfile("7442-tb.vcd");
$dumpvars;
// select BCD 0 -> first output is 0
A = 4'b0000;
#6
tbassert(Y == 10'b1111111110, "Test 1");
#0
// select BCD 1 -> second output is 0
A = 4'b0001;
#6
tbassert(Y == 10'b1111111101, "Test 2");
#0
// select BCD 9 -> highest output is 0
A = 4'b1001;
#6
tbassert(Y == 10'b0111111111, "Test 3");
#0
// select BCD invalid (1111) -> output is 1s
A = 4'b1111;
#10
tbassert(Y == 10'b1111111111, "Test 4");
#0
// select BCD invalid (1010) -> output is 1s
A = 4'b1010;
#10
tbassert(Y == 10'b1111111111, "Test 5");
#0
// repeat tests: change to select BCD n-1 from select BCD n
for (i = 9; i >= 0; i--)
begin
A = i;
case (i)
9:
begin
Y_expected = 10'b0111111111;
end
8:
begin
Y_expected = 10'b1011111111;
end
7:
begin
Y_expected = 10'b1101111111;
end
6:
begin
Y_expected = 10'b1110111111;
end
5:
begin
Y_expected = 10'b1111011111;
end
4:
begin
Y_expected = 10'b1111101111;
end
3:
begin
Y_expected = 10'b1111110111;
end
2:
begin
Y_expected = 10'b1111111011;
end
1:
begin
Y_expected = 10'b1111111101;
end
0:
begin
Y_expected = 10'b1111111110;
end
endcase
#10
tbassert2(Y == Y_expected, "Test", (10 - i), "6");
end
// end repeat tests
#0
// select BCD invalid bits transition to BCD 6 -> seventh output is 0
A = 4'b1110;
#6
tbassert(Y == 10'b1111111111, "Test 7");
#0
A = 4'b0110;
#6
tbassert(Y == 10'b1110111111, "Test 7");
#0
// all input select bits transition from previous -> highest output is 0
A = 4'b1001;
#6
tbassert(Y == 10'b0111111111, "Test 8");
#10
$finish;
end
endmodule