Lec03 Testbench and Pattern
Lec03 Testbench and Pattern
Lecturer: Yu-Wei Lu
ICLAB NCTU Institute of Electronics 1
Outline
Section 2- Pattern
Section 3- Testbench
Section 4- Environment
Section 2- Pattern
Section 3- Testbench
Section 4- Environment
Steps of verification
Generate stimulus
Apply stimulus to DUT (Design Under Test)
Capture the response
Check for correctness
Measure progress against overall verification goal
Data flow
DESIGN.v (./01_RTL)
Design under test (DUT)
PATTERN.v (./00_TESTBED)
Pattern TESTBED.v
Test program
DESIGN.v PATTERN.v
(module) (module)
Section 2- Pattern
Section 3- Testbench
Section 4- Environment
C C
C C C C
100%
Random
Coverage
test
Directed
test
Time
Generate stimulus
Check result
integer SEED;
reg[3:0] number;
SEED = 123; Same ?
number = $random(SEED) % ;
Correct
5
integer SEED;
reg[3:0] number;
SEED = 123;
number = $random(SEED) % ;
file = $fopen("
file2 = $fopen
file3 = $fopen
file = $fopen
file2 = $fopen
file3 = $fopen
$readmemb, $readmemh
$readmemb("file_name", memory_name [ , start_address [ , end_address ]] );
$readmemh("file_name", memory_name [ , start_address [ , end_address ]] );
Appendix
initial
begin
end
Always Blocks
Will be executed if the condition is met
always@(condition_expression)
begin
end
Task
A task is typically used to perform debugging operations, or to
behaviorally describe hardware.
Function
A function is typically used to perform a computation, or to represent
combinational logics.
Function
always execute in 0 simulation time
Simplified Syntax
task identifier;
parameter_declaration;
input_decleration;
output_decleration;
inout_declaration;
register_declaration;
begin
statement;
end
endtask
Simplified Syntax
begin
statement;
end
endfunction
always@(posedge CLK)
sum = add(a,b);
Clock signal
Clock signal should be forced to 0 before reset signal is given.
Using always procedure to produce a duty cycle 50% clock signal
Example:
reg clk, rst_n;
real CYCLE = 2.5;
initial clk = 0;
always #(CYCLE/2.0) clk = ~clk;
initial begin
rst_n
force clk =0;
#(0.5); rst_n
#(10); rst_n
#(3); release clk;
end
Section 2- Pattern
Section 3- Testbench
Section 4- Environment
TESTBED.v
DESIGN.v PATTERN.v
(module) (module)
A compiler directive
Specifies the unit of measurement for time and the degree of
precision of the time
Syntax:
Note: if you use memory in your design, you should set timescale according to the
timescale specified by memory file
$fsdbDumpvars
depth: level of waveform to be dumped
instance: module to be dumped
mda
Option
IO_only port signals will be dumped.
Reg_only only reg type signals will be dumped.
initial begin
`ifdef RTL
$fsdbDumpfile Design.fsdb");
$fsdbDumpvars(0,"+mda");
`endif
`ifdef GATE
$fsdbDumpfile Design_SYN.fsdb");
$fsdbDumpvars(0,"+mda");
$sdf_annotate("CORE_SYN.sdf",dut);
`endif
end
Section 2- Pattern
Section 3- Testbench
Section 4- Environment
01_RTL
RTL code functionality simulation
02_SYN
Circuit synthesize
03_GATE
Gate level simulation
04_MEM
05_APR
06_POST
ICLAB NCTU Institute of Electronics 48
00_TESTBED & 01_RTL
00_TESTBED:
TESTBED.v
PATTERN.v
01_RTL:
DESIGN.v
01_run: irun TESTBED.v -define RTL -debug
Link:
PATTERN.v & TESTBED.v
03_GATE:
01_run:
Link:
DESIGN_SYN.v & DESIGN_SYN.sdf
Result