File size: 4,740 Bytes
8dc19e4 | 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | // Test: 8-input multiplexer
module test;
`TBASSERT_METHOD(tbassert)
localparam WIDTH_IN = 5;
localparam WIDTH_SELECT = $clog2(WIDTH_IN); // do not pass this to the module because
// it is dependent value
// DUT inputs
reg Enable_bar;
reg [WIDTH_SELECT-1:0] Select; // Select is three bits but only valid in range 3'b000
// to 3'b100
reg [WIDTH_IN-1:0] D;
// DUT outputs
wire Y;
wire Y_bar;
// DUT
ttl_74151 #(.WIDTH_IN(WIDTH_IN), .DELAY_RISE(5), .DELAY_FALL(3)) dut(
.Enable_bar(Enable_bar),
.Select(Select),
.D(D),
.Y(Y),
.Y_bar(Y_bar)
);
initial
begin
$dumpfile("74151-tb.vcd");
$dumpvars;
// select 000: enabled
Enable_bar = 1'b0;
Select = 3'b000;
D = 5'b01011;
#6
tbassert(Y == 1'b1, "Test 1");
tbassert(Y_bar == 1'b0, "Test 1");
#0
// select 000: disabled -> output 0
Enable_bar = 1'b1;
#6
tbassert(Y == 1'b0, "Test 2");
tbassert(Y_bar == 1'b1, "Test 2");
#0
// select 011: disabled
Select = 3'b011;
#10
tbassert(Y == 1'b0, "Test 3");
tbassert(Y_bar == 1'b1, "Test 3");
#0
// select 011: enabled
Enable_bar = 1'b0;
#10
tbassert(Y == 1'b1, "Test 4");
tbassert(Y_bar == 1'b0, "Test 4");
#0
// select 100: enabled
Select = 3'b100;
#10
tbassert(Y == 1'b0, "Test 5");
tbassert(Y_bar == 1'b1, "Test 5");
#0
// select 100: disabled
Enable_bar = 1'b1;
#10
tbassert(Y == 1'b0, "Test 6");
tbassert(Y_bar == 1'b1, "Test 6");
#0
// select 001: disabled
Select = 3'b001;
#10
tbassert(Y == 1'b0, "Test 7");
tbassert(Y_bar == 1'b1, "Test 7");
#0
// select 001: enabled
Enable_bar = 1'b0;
#10
tbassert(Y == 1'b1, "Test 8");
tbassert(Y_bar == 1'b0, "Test 8");
#0
// while enabled: change to select 000 from select 001
Select = 3'b000;
#10
tbassert(Y == 1'b1, "Test 9");
tbassert(Y_bar == 1'b0, "Test 9");
#0
// while enabled: change to select 100 from select 001
Select = 3'b001;
#10
tbassert(Y == 1'b1, "Test 10");
Select = 3'b100;
#10
tbassert(Y == 1'b0, "Test 10");
tbassert(Y_bar == 1'b1, "Test 10");
#0
// while select 100 enabled: change to different inputs
D = 5'b11110;
#10
tbassert(Y == 1'b1, "Test 11");
tbassert(Y_bar == 1'b0, "Test 11");
#0
// while enabled: change to select 000 from select 100
Select = 3'b000;
#10
tbassert(Y == 1'b0, "Test 12");
#0
// select 000: disabled
Enable_bar = 1'b1;
#6
tbassert(Y == 1'b0, "Test 13");
#0
// select 010: disabled
Select = 3'b010;
#10
tbassert(Y == 1'b0, "Test 14");
#0
// select 010: enabled and change to different inputs with null effect on output 0
Enable_bar = 1'b0;
D = 5'b00000;
#10
tbassert(Y == 1'b0, "Test 15");
tbassert(Y_bar == 1'b1, "Test 15");
#0
// select 100: enabled with null change to output 0
Select = 3'b100;
#10
tbassert(Y == 1'b0, "Test 16");
tbassert(Y_bar == 1'b1, "Test 16");
#0
// select 100: output bit transitions from previous, direct from inputs
D = 5'b11111;
#6
tbassert(Y == 1'b1, "Test 17");
tbassert(Y_bar == 1'b0, "Test 17");
#0
// output bit transitions from previous, direct from select 001
D = 5'b00010;
#10
tbassert(Y == 1'b0, "Test 18");
Select = 3'b001;
#6
tbassert(Y == 1'b1, "Test 18");
tbassert(Y_bar == 1'b0, "Test 18");
#0
// select 001: output bit transitions from previous, on disable
Enable_bar = 1'b1;
#10
tbassert(Y == 1'b0, "Test 19");
tbassert(Y_bar == 1'b1, "Test 19");
#0
// select 001: enabled and change to different inputs with null effect on output 1
Enable_bar = 1'b0;
#10
tbassert(Y == 1'b1, "Test 20");
tbassert(Y_bar == 1'b0, "Test 20");
D = 5'b11110;
#10
tbassert(Y == 1'b1, "Test 20");
tbassert(Y_bar == 1'b0, "Test 20");
#0
// change to select 010 from select 001 and change to different inputs with null effect on
// output 1
Select = 3'b010;
D = 5'b10101;
#10
tbassert(Y == 1'b1, "Test 21");
tbassert(Y_bar == 1'b0, "Test 21");
#0
// change to select 011 from select 010 and change to different inputs with null effect on
// output 1
Select = 3'b011;
D = 5'b01010;
#10
tbassert(Y == 1'b1, "Test 22");
tbassert(Y_bar == 1'b0, "Test 22");
#0
// the following set of tests show the implementer is responsible for valid range of input
// when the WIDTH_IN parameter is set for this device
// select invalid (101), with input ones -> output is not driven
Enable_bar = 1'b0;
Select = 3'b101;
D = 5'b11111;
#10
tbassert(Y === 1'bx, "Test 23");
tbassert(Y_bar === 1'bx, "Test 23");
#0
// select invalid (111), with input zeroes -> output is not driven
Enable_bar = 1'b0;
Select = 3'b111;
D = 5'b00000;
#10
tbassert(Y === 1'bx, "Test 24");
tbassert(Y_bar === 1'bx, "Test 24");
#10
$finish;
end
endmodule
|