forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
74147-tb.v
128 lines (115 loc) · 3.05 KB
/
74147-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
// Test: 10-line to 4-line priority encoder
module test;
`TBASSERT_METHOD(tbassert)
localparam WIDTH_IN = 9; // do not pass this to the module because it is not variable
localparam WIDTH_OUT = 4; // do not pass this to the module because it is not variable
// DUT inputs
reg [WIDTH_IN-1:0] A_bar;
// DUT outputs
wire [WIDTH_OUT-1:0] Y_bar;
// DUT
ttl_74147 #(.DELAY_RISE(5), .DELAY_FALL(3)) dut(
.A_bar(A_bar),
.Y_bar(Y_bar)
);
initial
begin
$dumpfile("74147-tb.vcd");
$dumpvars;
// all zeroes -> output is highest priority 9 (active low)
A_bar = 9'b000000000;
#6
tbassert(Y_bar == ~4'b1001, "Test 1");
#0
// all ones -> output is lowest priority 0
A_bar = 9'b111111111;
#6
tbassert(Y_bar == ~4'b0000, "Test 2");
#0
// bit 6 zero (*where bit numbering goes from 1 to 9) -> output is 6
A_bar = 9'b111011111;
#6
tbassert(Y_bar == ~4'b0110, "Test 3");
#0
// bit 6 zero with other zeroes present -> output is 6
A_bar = 9'b111010101;
#6
tbassert(Y_bar == ~4'b0110, "Test 4");
#0
// single bit transition to bit 4 zero -> output is 4
A_bar = 9'b111110101;
#6
tbassert(Y_bar == ~4'b0100, "Test 5");
#0
// multiple bit transition to bit 1 zero -> output is 1
A_bar = 9'b111111110;
#6
tbassert(Y_bar == ~4'b0001, "Test 6");
#0
// single bit transition to bit 8 zero -> output is 8
A_bar = 9'b101111110;
#6
tbassert(Y_bar == ~4'b1000, "Test 7");
#0
// all input bits transition from previous -> output is 9
A_bar = 9'b010000001;
#6
tbassert(Y_bar == ~4'b1001, "Test 8");
#0
// multiple bit transition with null change to outputs -> output is 9
A_bar = 9'b011111111;
#6
tbassert(Y_bar == ~4'b1001, "Test 9");
#0
// multiple bit transition with null change to outputs -> output is 7
A_bar = 9'b110101100;
#6
tbassert(Y_bar == ~4'b0111, "Test 10");
#0
A_bar = 9'b110000111;
#6
tbassert(Y_bar == ~4'b0111, "Test 10");
#0
// multiple bit transition from all ones to bit 6 zero -> output is 6
A_bar = 9'b111111111;
#6
tbassert(Y_bar == ~4'b0000, "Test 11");
#0
A_bar = 9'b111000110;
#6
tbassert(Y_bar == ~4'b0110, "Test 11");
#0
// multiple bit transition to all ones -> output is 0
A_bar = 9'b111111111;
#6
tbassert(Y_bar == ~4'b0000, "Test 12");
#0
// single bit transition to bit 9 zero -> output is 9
A_bar = 9'b011111111;
#6
tbassert(Y_bar == ~4'b1001, "Test 13");
#0
// the following set of tests check when the inputs are floating (high impedance)
// since the device logic incorporates don't cares
// 1. floating inputs behind any leading zero do not affect the output
// 2. inputs that may affect the output must be tied to high or low logic voltage level
// (e.g. pull-up resistor), so floating input at leading bit position is not tested
// and should not be simulated
// bit 9 zero -> output is 9
A_bar = 9'b0zz0zz000;
#6
tbassert(Y_bar == ~4'b1001, "Test 14");
#0
// bit 6 zero -> output is 6
A_bar = 9'b1110z01zz;
#6
tbassert(Y_bar == ~4'b0110, "Test 15");
#0
// bit 2 zero -> output is 2
A_bar = 9'b11111110z;
#6
tbassert(Y_bar == ~4'b0010, "Test 16");
#10
$finish;
end
endmodule