Académique Documents
Professionnel Documents
Culture Documents
Advantages
Speeds up verification and results in early tape out of the chip. Less man power is required, by which the over all cost of the project will be low. Environment can be reusable. Easy tracking of verification progress(functional coverage). Developing self checking testbench is very interesting.
1. A device under test, called a DUT. This is what your testbench is testing.
Simple testbench
module mux_tb(); wire c; reg a,b,s; mux m1(c, a, b, s) ; initial begin a=1'b0; b=1'b0; s=1'b0; #5 a=1'b1; #5 s=1'b1; #5 $finish; // The $finish call ends simulation. end initial begin $dumpfile("mux_tb.dump"); $dumpvars (0,mux_tb); end endmodule
Parameter definition
Parameterize items in your test bench - this makes it much easier for you and others to read and understand your testbench Commonly parameterized items are as follows.
Insert parameter
module mux_tb(); parameter finishtime= 5 ; wire c; reg a,b,s; mux m1(c, a, b, s) ; initial begin a=1'b0; b=1'b0; s=1'b0; #5 a=1'b1; #5 s=1'b1; #finishtime $finish; // The $finish call ends simulation.
Preprocessor Directives
A preprocessor directive works in a very similar fashion to a parameter. It is essentially a variable that gets replaced when encountered. It is typically used for variables you want GLOBAL to all modules . cver mux_tb.v +define+DELAY=10
10
:timescale:
`timescale 10ns/100ps; #5.46734 i=1; 5.46834*10=54.6834 Resolution is 0.1ns Delay will be 54.6 but verilog rounded this delay to 54.7
12
Timescale directive
`timescale 10ns/1ps ; module tim(); reg i; initial begin i=0; #7.7212; i=1; $display("STATEMENT 1 :: time is ",$time); end endmodul Output: STATEMENT 1 :: time is 8
13
`timescale 10ns/1ps; module try; reg i; initial begin i=0; #7.7212; i=1; $display("STATEMENT 1 :: delay for %0t",$time ); $display("STATEMENT 2 :: delay for %0t",$realtime); end endmodule output:
14
Include statements
Include statements are similar to C style include statements. They allow a another file to be a part of the current file. They are commonly used to include a file with the timescale directive. They can also be used outside of testbenches, often for global constants.
15
16
17
DUT Instantiation
Connecting by ordered list mux m1(c, a, b, s); Connecting by port names mux m1(.c(c), .a(a), .b(b), .select(s)); Named ports do not depend on the port order , depends only on port name. It's a more portable way of instantiating modules. Now the local variable s, is connected to the port select inside the module. the named port
18
19
Debug output
`include "globals.v" module mux_tb(); parameter finishtime= 5 ; integer N; wire c; reg [2:0] test_vectors; // 3-bit wide test vector mux m1(.c(c), .a(test_vectors[2]), .b(test_vectors[1]), .select(test_vectors[0])); initial begin // initialize all variables $monitor ("TIME = %d, test_vectors= %b, c= %b", $time, test_vectors, c); test_vectors = 3b000; end initial begin for(N=0; N<7; N=N+1) #`DELAY test_vectors = test_vectors + 1; #finishtime // everything below will printout after finishtime expires $display ("Time is - %d",$time); $finish; end endmodule
20
The output of this testbench will be: TIME = 0, test_vectors= 000, c= 0 TIME = 5, test_vectors= 001, c= 0 TIME = 10, test_vectors= 010, c= 1 TIME = 15, test_vectors= 011, c= 0 TIME = 20, test_vectors= 100, c= 0 TIME = 25, test_vectors= 101, c= 1 TIME = 30, test_vectors= 110, c= 1 TIME = 35, test_vectors= 111, c= 1
21
Self-checking
it would be better if the test-bench could check itself and let us know if any test case has failed. At the top level testbench this is always preferred so that the waveforms do not have to be viewed.
1 0 10110 1
S0
000
S1
001
S2
010
S3
011
S4
100
0 0
0/1
23
THANK YOU