forked from TimRudy/ice-chips-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7474-tb.v
537 lines (519 loc) · 12.2 KB
/
7474-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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
// Test: Dual D flip-flop with set and clear; positive-edge-triggered
module test;
`TBASSERT_METHOD(tbassert)
localparam BLOCKS = 3;
// DUT inputs
reg [BLOCKS-1:0] Preset_bar;
reg [BLOCKS-1:0] Clear_bar;
reg [BLOCKS-1:0] D;
reg [BLOCKS-1:0] Clk;
// DUT outputs
wire [BLOCKS-1:0] Q;
wire [BLOCKS-1:0] Q_bar;
// DUT
ttl_7474 #(.BLOCKS(BLOCKS), .DELAY_RISE(5), .DELAY_FALL(3)) dut(
.Preset_bar(Preset_bar),
.Clear_bar(Clear_bar),
.D(D),
.Clk(Clk),
.Q(Q),
.Q_bar(Q_bar)
);
initial
begin
$dumpfile("7474-tb.vcd");
$dumpvars;
// the following set of tests are for: load
#65
// initial state
tbassert(Q === 3'bxxx, "Test 1");
tbassert(Q_bar === 3'bxxx, "Test 1");
#0
// load all zeroes, the clock input takes on a value
Clk = 3'b000;
#7
tbassert(Q === 3'bxxx, "Test 1");
tbassert(Q_bar === 3'bxxx, "Test 1");
#0
// load all zeroes, set up the data
D = 3'b000;
#25
tbassert(Q === 3'bxxx, "Test 1");
tbassert(Q_bar === 3'bxxx, "Test 1");
#0
// load all zeroes, not enough time for output to fall/rise
Clk = 3'b111;
#2
tbassert(Q === 3'bxxx, "Test 1");
tbassert(Q_bar === 3'bxxx, "Test 1");
#5
// load all zeroes -> output 0s
tbassert(Q == 3'b000, "Test 1");
tbassert(Q_bar == 3'b111, "Test 1");
#140
// hold state
Clk = 3'b000;
#175
tbassert(Q == 3'b000, "Test 2");
tbassert(Q_bar == 3'b111, "Test 2");
#0
// load all ones, set up the data
D = 3'b111;
#125
tbassert(Q == 3'b000, "Test 3");
tbassert(Q_bar == 3'b111, "Test 3");
#0
// load all ones, not enough time for output to rise/fall
Clk = 3'b111;
#2
tbassert(Q == 3'b000, "Test 3");
tbassert(Q_bar == 3'b111, "Test 3");
#5
// load all ones -> output 1s
tbassert(Q == 3'b111, "Test 3");
tbassert(Q_bar == 3'b000, "Test 3");
#50
// hold state
Clk = 3'b000;
#125
tbassert(Q == 3'b111, "Test 4");
tbassert(Q_bar == 3'b000, "Test 4");
#0
// hold state, the clear input takes on a value
Clear_bar = 3'b111;
#50
tbassert(Q == 3'b111, "Test 4");
tbassert(Q_bar == 3'b000, "Test 4");
#0
// hold state, the preset input takes on a value
Preset_bar = 3'b111;
#50
tbassert(Q == 3'b111, "Test 4");
tbassert(Q_bar == 3'b000, "Test 4");
#0
// load 010, set up the data
D = 3'b010;
#15
// load 010, apply clock edge in first block separately -> output 110
Clk[0] = 1'b1;
#7
tbassert(Q == 3'b110, "Test 5");
tbassert(Q_bar == 3'b001, "Test 5");
#25
// load 010, apply clock edge in second block separately -> output 110
Clk[1] = 1'b1;
#7
tbassert(Q == 3'b110, "Test 6");
tbassert(Q_bar == 3'b001, "Test 6");
#25
// load 010, apply clock edge in third block separately -> output 010
Clk[2] = 1'b1;
#7
tbassert(Q == 3'b010, "Test 7");
tbassert(Q_bar == 3'b101, "Test 7");
#140
// hold state, end clock pulse in second block separately
Clk[1] = 1'b0;
#7
tbassert(Q == 3'b010, "Test 8");
tbassert(Q_bar == 3'b101, "Test 8");
#10
// hold state, end clock pulse in first block separately
Clk[0] = 1'b0;
#7
tbassert(Q == 3'b010, "Test 8");
tbassert(Q_bar == 3'b101, "Test 8");
#10
// hold state, end clock pulse in third block separately
Clk[2] = 1'b0;
#50
tbassert(Q == 3'b010, "Test 8");
tbassert(Q_bar == 3'b101, "Test 8");
#0
// the following set of tests are for: clear
// clear from 010, not enough time for output to fall/rise
Clear_bar = 3'b000;
#2
tbassert(Q == 3'b010, "Test 9");
tbassert(Q_bar == 3'b101, "Test 9");
#5
// clear from 010 -> output 0s
tbassert(Q == 3'b000, "Test 9");
tbassert(Q_bar == 3'b111, "Test 9");
#150
// hold state -> remains clear after clear signal ends
Clear_bar = 3'b111;
#120
tbassert(Q == 3'b000, "Test 10");
tbassert(Q_bar == 3'b111, "Test 10");
#50
// load new value
D = 3'b011;
#15
Clk = 3'b111;
#15
Clk = 3'b000;
#15
tbassert(Q == 3'b011, "Test 11");
tbassert(Q_bar == 3'b100, "Test 11");
#0
// set up different data input value
D = 3'b010;
#15
// clear from 011 in contention with load (at clock edge in second and third blocks)
Clear_bar = 3'b000;
Clk = 3'b110;
#2
tbassert(Q == 3'b011, "Test 11");
tbassert(Q_bar == 3'b100, "Test 11");
#5
// clear from 011 in contention with load -> output 0s
tbassert(Q == 3'b000, "Test 11");
tbassert(Q_bar == 3'b111, "Test 11");
#10
// clear from 011, apply clock edge in first block separately with null effect on output
Clk[0] = 1'b1;
#7
tbassert(Q == 3'b000, "Test 11");
tbassert(Q_bar == 3'b111, "Test 11");
#150
// hold state, second block -> remains clear after clear signal ends
Clear_bar[1] = 1'b1;
#20
tbassert(Q == 3'b000, "Test 12");
tbassert(Q_bar == 3'b111, "Test 12");
#0
// hold state, first block
Clear_bar[0] = 1'b1;
#7
tbassert(Q == 3'b000, "Test 12");
tbassert(Q_bar == 3'b111, "Test 12");
#10
// hold state, third block
Clear_bar[2] = 1'b1;
#70
tbassert(Q == 3'b000, "Test 12");
tbassert(Q_bar == 3'b111, "Test 12");
#0
// hold state, end clock pulse in first and third blocks
Clk = 3'b010;
#70
tbassert(Q == 3'b000, "Test 12");
tbassert(Q_bar == 3'b111, "Test 12");
#0
Clk[1] = 1'b0;
#50
// load new value
D = 3'b111;
#15
Clk = 3'b111;
#15
Clk = 3'b000;
#15
tbassert(Q == 3'b111, "Test 13");
tbassert(Q_bar == 3'b000, "Test 13");
#0
// set up different data input value
D = 3'b110;
#15
// clear third block separately -> output 011
Clear_bar[2] = 1'b0;
#20
tbassert(Q == 3'b011, "Test 13");
tbassert(Q_bar == 3'b100, "Test 13");
#0
Clear_bar[2] = 1'b1;
#50
// load new value
D = 3'b111;
#15
Clk = 3'b111;
#15
Clk = 3'b000;
#15
tbassert(Q == 3'b111, "Test 14");
tbassert(Q_bar == 3'b000, "Test 14");
#0
// clear first and second blocks separately in contention with load (at clock edge in
// second block)
Clear_bar[0] = 1'b0;
Clear_bar[1] = 1'b0;
// D = 3'b111;
Clk[1] = 1'b1;
#2
tbassert(Q == 3'b111, "Test 14");
tbassert(Q_bar == 3'b000, "Test 14");
#5
// clear first and second blocks separately in contention with load -> output 100
tbassert(Q == 3'b100, "Test 14");
tbassert(Q_bar == 3'b011, "Test 14");
#10
Clear_bar = 3'b111;
#25
tbassert(Q == 3'b100, "Test 14");
tbassert(Q_bar == 3'b011, "Test 14");
#0
// the following set of tests are for: clear from initial state
// set up the data for initial state
D = 3'bxxx;
#15
// load to initial state
Clk = 3'b000;
#15
Clk = 3'b111;
#15
tbassert(Q === 3'bxxx, "Test 15");
tbassert(Q_bar === 3'bxxx, "Test 15");
#0
// set up the control inputs for initial state
Preset_bar = 3'bxxx;
Clear_bar = 3'bxxx;
Clk = 3'bxxx;
#15
// clear from initial state, not enough time for output to fall/rise
Clear_bar = 3'b000;
#2
tbassert(Q === 3'bxxx, "Test 15");
tbassert(Q_bar === 3'bxxx, "Test 15");
#5
// clear from initial state -> output 0s
tbassert(Q == 3'b000, "Test 15");
tbassert(Q_bar == 3'b111, "Test 15");
#75
// hold state -> remains clear after clear signal ends
Clear_bar = 3'b111;
#80
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#0
// hold state, the preset input takes on a value
Preset_bar = 3'b111;
#50
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#0
D = 3'b000;
#15
// hold state, the clock inputs take on values, each separately
Clk[0] = 1'b1;
#15
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#0
Clk[1] = 1'b1;
#7
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#10
Clk[2] = 1'b0;
#15
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#0
Clk[1] = 1'b0;
#0
// hold state, apply clock edge in third block, load same value appearing at the output
// with null effect on output
Clk[2] = 1'b1;
#15
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#0
// hold state, end clock pulses in each block
Clk[0] = 1'b0;
#7
tbassert(Q == 3'b000, "Test 16");
tbassert(Q_bar == 3'b111, "Test 16");
#7
Clk[2] = 1'b0;
#0
// the following set of tests are for: preset from initial state
// set up the data for initial state
D = 3'bxxx;
#15
// load to initial state
Clk = 3'b000;
#15
Clk = 3'b111;
#15
tbassert(Q === 3'bxxx, "Test 17");
tbassert(Q_bar === 3'bxxx, "Test 17");
#0
// set up the control inputs for initial state
Preset_bar = 3'bxxx;
Clear_bar = 3'bxxx;
Clk = 3'bxxx;
#15
// preset from initial state, not enough time for output to rise/fall
Preset_bar = 3'b000;
#2
tbassert(Q === 3'bxxx, "Test 17");
tbassert(Q_bar === 3'bxxx, "Test 17");
#5
// preset from initial state -> output 1s
tbassert(Q == 3'b111, "Test 17");
tbassert(Q_bar == 3'b000, "Test 17");
#75
// hold state -> remains preset after preset signal ends
Preset_bar = 3'b111;
#80
tbassert(Q == 3'b111, "Test 18");
tbassert(Q_bar == 3'b000, "Test 18");
#0
D = 3'b111;
#15
// hold state, the clock inputs take on values, each separately
Clk[0] = 1'b1;
#15
tbassert(Q == 3'b111, "Test 18");
tbassert(Q_bar == 3'b000, "Test 18");
#0
Clk[2] = 1'b0;
#7
tbassert(Q == 3'b111, "Test 18");
tbassert(Q_bar == 3'b000, "Test 18");
#10
Clk[1] = 1'b1;
#15
tbassert(Q == 3'b111, "Test 18");
tbassert(Q_bar == 3'b000, "Test 18");
#0
// hold state, apply clock edge in third block, load same value appearing at the output
// with null effect on output
Clk[2] = 1'b1;
#15
tbassert(Q == 3'b111, "Test 18");
tbassert(Q_bar == 3'b000, "Test 18");
#0
// hold state, the clear input takes on a value
Clear_bar = 3'b111;
#0
// hold state, end clock pulses in each block
Clk[0] = 1'b0;
Clk[1] = 1'b0;
#7
tbassert(Q == 3'b111, "Test 18");
tbassert(Q_bar == 3'b000, "Test 18");
#10
Clk[2] = 1'b0;
#50
// load new value
D = 3'b000;
#15
Clk = 3'b111;
#15
Clk = 3'b000;
#15
tbassert(Q == 3'b000, "Test 19");
tbassert(Q_bar == 3'b111, "Test 19");
#0
// set up different data input value
D = 3'b010;
#15
// preset third block separately -> output 100
Preset_bar[2] = 1'b0;
#20
tbassert(Q == 3'b100, "Test 19");
tbassert(Q_bar == 3'b011, "Test 19");
#0
// preset first and second blocks separately in contention with load (at clock edge in
// first and second blocks)
Preset_bar[0] = 1'b0;
Preset_bar[1] = 1'b0;
// D = 3'b010;
Clk[0] = 1'b1;
Clk[1] = 1'b1;
#2
tbassert(Q == 3'b100, "Test 20");
tbassert(Q_bar == 3'b011, "Test 20");
#5
// preset first and second blocks separately in contention with load -> output 1s
tbassert(Q == 3'b111, "Test 20");
tbassert(Q_bar == 3'b000, "Test 20");
#15
Preset_bar = 3'b111;
#25
tbassert(Q == 3'b111, "Test 20");
tbassert(Q_bar == 3'b000, "Test 20");
#15
Clk = 3'b000;
#0
// the following set of tests are for: hold state and applying clock edge in
// each block separately
// load new value
D = 3'b101;
#15
Clk = 3'b111;
#15
Clk = 3'b000;
#15
tbassert(Q == 3'b101, "Test 21");
tbassert(Q_bar == 3'b010, "Test 21");
#0
// load same value appearing at the output with null effect on output 101
// D = 3'b101;
#7
// apply clock edge in third block separately
Clk = 3'b100;
#20
tbassert(Q == 3'b101, "Test 21");
tbassert(Q_bar == 3'b010, "Test 21");
#0
// apply clock edge in second block separately
Clk = 3'b110;
#20
tbassert(Q == 3'b101, "Test 21");
tbassert(Q_bar == 3'b010, "Test 21");
#0
// apply clock edge in first block separately
Clk = 3'b111;
#20
tbassert(Q == 3'b101, "Test 21");
tbassert(Q_bar == 3'b010, "Test 21");
#0
Clk = 3'b000;
#15
// transient (unclocked) change to data input with null effect on output
Clk = 3'b111;
#7
D = 3'b011;
#75
tbassert(Q == 3'b101, "Test 22");
tbassert(Q_bar == 3'b010, "Test 22");
#0
Clk = 3'b000;
#25
// set up different data input value
D = 3'bzz0;
#50
tbassert(Q == 3'b101, "Test 22");
tbassert(Q_bar == 3'b010, "Test 22");
#0
// load new value in first block separately
D = 3'bz10;
#40
Clk = 3'b001;
#15
Clk = 3'b000;
#15
tbassert(Q == 3'b100, "Test 23");
tbassert(Q_bar == 3'b011, "Test 23");
#0
// load same value appearing at the output with null effect on output
D = 3'b100;
#7
// apply clock edge in first block separately
Clk = 3'b001;
#20
tbassert(Q == 3'b100, "Test 24");
tbassert(Q_bar == 3'b011, "Test 24");
#0
// apply clock edge in second and third blocks, end clock pulse in first block
Clk = 3'b110;
#40
tbassert(Q == 3'b100, "Test 25");
tbassert(Q_bar == 3'b011, "Test 25");
#50
$finish;
end
endmodule