Digital System Design Verilog: Using
Digital System Design Verilog: Using
Design
Using
Verilog
By:
Vimal Kant Pandey
By: Vimal Kant Pandey
Digital System Design
Using Verilog
Design Flow
Design
Specification
Gate Level
Netlist
Behavioral
Description
Logical
Verification
& Testing
RTL
Description
Floor
Planning
Automatic
Place &
Route
Functional
Verification
&
Testing
Logic
Synthesis
Physical
Layout
Layout
Verification
Implementatio
n
Design Methodologies
Subblock1
Leaf
cell
Leaf
cell
Subblock n
Sub-block
2
Leaf
cell
Leaf
cell
Leaf
cell
Leaf
cell
Bottom-Up Methodology
Top Level Block
MacroCell 1
Leaf
cell
Leaf
cell
MacroCell
2
Leaf
cell
MacroCell n
Leaf
cell
Leaf
cell
Leaf
cell
Basic Conventions
endmodule
Example
module T_ff (q, clk, reset);
..
..
<functionality T_ff>
..
..
endmodule
Levels of Abstraction
Verilog is both a behavioral and a
structural language.
Internals of each module can be
defined at four levels of abstraction,
depending on the needs of the
design.
The module behaves identically with
the
external
environment
irrespective
of
the
level
of
abstraction at which the module is
described.
By: Vimal Kant Pandey
Digital System Design
Using Verilog
Continued.
Behavioral Level:
Highest level of abstraction
Module can be implemented in terms of
the desired design algorithm without
concern
for
the
hardware
implementation details.
Very similar to C programming
Dataflow Level:
Module designed by specifying dataflow.
The designer is aware of how data flows
between hardware registers and how
Vimal Kant Pandey
Digital
System
Design
the data isBy:processed
in
the
design
9
Using Verilog
Continued.
Gate Level:
Module implemented in terms of logic
gates like (and ,or) and interconnection
between gates
Similar to the design in terms of gate
level logic diagram.
Switch Level:
Module implemented with switches and
interconnects.
Lowest level of Abstraction
By: Vimal Kant Pandey
Digital System Design
Using Verilog
10
Instance
A module provides a template from
which you can create actual objects.
When a module is invoked, Verilog
creates a unique object from the
template.
The process of creating a object from
module
template
is
called
instantiation.
The object is called instance.
By: Vimal Kant Pandey
Digital System Design
Using Verilog
11
Example
module ripple_carry_counter(q, clk,
reset);
output [3:01 ]q;
input clk, reset;
//Four instances of the module T-FF are
created.
T_FF tff0(q[0], clk, reset);
T-FF tffl(q[1] ,q[0], reset);
T-FF tff2 (q[2] ,q[1] , reset) ;
T-FF tff3(q[3] ,q[2], reset) ;
endmodule
/ / Define the module T_FF.
module T_FF(q, clk, reset) ;
output q;
input clk, reset;
wire d;
D_FF dff0 (q, d, clk, reset) ;
not n1(d, q);
Note: In Verilog nesting of modules is illegal
endmodule
By: Vimal Kant Pandey
Digital System Design
Using Verilog
12
Components of Simulation
Two styles of stimulus application is
possible.
13
Basic Concepts
Lexical Conventions
White Space: It comprises
Blank spaces (\b)
tabs (\t)
newlines (\n)
14
Continued..
Number Specification
Sized Number: Number is specified as
Decimal (d or D)
Hexadecimal (h or H)
Binary (b or B)
Octal (o or O)
15
Continued..
Unsized numbers
Numbers that are specified without a
<base format> specification are decimal
numbers by default.
Numbers that are written without a
<size> specification have a default
number of bits that is simulator- and
machine-specific (must be at least 32).
16
Continued..
X or Z Values
Negative Numbers
specified by putting a minus sign before
the size for aconstant number.
Size constants are always positive
17
Continued..
Underscore characters and question
marks
"-" is allowed anywhere in a number except the
first character.
is the Verilog HDL alternative for z in the
context of numbers.
Strings
sequence of characters that are enclosed by
double quotes
By: Vimal Kant Pandey
Digital System Design
Using Verilog
18
Continued..
Identifiers and Keywords
Identifiers are names given to objects so that they can be
referenced in the design.
Identifiers are made up of alphanumeric characters, the
underscore ( _ ) and the dollar sign ( $ ) and are case
sensitive.
Identifiers start with an alphabetic character or an
underscore.
Cannot start with a number or a $ sign
Keywords are special identifiers reserved to define the
language constructs
Keywords are in lowercase
19
Data Types
Value Sets
20
Continued
Nets
Nets represent connections between hardware
elements.
Declared with keyword wire
Nets are one-bit values by default unless they
are declared explicitly as vectors
The default value of a net is z (except the
trireg net, which defaults to x).
Nets get the output value of their drivers. If a
net has no driver, it gets the value z
21
Continued.
Registers
Declared by keyword reg and default
value is x
Registers
represent
data
storage
elements. Registers retain value until
another value is placed onto them.
In Verilog, the term register merely
means a variable that can hold a value.
Unlike a net, a register does not need a
driver.
By: Vimal Kant Pandey
Digital System Design
Using Verilog
22
Continued.
Vectors
Nets or reg data types can be declared as vectors
If bit width is not specified, the default is scalar
(1-bit).
Vectors can be declared as [high# : low#] or
[low# : high#] but the left number in the squared
brackets is always the most significant bit of the
vector
23
Continued.
It is possible to address bits or parts
of vectors.
24
Integer
declared by the keyword integer
default width for an integer is the hostmachine word size, which is implementation
specific but is at least 32 bits.
Registers declared as data type reg store
values as unsigned quantities, whereas
integers store values as signed quantities.
25
Continued
Real
Declared by keyword real
Time
Keyword time
width for time register data types is implementation
specific but is at least 64 bits
system function $time is invoked to get the current
simulation time
26
Continued
Arrays
Allowed for reg, integer, time, and vector register
data
Not allowed for real variables
accessed by <array-name> [<subscript>]
Multidimensional arrays are not permitted
27
Continued.
Parameters
constants to be defined in a module by the keyword
parameter
cannot be used as variables
Parameter values for each module instance can be
overridden individually at compile time
Parameters can be changed at module instantiation or
by using the defparam statement
28
29
Continued.
Monitoring information
$monitoron
$monitoroff
30
Continued.
Compiler Directives
Defined by using the ' <keyword> construct
`define & `include
31
32
Continued.
Ports
Ports provide interface for by which a module can
communicate with its environment
33
34
module Top;
module fulladd4 (sum, c-out, a, b, c-in) ;
Declare connection variables
output [3 : 01 sum;
eg [3:O]A,B;
output c-cout;
eg C-IN;
input [ 3 : 0 ] a, b;
wire [3:0] SUM;
input c-in;
wire C-OUT;
...
Instantiate fulladdl, call it fa-ordered. <module internals>
Signals are connected to ports in order (by
... position)
ulladd4 fa-ordered(SUM, C-OUT, A, B, C-IN);
endmodule
.
<stimulus>
ndmodule
By: Vimal Kant Pandey
Digital System Design
Using Verilog
35
Continued.
Connecting ports by name
36
37
38
39
Verilog Code
1-bit adder
40
Continued.
4-bit adder
41
Gate Delays
Rise Delay: Delay associated with a o/p transition
to 1 from any value.
42
Min/Typ/Max Values
Min value
The min value is the minimum delay value that the
designer expects the gate to have.
Typ value
The typ value is the typical delay value that the designer
expects the gate to have.
Max value
The max value is the maximum delay value that the
designer expects the gate to have.
43
Example
44
Dataflow Modeling
In complex designs the number of gates is
very large
With gate densities on chips increasing
rapidly, dataflow modeling has assumed
great importance.
Currently, automated tools are used to
create a gate-level circuit from a dataflow
design description. This process is called
logic synthesis
45
Continuous Assignment
46
Continued.
Rules:
The left hand side of an assignment must always
be a scalar or vector net
47
Continued.
Implicit Continuous Assignment
Delays
Regular Assignment Delay
Implicit Continuous Assignment Delay
Net Declaration Delay
48
Continued.
Example
Regular Assignment Delay
49
Continued.
Implicit Continuous Assignment Delay
50
Operator Types
51
Continued
52
Arithmetic Operators
There are two types of arithmetic operators:
Binary and Unary
Continued.
Unary Operator
The operators + and - can also work as unary operators.
used to specify the positive or negative sign of the
operand.
Unary + or - operators have higher precedence than the
binary + or operator
Example
-4 //Negative 4
+5 //Positive 5
54
Logical Operators
Logical operators follows the following conditions:
Logical operators always evaluate to a 1-bit value, 0
(false), 1 (true), or X (ambiguous).
If an operand is not equal to zero, it is equivalent to a
logical 1 (true condition).
If it is equal to zero, it is equivalent to a logical 0 (false
condition).
If any operand bit is X or z, it is equivalent to X
(ambiguous condition) and is normally treated by
simulators as a false condition.
Logical operators take variables or expressions as
operands.
Continued.
Examples
56
Relational Operators
Relational operators:
greater-than (>),
less-than (<)
greater-than-or-equal-to (>=)
less-than-or-equal-to (<=)
57
Equality Operators
58
Bitwise Operators
It performs bit-by-bit operations on two operands.
If one operand is shorter than the other, it will be
bit extended with zero to match the length.
Example:
Reduction operator
Perform a bitwise operation on single bit-vector
operand and yield a 1-bit result.
Example:
Shift Operator
Logical Shift: vacant bit positions are filled with
zeros
Arithmetic Shift: use the context of the expression
to determine the value with which to fill the
vacated bits.
Example:
Concatenation Operator({,})
It provides a mechanism to append multiple
operands.
The operands must be sized.
Unsized operands are not allowed because the
size of each operand must be known for the
computation of result.
Replication Operator
Repetitive concatenation of the same number can
be expressed by using a replication constant.
Replication constant specifies how many times to
replicate the number inside the brackets ({}).
Conditional Operator
66
Behavioral Modeling
Structured Procedures: there are two structured
procedure statements: always and initial
All other behavioral statements can appear only
inside these structured statements.
Each always and initial statement represents a ,
separate activity flow in Verilog.
Each activity flow starts at simulation time 0.
The statements always and initial cannot be
nested
initial Statement
All statements inside this constitute initial block.
An initial block starts at time 0ns,executes only
once during simulation and then does not
executes again.
If there are multiple initial blocks, each block
starts to execute concurrently at 0ns.
Each block finishes execution independently of
other blocks.
Multiple behavioral statements must be grouped,
typically using the keywords begin and end.
Example
always Statement
All behavioral statements inside an always
statement constitute an always block.
The always statement starts at time 0 and
executes the statements in the always block
continuously in a looping fashion
70
Procedural Assignments
Update values of reg, integer, real, or time
variables.
Syntax: <assignment> ::=<lvalue> =
<expression>
The left-hand side of a procedural assignment
<lvalue> can be one of the following:
A reg, integer, real, or time register variable or a
memory element
A bit select of these variables (e.g., addr[Ol)
A part select of these variables (e.g., addr[31:161)
A concatenation of any of the above
71
Blocking assignments
Executed in the order they are specified in a
sequential block.
A blocking assignment will not block execution of
statements that follow in a parallel block.
72
Nonblocking Assignments
Allows scheduling of assignments without
blocking execution of the statements that follow
in a sequential block.
A <= operator is used to specify nonblocking
assignments.
73