8 - Test Bench System Verilog
8 - Test Bench System Verilog
Prepared By:
Jignesh Patoliya,
Sr. Assistant Professor,
EC Deparment, CSPIT,
CHARUSAT, Changa
Test bench
A test bench is a program used for exercising
and verifying the correctness of design.
Figure :
Figure
Figure
03/17/2023 Test bench 12
Alternate way of generating a clock
Generating clock with on-off width of 2.
module gen_clk_B(clk_B);
output clk_B;
reg start;
initial
begin
start=1;
#5 start=0;
end
nor #2(clk_B,start,clk_B);
endmodule
figure
03/17/2023 Test bench 14
Clock with start-up delay
figure
03/17/2023 Test bench 15
Phase-delayed clock
figure
03/17/2023 Test bench 16
System task:display
The display system task are used for displaying and
printing information.
These system task are further characterized into:
1. Display and write tasks.
2. Strobed monitoring.
3. Continuous monitoring.
Format
specification
Display taks:
Print with a end-of line character.
Executed at the time the statement is encountered.
$display
$displayb
$displayh
$displayo
Write task:
Print without a end-of-line character.
Write
writeb
writeh
writeo
Strobe task:
Execution of the strobe task is postponed to the
end of the time step, that means all events have
been processed for the specified time step.
$strobe
$strobeb
$strobeh
$strobeo
Example :
integer cool;
initial
begin
cool=1;
$display(“first assignment, cool %d”, cool);
$strobe(“when strobe is executed , cool %d”,
cool); //value hold at the end of time step.
03/17/2023 Test bench 22
System task-display [cont’d]
cool=2;
$display(“second assignment, cool %d”, cool);
end
Output:
first assignment, cool 1
second assignment, cool 2
when strobe is executed, cool 2 //take updated value
at the end of time step
03/17/2023 Test bench 23
System task-monitor
Similar in syntax to $display, but does not print
immediately.
It will print the value whenever the value of some
variable in the given list changes.
It has the functionality of event-driven print.
$monitor , $monitorb , $monitorh , $monitoro
$monitoron // enable all monitors.
$monitoroff // disable all monitors
$dumpoff;
This directive stop the dumpling of variables.
$dumpon;
This directive start previously stopped dumping of
variables.
$dumpall;
The current values of all variables will be written to
the file, irrespective of whether there has been any
changes in their values or not.
$dumplimit (file size);
Used to set the maximum size of the .vcd file.
03/17/2023 Test bench 26
Value change dump(VCD) [cont’d]
x=2’b01; y=2’b10;
#10 x=2’b10; y=2’b10;
#10 x=2’b01; y=2’b11;
end
initial
begin
$monitor(“t=%d”, x=%2b, y=%2b, z=%d”, $time, x, y, z);
end
endmodule
03/17/2023 Test bench 30
Example 2: 3x8 decoder
1. module Decoderr3x8( 14. if(a==3'b011)
2. input [2:0] a, 15. y=8'b00001000;
3. output [7:0] y 16. if(a==3'b100)
4. ); 17. y=8'b00010000;
5. reg [7:0] y; 18. if(a==3'b101)
6. always@(a) 19. y=8'b00100000;
7. begin 20. if(a==3'b110)
8. if(a==3'b000) 21. y=8'b01000000;
9. y=8'b00000001; 22. if(a==3'b111)
10. if(a==3'b001) 23. y=8'b10000000;
11. y=8'b00000010; 24. end
12. if(a==3'b010) 25.endmodule
13. y=8'b00000100;
03/17/2023 Test bench 31
TB:3x8 decoder
1. module tb; 12. // Initialize Inputs
2. // Inputs 13. a =3'b000; #100;
3. reg [2:0] a; 14. a =3'b001; #100;
4. // Outputs 15. a =3'b010; #100;
5. wire [7:0] y; 16. a =3'b011; #100;
6. // Instantiate the Unit Under 17. a =3'b100; #100;
Test (UUT) 18. a =3'b101; #100;
7. Decoderr3x8 uut ( 19. a =3'b110; #100;
8. .a(a), 20. a =3'b111; #100;
9. .y(y) 21. end
10. ); 22.
11.initial
03/17/2023
begin 23.endmodule
Test bench 32
Example 3: mux 4x1
1. module testbench;
2. reg [1:0] Select;
3. wire OUT;
4. integer i,j;
5. MUX_4x1 DUT (.I(INPUT), .Sel(Select), .MUX_Out(OUT));
6. initial
7. begin
8. for (i=0;i<16;i=i+1)
9. begin
10. for (j=0;j<4;j=j+1)
11. begin
12. {INPUT[0], INPUT[1], INPUT[2], INPUT[3]} = i;
13. {Select[0], Select[1]} = j;
14. #1;
03/17/2023 Test bench 33
Example 3: mux 4x1 [cont’d]
14. end
15. end
16. #5 $finish;
17. end
18. initial
19. begin
20. $dumpfile("df_4x1_mux_3.vcd");
21. $dumpvars;
22. end
26. endmodule