L07 Verilog - Testbenches
L07 Verilog - Testbenches
2
How Do You Know That A Circuit Work
• You have written the Verilog code of a circuit
– Does it work correctly?
– Even if the syntax is correct, it might do what you want?
– What exactly it is that you want anyway?
3
Why Should We “FIX” Bugs ASAP?
10
Design Under Test [DUT]
• The test bench applies stimulus to the DUT,
– Therefore must be instantiated in the test bench.
– A testbench typically does not have inputs or outputs!
Design Under
Pattern
Test
Generator
Process(es
)
Testbench
11
Recipe for Expressing Testbench in Verilog
1. Declare tb module with no interface,
– i.e module tb (); ….. end module
3. DUT Instantiation
4. Initialization:
– Signals are undefined at startup.
– Initialize any reg types in the design to a known value.
▪ Use initialize block
– Clock Generation:
▪ Use always block to generate clk
12
Example: Testbench
• Write Verilog code to implement the following function in
hardware:
13
Example: Testbench
module testbench(); // 1. Testbench has no inputs and outputs
reg a, b, c; // 2. inputs to the DUT are reg type
wire y; // 3. outputs from the DUT are wire type
14
Example: Testbench
• Simple testbench instantiates the design under test
15
Initial and Always blocks in TB
• Initial and Always blocks inside tb module:
– Always and initial blocks are two sequential control blocks
that operate on reg types in a Verilog simulation.
16
Other Helpful TB Constructs
• Generating clocks:
• $display
– is used to print to a line, and enter a carriage return at the
end.
– $display($time, "<< count = %d - Turning OFF count
enable >>",cnt_out);
17
Recommended Reading
• A Verilog HDL Test Bench Primer Application Note
– Uploaded on LMS
18
THANK YOU