Unit-V Verilog Hardware Description Language
Unit-V Verilog Hardware Description Language
Unit-V Verilog Hardware Description Language
HARDWARE DESCRIPTION
LANGUAGE
TOPICS
• Overview of digital design with Verilog HDL
• Hierarchical modeling concepts
• Modules and port definitions
• Gate level modeling
• Data flow modeling
• Behavioral modeling
• Tasks & functions
• Test bench
Overview of digital design with
Verilog HDL
Evolution of Computer Aided Digital Design
Digital ckt Designed with vacuum tube & transistors
●
●
Process
VLSI DESIGN FLOW
Process
VLSI DESIGN FLOW
Process
VLSI DESIGN FLOW
Process
VLSI DESIGN FLOW
Process
VLSI DESIGN FLOW
Process
Hierarchical modeling concepts
Design Methodologies
• Two basic types of design methodologies
– Top-down design
– Bottom-up design
Behavioral or algorithmic
level
Dataflow level
Switch level
Behavioral or algorithmic level
• This is the highest level of abstraction
provided by verilog HDL.
• Module can be implemented in terms of the
desired design algorithm without concern for
h/w implementation details.
• Very similar to C programming.
Dataflow level
• Module is designed by specifying the dataflow.
• The designer is aware of how data flows b/w
hardware reg’s & how data is processed in
design.
Gate level or structural
• Module is implemented in terms of logic gates
and interconnections b/w those gates.
• Similar to describing a design in terms of a
gate level logic diagram.
Modules and port definitions
Definition of Module
• Modules are the basic
building blocks in Verilog.
• Interface: port and
parameter declaration
• Body: Internal part of
module
• Add-ons (optional)
A simple Verilog Example
a
// A simple example comment line c
b
module and2 (a, b ,c); module name
port list
input a, b;
port declarations
output c;
• Port Declaration
Instances
• The process of creating objects from a module
template is called instantiation.
• The objects are called instances.
Components of simulation
• Design block
• Stimulus block
One language, Many Coding Style
One language, Many Coding Style
(contd.)
One language, Many Coding Style (contd.)
Behavioral style: Verilog Code
Dataflow style: Verilog Code
Structural style: Verilog Code
Basic concepts
Keywords
Module name Module ports
module Add_half ( sum, c_out, a, b );
input a, b;
Declaration of port
outputsum, c_out; modes
wire c_out_bar; Declaration of internal
signal
• Unsized numbers:
• X or Z values:
— 12 // decimal number 12
— `h12 // hex number 12 (18 decimal number)
—`o12 // octal number 12 (10 decimal number)
—`b1001 // binary number 1001 (9 decimal number)
Use of ?, X, Z, _ characters
— 8`h1? // 0001ZZZZ
— 2`b1? // 1Z
— 4`b10XX // 10XX
— 4`b100Z // 100Z
— 8`b1010_0011 // 10100011
Strings
• Sequence of characters that are enclosed by
double qoutes.
Identifiers
• Identifiers are names given to objects so that they can
be referenced in the design.
• --made up of a space-free sequence of uppercase and
lowercase letters from alphabet, digits (0,1,….9),
underscore (_), and the $ symbol.
• Verilog is a case sensitive language.
– c_out_bar and C_OUT_BAR are two different identifiers.
• The name of a variable may not begin with a digit or $,
and may be up to 1,024 characters long.
– e.g. clock_, state_3
2.Data Types
• Value set: verilog supports 4 values & 8
strengths to model the functionality of real
h/w.
• Four signal values:
Strength levels
Available signal values
—1 True
—0 False
—X Unknown
—Z High impedance
Logic operations on four-value signals
Truth table
AND 1 0 X Z
a
b c 1 1 0 X X
0 0 0 0 0
X X 0 X X
Z X 0 X X
Signal Classification
Each signal in Verilog belongs to either a net or a register
• Registers: Store
value even if
disconnected
Net declaration
Nets: Represents connections b/w h/w elements.
A net declaration starts with keyword wire
…… addr
wire r_w; // scalar signal
Processor
Memory
wire [7:0] data; // vector signal data
Processor
Memory
wire r_w; data[7:0]
wire [7:0] data; status[3:0]
wire [9:0] addr; r_w
…… i_o[7:0]
endmodule
Register declaration
A register declaration starts with keyword reg
……
reg done; // scalar signal
reg [7:0] count; // vector signal
……
Registers can be used to describe the behavior of sequential circuits
Example:
……
reg [7:0] myMem [3:0]; // It defines a memory with 4 locations and each
// location contains an 8-bit data
Bit 7 6 5 4 3 2 1 0
myMem[0]
myMem[1]
myMem[2]
myMem[3]
Using parameters
The use of parameters make code easy to read and modify
Example:
……
parameter bussize = 8;
reg [bussize-1 : 0] databus1;
reg [bussize-1 : 0] databus2;
……
• Strings: strings can be stored in reg.
3.System Tasks & Compiler
Directives
System Tasks
• Verilog provides std. system tasks to do certain
routine operations.
• Syntax: $<keyword>
• Operations: displaying on the screen,
monitoring values of nets, stopping, &
finishing.
Display information
• Usage: $display(p1,p2,p3,……,pn)
– p1, ,p2,p3,……,pn can be quoted strings or
variables or expressions.
e.g.
a
not (a, b, c) c
b
Predefined gate primitives
— tri-state gates: bufif1, bufif0, notif1, notif0
e.g. c
bufif1 (a, b, c) b a
c
e.g.
notif0 (a, b, c) a
b
— Example:
Example
Left Op. Right Op. === !== == !=
0110 0110 1 0 1 0
0110 0XX0 0 1 X X
0XX0 0XX0 1 0 X X
Logic operators
Logic operators:
— && (logic and), || (logic or), ! (logic not)
Operand A Operand B A&B A|B !A !B
1010 00 0 1 0 1
1010 011 1 1 0 0
Reducation operators:
— & (and), ~& (nand), | (or), ~| (nor), ^ (xor), ~^ (xnor)
Operand A &A ~&A |A ~|A ^A ~^A
1010 0 1 1 0 0 1
Shifter operators
<< : shift left
reg [3:0] A;
1 1 0 1 A << 2 0 1 0 0
reg [3:0] A;
1 1 0 1 A >> 2 0 0 1 1
Concatenation operators
Example
Data 1 1 0 1 0 0 0 0
c c
A[3:0] B[7:6]