Professional Documents
Culture Documents
-1-
Outline
Introduction to Verilog HDL
Verilog data types and models
Verilog test bench
Introduction to Verilog-XL simulator
Annotating SDF Timing
-2-
-3-
Re-use
Choice of tools, vendors
-4-
-5-
-6-
RTL
RTL
Level
Level
Verilog
Algorithm
RTL
Logic
Gate
Gate
Level
Level
vital
Gate
-7-
Structural (Gate-level)
Models components by connecting primitives or low-level
components (gates) for greater accuracy, especially in timing
Uses technology-specific, low-level components when mapping
from an RTL description to a gate-level netlist, such as during
synthesis
-82005 VLSI Training Course
a
out
b
sel
-9-
RTL model
Based on clock
RTL model must be accurate at the boundary of every
clocked elements
RTL level is appropriate for synthesis, so designers use RTL
to mean the synthesizable subset of behavioral Verilog
- 10 -
Overall Structure
Top module
No glue logic within top module
- 11 -
Outline
Introduction to Verilog HDL
Verilog data types and models
Verilog operations
Verilog data types
Verilog models
- 12 -
Module Definition
- 13 -
Number representation
<number>
<base><number>
<width><base><number>
base b, d, o ,h
- 14 -
Wired nets
wand, wor, triand, trior
trireg
tri0, tri1
Supply nets
supply0, supply1
- 15 -
Memories
array of register variables
Integers (32-bit)
integer
Time (64-bit)
time
Real numbers
real
Parameters
parameter
2005 VLSI Training Course
- 16 -
Operators (1/2)
Arithmetic operators
+, 1, *, /, %
Bit-wise operators
~, &, |, ^, ~^, ^~
- 17 -
Operators (2/2)
Reduction operators (unary)
&, |, ^, ~&, ~|, ~^, ^~
Conditional operator
?...:
Concatenations
{, }
- 18 -
Module Connectivity
Order list
Name
Better !!!
- 19 -
Parameters
Use parameters to declare run-time constants
You can use a parameter anywhere that you can use
a literal
Parameters are local, known only to the module in
which they are defined
module mod (in1, in2, out);
parameter cycle = 20, prop_del = 3,
setup = cycle/2 prop_del,
p1 = 8,
x_word = 16bx,
file = /usr1/jdough/design/mem_file.dat;
...
wire [p1:0] w1; // a wire declaration using parameter
...
endmodule
- 20 -
10
- 21 -
- 22 -
11
Register Arrays
You can declare an array of registers in Verilog
integer nums [7:0]; // array of 8 integer variables
time t_vals [3:0]; // array of 4 time variables
- 23 -
Memory Addressing
<<example>>
module mems;
reg [7:0] mema [0:255]; // declare memory called mema
reg [7:0] mem_word; // temp register called mem_word
...
initial
begin
// Display contents of the 6th memory address
$display(mema[5]);
// Display the MSB of the 6th memory word
mem_word = mema[5];
$displayb(mem_word[7]); // Display the MSB
end
endmodule
- 24 -
12
Behavioral Modeling
Event-driven procedures
always, initial
Sequential blocks
Begin...end
Parallel blocks
Fork...join
- 25 -
Procedure blocks
initial
always
- 26 -
13
- 27 -
Edge-Sensitive Timing
Example
Example
- 28 -
14
Conditional Statements
<<example>>
if (<expression>)
<statement_or_null>
if (index>0)
if (rega > regb)
result = rega;
else
result = regb;
if (<expression>)
<statement_or_null>
else
<statement_or_null>
if (index > 0)
begin
if (rega > regb)
result = rega;
end
else
result = regb;
- 29 -
<<example>>
if (<expression>)
<statement>
else if (<expression>)
<statement>
else if (<expression>)
<statement>
else
<statement>
case/casez/casex (<epression>)
<case_item>
endcase
2005 VLSI Training Course
- 30 -
15
Nonblocking Procedural
Assignment
Non-blocking
Non-blocking Assignment
Assignment
<<example>>
- 31 -
Continuous Assignments
Drive values onto nets, both vector and scalar
The assignment is always active
Provide a way to model combinational logic
without specifying an interconnection of gates
Can make continuous assignments explicit or implicit
/* Better !!! */
wire out;
assign out = a & b; //explicit
/* not the best choice */
wire out = a & b //implicit
- 32 -
16
- 33 -
Function
Is typically used to perform a computation, or to represent
combinational logic
- 34 -
17
Verilog Tasks
<<example>>
module mult (clk, a, b, out, en_mult);
input clk, en_mult;
input [3:0] a, b;
output [7:0] out;
reg [7:0] out;
always @ (posedge clk)
multme (a, b, out); // task invocations
task multme; // task definition
input [3:0] xme, tome;
output [3:0] result;
wait (en_mult)
result = xme * tome;
endtask
endmodule
- 35 -
Verilog Functions
<<example>>
module foo (loo, goo);
input [7:0] loo;
output [7:0] goo;
// you can call a function from a continuous assignment
wire [7:0] goo = zero_count (loo);
function [3:0] zero_count // task definition
input [3:0] in_bus;
integer i;
begin
zero_count = 0;
for (i = 0; i < 8; i = i + 1)
if (!in_bus[i])
zero_count = zero_count + 1;
end
endfunction
endmodule
- 36 -
18
- 37 -
Text Substitution
The `define compiler directive provides a simple
text-substitution facility.
`define <macro_name> <macro_text>
Example
`define D_NOT #1
`define D_AND #2
`define D_OR #1
module mux2to1 (a, b, sel, out);
input a, b, sel;
output out;
not `D_NOT not1(sel_, sel);
and `D_AND and1(a1, a, sel_);
and `D_AND and2(b1, b, sel);
or `D_OR or1(out, a1, b1);
endmodule
- 38 -
19
Text Inclusion
Use the `include compiler directive to insert the
contents of an entire file
`include global.v
`include parts/count.v
`include ../../library/mux.v
- 39 -
Timescale
`timescale compiler directive declares the time
unit and precision
`timescale <time_unit>/<time_precision>
`timescale 1ns/100ps
2005 VLSI
`timescale 1ns/10ps
// All time units are in multiples of 1 nanosecond
module mux2to1 (a, b, sel, out);
input a, b, sel;
output out;
not #1 not1(sel_, sel);
and #2 and1(a1, a, sel_);
and #2 and2(b1, b, sel);
or #1 or1(out, a1, b1);
endmodule
- 40 Training Course
20
Outline
Introduction to Verilog HDL
Verilog data types and models
Verilog test bench
Introduction to Verilog-XL simulator
Annotating SDF Timing
- 41 -
Design to verify
Simple
Simple test
test bench
bench
Testbench
Design to verify
Sophisticated
Sophisticated test
test bench
bench
- 42 -
21
Test Fixture
module testfixture;
// data type declaration
reg [7:0] a, b;
reg sel;
wire [7:0] out;
// instantiate modules
mux2to1 test_mux (.a(a),
.b(b),
.sel(sel),
.out(out));
// apply stimulus
// display results
endmodule
- 43 -
- 44 -
22
Action
$dumpfile(file.dump);
$dumpvars();
$dumpflush;
$dumpoff;
Stop recording
$dumpon;
$dumplimit(<file_size>);
$dumpall;
- 46 -
23
Dumping Signals
Supply levels and scope arguments to $dumpvars
$dumpvars; // Dump all signals in the hierarchy
$dumpvars (1, top); // Dump all signals in module top
//Dump signals in instance top.u1 and its subscope
$dumpvars (2, top.u1);
//Dump signals in top.u2 and below, and signal top.u1.u13.q
$dumpvars (0, top.u2, top.u1.u13.q);
//Dump signals in top.u1 and top.u2, and in all their subscopes of them, two level down
$dumpvars (3, top.u2, top.u1)
- 47 -
$readmemh
$readmemh(file_name,<memory_name>);
$readmemh(file_name,<memory_name>,<start_addr>);
$readmemh(file_name,<memory_name>,<start_addr>,<finish_addr>);
- 48 -
24
00000000
Text File
01100001
mem_file.txt
11111100
256
11100010
1023
...
00110010
...
0000_0000
0110_0001 0011_0010
// addresses 3-255 are not defined
@100 //hex
1111_1100
/* addresses 257-1022 are not defined */
@3FF
1110_0010
- 49 -
- 50 -
Example
Example
25
- 51 -
In Line Stimulus
Variable can be listed only when their values change
Complex timing relationship are easy to define
A test bench can become very large for complex
tests
module inline_tb;
reg [7:0] data_bus, addr;
wire [7:0] results;
DUT u1 (data_bus, addr, results);
initial
fork
data_bus = 8h00;
addr = 8h3f;
#10 data_bus = 8h45;
#15 addr = 8hf0;
#40 data_bus = 8h0f;
#60 $finish;
join
endmodule
Example
Example
- 52 -
26
- 53 -
Example
Example
- 54 -
Example
Example
27
module read_file_tb;
parameter num_vecs = 256;
reg [7:0] data_bus, stim[0:num_vecs-1:0];
wire [7:0] results
integer i ;
DUT u1 (data_bus, results);
initial
begin // Vectors are loaded
$readmemb(vec.txt, stim);
for (i = 0; i < num_vecs; i = i + 1)
#50 data_bus = stim[i];
end
endmodule
Example
Example
- 55 -
Outline
Introduction to Verilog HDL
Verilog data types and models
Verilog test bench
Introduction to VerilogVerilog-XL simulator
Annotating SDF Timing
- 56 -
28
Simulation Algorithms
There are three broad categories of simulation
algorithm
Time-based (used by SPICE simulators)
Event-based (used by Verilog-XL and NC-Verilog simulators)
Cycle-based
- 57 -
Simulation
- 58 -
29
Invoking Verilog-XL
Syntax
verilog [verilog-xl_operations] design_files
run.f
mux.v
test.v
-c
- 59 -
Outline
Introduction to Verilog HDL
Verilog data types and models
Verilog test bench
Introduction to Verilog-XL simulator
Annotating SDF Timing
- 60 -
30
Delay Calculators
Two categories of delay calculators
Delay calculators embedded in the tools
Custom delay calculators
User-defined
Vendor-supplied
- 61 -
- 62 -
31
SDF Annotator
Use the $sdf_annotate system task to annotate
SDF timing information
You can invoke this task interactively or from within
the source code
$sdf_annotate(sdf_file,[module_instance,
config_file, log_file, mtm_spec,
scale_factors, scale_type]);
Example
Example
- 63 -
module top;
...
cpu u1 (...);
fpu u2 (...);
dma u3 (...);
...
initial
begin
$sdf_annotate(sdffiles/cpu.sdf,m1,,logfiles/cpu_sdf.log);
$sdf_annotate(sdffiles/fpu.sdf,m1,,logfiles/fpu_sdf.log);
$sdf_annotate(sdffiles/dma.sdf,m1,,logfiles/dma_sdf.log);
end
...
endmodule
Example
Example
- 64 -
32
Reference
1. , CIC: Verilog Training Manual, July. 2004
- 65 -
33