UNIT1 - Logic Design Through Verilog HDL
UNIT1 - Logic Design Through Verilog HDL
* 1
Tutorial Outline
• Introduction
• VLSI Design flow
• Circuit Modeling
• Gate-level Modeling
• Data-level Modeling
• Behavioral Modeling
• Testing & Simulation
* 2
VLSI DESIGN FLOW
A design flow is a sequence of operations that transform the
IC designers’ intention (usually represented in RTL format)
into layout GDSII (Graphic Design System) data.
* 9
Where can we use Verilog HDL?
• Verilog is designed for circuit simulation and
verification, for timing analysis, for test
analysis (testability analysis and fault grading)
and for logic synthesis.
* 10
Basics of Verilog HDL
• Module & its syntax
• Basics of Verilog
• Modeling styles
– Gate Level
– Data flow
– Behavioral
* 11
Basic Syntax of a Module
Module module_name (port_list);
Declarations:
input, output, wire, parameter…..
System Modeling:
describe the system in gate-level, data-flow, or
behavioral style…
endmodule
* 12
Basic Module Construction
// Compute the logical AND and OR of
inputs A and B.
* 14
* 15
List of declarations wire connected
primitives
* 16
Format of Verilog module
* 17
Verilog structural models
• Module ports
* 18
Language rules
• Verilog is a case sensitive language
– Eg: AND_OR & and_or names are different.
* 19
• Keywords
module -- signifies the beginning of a module
definition.
endmodule -- signifies the end of a module
definition.
begin -- signifies the beginning of a block of
statements.
end -- signifies the end of a block of statements.
if -- signifies a conditional activity to be checked
while -- signifies a conditional activity to be carried
out.
* 20
• Identifiers
– It is good practice for us to use identifiers,
closely related to the significance of
variable, signal, block, etc., concerned.
This eases understanding and debugging
of any program.
– There are some restrictions in assigning identifier
names. All characters of the alphabet can be used
as the first character. Subsequent characters can
be of alphanumeric type, or the underscore (_), or
the dollar ($) sign.
* 21
• for example name, Name, name1, name_$, . . . -- all
these are allowed as identifiers
• name aa -- not allowed as an identifier because of
the blank ( “name” and “aa” are interpreted as two
different identifiers)
• $name -- not allowed as an identifier because of the
presence of “$” as the first character. 1_name -- not
allowed as an identifier, since the numeral “1” is the
first character
• @name -- not allowed as an identifier because of the
presence of the character “@”. A+b m not allowed as
an identifier because of the presence of the character
“+”.
* 22
• White Space Characters
– Blanks (\b), tabs (\t), newlines (\n), and
form feed form the white space characters
in Verilog
• to improve readability.
• Functionally, they separate legal tokens
• They are introduced between keywords,
keyword and an identifier, between two
identifiers, between identifiers and operator
symbols, and so on.
• White space characters have significance only
when they appear inside strings.
* 23
• Comments
– Comments can be inserted in the code for
readability and documentation.
– There are two ways to write comments
• a = b && c; // This is a one-line comment
• /* This is a multiple line
comment */
• /* This is /* an illegal */ comment */
• /* This is //a legal comment */
* 24
• X or Z values
– for modeling real circuits.
– An unknown value is denoted by an x.
– A high impedance value is denoted by z.
Example:
– 12'h13x // This is a 12-bit hex number; 4
least significant bits unknown
– 6'hx // This is a 6-bit hex number
– 32'bz // This is a 32-bit high impedance
number
* 25
• Value Set or Logic Values
* 26
• Strengths
* 27
• Datatypes
– Nets
– Variable
* 28
• Operators
– Operators are of three types: unary, binary,
and ternary.
– Unary operators precede the operand.
Binary operators appear between two
operands.
– Ternary operators have two separate
operators that separate three operands.
* 29
• Examples of operators
– a = ~ b; // ~ is a unary operator. b is the
operand
– a = b && c; // && is a binary operator. b and
c are operands
– a = b ? c : d; // ?: is a ternary operator. b, c
and d are operands
* 30
• Number Specification
Sized :
–4'b1111 // This is a 4-bit binary number
– 12'habc // This is a 12-bit hexadecimal
number
–16'd255 // This is a 16-bit decimal number.
Unsized:
eg: 23456 // This is a 32-bit 'hc3 //
This is a 32-bit 'o21 //
This is a 32-bit decimal number by default
* hexadecimal number octal number 31
Vectors in Verilog
• Vectors in Verilog denoted by square
brackets, enclosing a contiguous range
of bits.
• Eg:
– Sum[3:0]
– Input[3:0]
– Output[7:0]
* 32
Modeling styles of Verilog
• Data flow
• Behavioral
• Gate Level
• Structural
* 33
Data-flow Modeling
• The basic mechanism used to model a
design in the dataflow style is the
continuous assignment.
• In a continuous assignment, a value is
assigned to a net.
• Syntax:
assign #delay LHS_net = RHS_expression;
* 34
Example: 2 to 4 Decoder
* 35
Example
module Decoder 2_4(Z,A,B,EN);
Input A,B,EN;
output [3:0] Z;
wire Ab, Bb;
assign #1 Ab=~A;
assign #1 Bb=~B;
assign #2 Z[0]=~(Ab & Bb & EN);
assign #2 Z[1]=~(Ab & B & EN);
assign #2 Z[2]=~(A & Bb & EN);
assign #2 Z[3]=~(A & B & EN);
endmodule
* 36
Behavioral Modeling
• The behavior of a design is described
using procedural constructs. These are:
– Initial statement: This statement executes
only once.
– Always statement: this statement always
executes in a loop forever…..
• Only register data type can be assigned
a value in either of these statements.
* 37
Always Statement
• Syntax: always
#timing_control procedural_statement
• Procedural statement is one of :
– Blocking Procedural_assignment
always
@ (A or B or Cin)
begin
T1=A & B;
T2=B & Cin;
T3=A & Cin;
Cout=T1 | T2 | T3;
end
T1 assignment is occurs first, then T2, then T3….
* 38
Procedural statements
Conditional_statement
always
@(posedge clk or posedge reset)
if ( Sum <60)
begin
Grade = C;
Total_C=Total_C +1;
end
else if (Sum<75)
Grade = B;
else
Grade = A;
* 39
Procedural statements
Case_statement
always
@(Time ==7)
case(Day)
Tue: Pocket-Money = 6;
Mon,
Wed: Pocket_Money = 2;
Fri,
Sat,
Sun: Pocket_Money = 7;
default: Pocket_Money= 0;
endcase
* 40
Gate-Level Modeling
Systems structure can be described using Build-in
gates or pre-built modules.
Basic syntax is :
* 41
The Built-in Primitive Gates
• Multiple-input gates:
– and, nand, or, nor, xor, xnor
xor xor1(out, inA, inB, inC);
• Multiple-output gates:
– buf, not
not inverter1(fanout1, fanout2, in);
• Tristate gates:
– bufif0, bufif1, notif0, notif1
bufif0 tbuffer1(out, in, control);
* 42
Gate Delays
• Syntax: #(Tplh, Tphl)
• Examples:
* 43
Example: A 4 to1 Multiplexer
* 44
Simple Example
module Mux4_1 (Z, D,S);
output Z;
input [3:0] D;
input [1:0] S;
wire S0b, S1b, T0, T1, T2, T3;
* 46
16-bit Ripple carry adder using 4-bit
ripple carry adders
* 47
Design hierarchy of 16 bit RCA
* 48
Structural connectivity - Wires
• Wires in Verilog establish connectivity
between design objects.
• They connect primitives to other primitives
and/or modules.
• Or they connect modules to other modules
and/or primitives
• The variable Wire is a member of family of
nets
– Establish connectivity in a design
* 49
Formal and actual names for port
association by name in module
* 50
Eg: 2-bit Comparator:
- compares two 2-bit numbers and
asserts the relation > or < or =
* 51
Schematic of 2-bit Comparator
* 52
Verilog code (Gate level modeling style)
* 53
4-bit Comparator
using two 2-bit comparators
* 54
Verilog code (Structural style)
* 55
Logic System, Design verification
and Test methodology
• Two methods of verification are used
– Logic simulation
• applies stimulus patterns to a circuit and
monitors its simulated behavior to determine
whether it is correct or not.
– Formal verification
• uses elaborated mathematical proofs to verify
circuit’s functionality without need to apply
stimulus pattern
* 57
Test Methodology
* 58
• A Simulator performs three essential
tasks.
– 1) Checks the source code
– 2) reports any violation of source code
– 3) simulates the behavior of the circuit
under the application of input signals
defined in the test bench
* 59
Example of Test bench
* 60
Signal generators for Testbenches
• The keyword, initial declares a single
pass behavior
– that begins executing when the simulator is
activated at tsim = 0.
* 62
Event driven simulation
• A change in the value of a signal
(variable) during simulation is referred
to as an “event”.
• Event driven simulation
– computational activity of simulators is
driven by propagation of events in a circuit
* 63
Test bench Template
* 64
Sized numbers
• The values assigned to the stimulus
waveforms in the testbench can be
sized numbers
• Eg: 8’ha : 8-bit hexa decimal no. a
• Four formats are available
– Binary (b)
– Decimal (d)
– Octal (o)
– Hexadecimal (h)
* 65
Propagation delay
• The delay between the time that an input
changes and the time that the output
responds to change
* 66
* 67
Inertial delay
• The amount of time that the input pulse must
be constant in order for the gate to make a
transition is called the inertial delay of the
gate.
• Verilog uses the Propagation Delay (PD) of a
gate as the minimum width of an input pulse
that could effect the output
– It also considered as inertial delay.
– Inertial delay has the effect of suppressing input
values whose duration is shorter than PD of the
gate.
* 68
Transport delay
• The time-of-flight of a signal travelling a
wire of a circuit is modeled as a
Transport delay.
– Narrow pulses are not suppressed
– All transitions at the driving end of a wire
appear at the receiving end after a finite
time delay.
– Wire delays
• Eg: wire #2 A_long_wire
* 69
Truth table models of combinational &
sequential logic with verilog
• A mechanism for building User Defined
Primitives (UDP)
uses Truth Tables to describe sequential
behavior and/or more complex
combinational logic.
UDPs are widely used in ASIC cell
libraries
As they simulate faster and requires less
storage than modules.
* 70
Example: AOI gate (5-input)
* 71
Eg: UDP for 2-input Multiplexer
* 72
Short hand notation: 2x1 MUX
* 73
UDP for Latch
* 74
UDP for D-Flip flop
* 75
UDP for J-K flip flop
* 76
Further References:
* 77