Verilog HDL Training Guide
Verilog HDL Training Guide
Verilog HDL
Training Guide
ࢪ: ᘽ Ꮂ
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
1. Introduction and Basic Concepts
Objectives
Understand the basics of Hardware Description Language (HDL) and
simulators.
Understand the verilog language and the verilog-XLTM software.
Introduce verilog structural and behavioral construct in a sample design.
Starting the verilog-XL software.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Key Features of HDLs
HDLs have high-level programming language constructs and constructs
to describe the connectivity of the circuit.
HDLs allow you to describe the design at various levels of abstractions.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Different Levels of Abstraction
Architecture / Algorithm .
RTL .
Gate .
Switch .
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Verilog HDL and Verilog-XL
Verilog and Verilog-XLTM are CADENCE trademarks.
Verilog HDL
Hardware description language that allows you to describe circuits at different
levels of abstractions and allow you to mix any level of abstraction in the
design.
Verilog-XL Software
High speed event-driven simulator that reads Verilog HDL and simulates the
description to emulate the behavior of real hardware.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Key Language Features
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Key Language Features (continued)
input d,clk,clr;
output q,qb;
d q
DFF
clk q
b
endmodule
clr
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Key Language Features (continued)
Module Instance
module REG4 (d,clk,clr,q,qb);
REG4
output [3:0] q,qb;
d clk clr input [3:0] d; input clk,clr;
DFF d0 (d[0],clk,clr,q[0],qb[0]);
DFF d1 (d[1],clk,clr,q[1],qb[1]);
DFF0 DFF3 DFF d2 (d[2],clk,clr,q[2],qb[2]);
DFF d3 (d[3],clk,clr,q[0],qb[3]);
endmodule
q q
b
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
A Simple and Complete Example
a a1 gr_waves
gr_regs
Test Fixture sel c_Waves
Files out
b b1
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Device Under Test
mux.v
module MUX2_1 (out,a,b,sel);
MUX2_1
output out;
a input a,b,sel;
a1
not (sel_,sel); and (a1,a,sel_);
sel
sel_ and (b1,b.sel);
out or (out,a1,b1);
b b1 endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Test Fixtures
testfixture.v
module testfixture; reg a,b,sel;
MUX2_1 mux (out,a,b,sel); initial input vectors
begin value input
a=0; b=1; sel=0;
#5 b=0; time a b sel
#5 b=1; sel=1;
#5 a=1; 0 0 1 0
end initial
$monitor ($time, ,out, ,a, ,b, ,sel); 5 0 0 0
endmodule
10 0 1 1
15 1 1 1
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Running and Results
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Procedural Blocks
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Starting the Verilog-XL Software
<command_line_options>
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Running and Results
% verilog –f run.f
run.f
fadder.v testfadder.v
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
2. Lexical Conventions and Data Types in Verilog
Objectives
Understand the lexical conventions used in the Verilog language.
Learn to recognize special language tokens. Learn the various classes of
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Comments
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Integer and Real Numbers
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Strings
Strings are enclosed in double quotes and must be specified on one line.
Verilog recognizes normal C-escape characters.
\t = tab
\n = newline
\\ = backslash
\” = quote mark ( “ )
%% = % sign
A new line using a carriage return can not be used in string.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Identifiers
Identifiers are user-provided names for Verilog objects within a
description.
Identifiers must begin with an alphabetical character (a~z, A~Z) or an
underscore (_) and can contain any alphanumeric character, dollar signs
($), and the underscore.
Identifiers can be up to 1023 characters long.
Names of modules, ports and instances are identifiers.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Case Sensitivity
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Special Language Tokens
System Tasks and Functions
$<identifier>
“$” sign denotes Verilog system tasks and functions
A number of system task and functions are available to perform different
operations like
-Finding the current simulation time ($time)
-Displaying / monitoring the values of the signals ($display, monitor)
-Stopping the simulation ($stop)
-Finishing the simulation ($finish)
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Special Language Tokens (continued)
Delay Specification
module testfixture; reg a,b,sel;
MUX2_1 mux (out,a,b,sel); initial
begin
a=0; b=1; sel=0;
#<delay specification> #5 b=0;
#5 b=1; sel=1;
The “#” character denotes the delay
#5 a=1;specification for both gate
instances and procedural statements.
end initial
$monitor ($time, ,out, ,a, ,b, ,sel);
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Compiler Directives
You indicate compiler directives with a grave accent (‘).
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Compiler Directives (continued)
Text Substitution
The ‘define compiler directive provides a sample text-substitution
facility.
‘define <name> <macro_text>
<name> will substitute <macro_text> at compile time.
‘define not_delay #1
......
.........
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Compiler Directives (continued)
Text Inclusion
Using the ‘inclusion compiler directive to insert the contents of an entire file.
Search directories for the file to be included can be specified using the +incdir
command-line option.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Timescale in Verilog
The ‘timescale compiler directive declares the time unit and its precision.
timescale <time_unit> / <time_precision>
‘timescale 1 ns / 100 ps
The ‘timescale compiler directive cannot appear inside a module
boundary.
‘timescale 1 ns / 100 ps
module MUX2_1 (out, a, b, sel);
.......
...........
...........
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Timescale in Verilog (continued)
‘timescale 1 ps / 100 fs
moduleN ( ... );
......
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
4-Value Logic System in Verilog
buf
Zero, Low, False, Logic Low, Ground, VSS,
“0”
Negative Assertion
buf
One, High, True, Logic High, Power, VDD,
“1”
VCC, Postive Assertion
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
4-Value Logic System in Verilog (continued)
bufif1
HiZ, High Impedance, Tri-Stated, Disabled
“Z”
Drived (Unknown)
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Major Data Type Classes
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Nets
MUX2_1
Nets
a a1
sel
sel_
out
b b1
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Registers
a a1
Reg_a
sel
Registers Reg_sel sel_
out
Reg_b b1
b
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Types of Registers
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Examples
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Choosing the Correct Data Type
Module Boundary
net
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Parameters
..............
wire [ p1:0] w1
.........
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Array of Instances
A range following an instance name creates an array of instances.
<name> <instance_name> <range> (<ports>);
module driver (out, in, en); output module driver (out, in, en); output
[2:0] out; [2:0] out;
input [2:0] in; input input [2:0] in; input
en; en;
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Verilog Operators
Unary ! ~ & | ^
Arithmetic * / % + -
Conditional ?:
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
3. Support for Verification
Objectives
Understand textural and graphic outputs from Verilog.
Understand different system function to read simulation time. Understand file
I/O in Verilog.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Support for Verification
Verilog has system functions to read the current simulation
$time
$stime
$realtime
Verilog has system tasks to support textual output
$display
$strobe
$write
$monitor
Verilog has system tasks to support graphic output
$gr_waves
$gr_regs cWaves
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Reading Simulation Time
The $time, $realtime, $stime functions return the current simulating time.
$time returns time as a 64-bit integer.
$stime returns time as a 32-bit integer.
$realtime returns time as a real number.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Displaying Signal Values
$display prints out the current values of the signals in the argument list.
$display automatically prints a new line.
$display supports different bases.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Displaying Signal Values (continued)
$write is identical to $display except that it does not print a new line
character.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Verilog Graphic Display
clk
load
cnt 00 01 02 1d 1e
Default in Hex.
Changing default setting
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Signal output to VCD file
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Signal output to VCD file
module fadder_test;
reg a,b,cin; wire sum,cout;
…
#10 a=0;b=1;cin=0;
… end
initial
Example:
begin
$dumpfile(“filename.vcd”);
$dumpvars();
end
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Gate Level Verilog for a Full Adder
endmodule
cout
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Behavior Level Verilog for a Full Adder
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Hierarchical Structure – Connection by Order List
top
module comp (o1, o2, i1, i2)
output o1, o2; In1 Out1
i1 o1
input i1, i2;
comp
… i2 o2
end In2 Out2
mod
ule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Hierarchical Structure – Connection by Name
module top (Out1, Out2, In1, In2); output module top (Out1, In1, In2);
Out1,Out2; output Out1; input In1, In2;
input In1, In2;
comp c1 (.i2(In2), .o1(Out1)
comp c1 (.i2(In2), .o1(Out1), .i1(In1));
.o2(Out2), .i1(In1)); endmodule
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
4. Behavior Modeling
Objectives
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Behavioral Modeling
Behavioral modeling enables you to describe the system at a high level of
abstraction.
Behavioral modeling in Verilog is described by specifying a set of
concurrently active procedural blocks.
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Behavioral Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Timing Control in Procedural Blocks
Simple Delay
#10 rega=regb ;
#(cycle/2) clk=~clk ; // cycle is declared as a parameter
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Timing Control in Procedural Blocks (continued)
0 10 30
50 70 90 110
clk
set
15 48 70
q
33 43 93 103
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Sequential Block vs. Parallel Block
c c c c
c c c c
c c c c
c c c c
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Sequential Block vs. Parallel Block
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Blocking vs. Non-Blocking Assignment
Block: “=“
Non-Block: “<=“
b=0; b<=0;
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
Blocking vs. Non-Blocking Assignment
b=1;
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]
References
CADENCE Verilog-XL User Guide
http://soc.eecs.yuntech.edu.tw/
E-Mail:[email protected]