Verilog HDL Training Guide
Verilog HDL Training Guide
Verilog HDL
Training Guide
ࢪ: ᘽ Ꮂ
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Different Levels of Abstraction
Architecture / Algorithm .
RTL .
Gate .
Switch .
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Key Language Features
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Running and Results
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Procedural Blocks
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Starting the Verilog-XL Software
<command_line_options>
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Running and Results
% verilog –f run.f
run.f
fadder.v testfadder.v
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Comments
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Integer and Real Numbers
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Case Sensitivity
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Compiler Directives
You indicate compiler directives with a grave accent (‘).
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Timescale in Verilog (continued)
‘timescale 1 ps / 100 fs
moduleN ( ... );
......
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Major Data Type Classes
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Nets
MUX2_1
Nets
a a1
sel
sel_
out
b b1
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Registers
a a1
Reg_a
sel
Registers Reg_sel sel_
out
Reg_b b1
b
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Types of Registers
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Examples
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Choosing the Correct Data Type
Module Boundary
net
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Parameters
..............
wire [ p1:0] w1
.........
endmodule
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Verilog Operators
Unary ! ~ & | ^
Arithmetic * / % + -
Conditional ?:
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Signal output to VCD file
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Gate Level Verilog for a Full Adder
endmodule
cout
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Behavior Level Verilog for a Full Adder
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Outline
1. Introduction and Basic Concepts
4. Design Examples
5. Behavior Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
4. Behavior Modeling
Objectives
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Behavioral Modeling
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
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:kevinsu@yuntech.edu.tw
Sequential Block vs. Parallel Block
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Blocking vs. Non-Blocking Assignment
Block: “=“
Non-Block: “<=“
b=0; b<=0;
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
Blocking vs. Non-Blocking Assignment
b=1;
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw
References
CADENCE Verilog-XL User Guide
http://soc.eecs.yuntech.edu.tw/
E-Mail:kevinsu@yuntech.edu.tw