Professional Documents
Culture Documents
14 Verilog Testbenches PDF
14 Verilog Testbenches PDF
http://www.syssec.ethz.ch/education/Digitaltechnik_14
1
Adapted from Digital Design and Computer Architecture, David Money Harris & Sarah L. Harris ©2007 Elsevier
Carnegie Mellon
Applying inputs
2
Carnegie Mellon
3
Carnegie Mellon
4
Carnegie Mellon
Testbenches
HDL code written to test another HDL module, the device
under test (dut), also called the unit under test (uut)
Not synthesizeable
Types of testbenches:
Simple testbench
Self-checking testbench
Self-checking testbench with testvectors
5
Carnegie Mellon
Example
Write Verilog code to implement the following function in
hardware:
y = (b ∙ c) + (a ∙ b)
6
Carnegie Mellon
Example
Write Verilog code to implement the following function in
hardware:
y = (b ∙ c) + (a ∙ b)
module sillyfunction(input a, b, c,
output y);
7
Carnegie Mellon
Simple Testbench
module testbench1(); // Testbench has no inputs, outputs
reg a, b, c; // Will be assigned in initial block
wire y;
8
Carnegie Mellon
Simple Testbench
Simple testbench instantiates the design under test
9
Carnegie Mellon
Self-checking Testbench
module testbench2();
reg a, b, c;
wire y;
10
Carnegie Mellon
Self-checking Testbench
Better than simple testbench
11
Carnegie Mellon
Testbench:
Generate clock for assigning inputs, reading outputs
Read testvectors file into array
Assign inputs, get expected outputs from DUT
Compare outputs to expected outputs and report errors
12
Carnegie Mellon
SETUP
HOLD MARGIN MARGIN
Apply inputs Check outputs
after some before the next
delay from the clock edge
clock
Testvectors File
We need to generate a testvector file (somehow)
14
Carnegie Mellon
// generate clock
always // no sensitivity list, so it always executes
begin
clk = 1; #5; clk = 0; #5; // 10ns period
end
15
Carnegie Mellon
16
Carnegie Mellon
This is important
Inputs should not change at the same time with clock
17
Carnegie Mellon
18
Carnegie Mellon
19
Carnegie Mellon
Golden Models
A golden model represents the ideal behavior of your
circuit.
Still it has to be developed
It is difficult to get it right (bugs in the golden model!)
Can be done in C, Perl, Python, Matlab or even in Verilog
20
Carnegie Mellon
22