Chapter 3
Chapter 3
1
OUTLINE
¢ Introduction
¢ Definition of a module
¢ Gate-level modeling
¢ Verilog primitives
¢ Verilog Syntax
¢ Verilog Data Types
¢ Module instantiation
¢ Organization of a Testbench for Verifying a Unit
Under Test (UUT)
¢ Propagation, inertial and transport delay
¢ Truth Table Models of Combinational and
2
Sequential Logic with Verilog
INTRODUCTION
¢ Verilog is one of the hardware description
languages (HDL) available in the industry for
hardware designing.
¢ Verilog is a standard HDL (IEEE 1364-1995,
2001, 2005)
¢ It allows designers to design at Behavior Level,
Register Transfer Level (RTL), Gate level and at
switch level.
¢ Parallel not serial (Not like C language).
¢ Add-ons (optional)
6
THE MODULE INTERFACE
This is the old Verilog
(Verilog-95)
Port List
Port Declaration
7
THE MODULE INTERFACE
8
DEFINITION OF A MODULE: VERILOG-2005
¢Module & Port Declaration:
module [module-name] #(parameter declarations)
(
[mode] [ data-type] [port-names] ,
[mode] [ data-type] [port-names] ,
...
[mode] [ data-type] [port-names]
);
Mode: input, output or inout
Data-Type: wire, reg or integer (scalar or array) 9
EXAMPLE
10
GATE LEVEL MODELING (STRUCTURAL)
¢ Net-list description: built-in primitives gates
11
An undeclared identifier is treated by default as a wire
VERILOG PRIMITIVES FOR MODELING
COMBINATIONAL LOGIC GATES
Verilog has 26 primitives for modeling combinational logic gates:
•and
•or
•not
•buf
•xor
•nand
•nor
•xnor
•bufif1, bufif0
•notif1, notif0
12
PRIMITIVE PINS ARE EXPANDABLE
14
VERILOG SYNTAX
¢ Identifiers:
Composed of letters, digits, the underscore character (_),
and the dollar sign ($). $ is usually used with a system task
or function
The first character of an identifier must be a letter or
underscore
Verilog is a case-sensitive language D_BUS is different from
D_Bus
¢ Keywords: predefined identifiers that are used to
describe language constructs. E.g. module, always,
wire …etc. à Can not be used as user-defined
identifiers
¢ White space: space, tab, and newline characters are
used to separate identifiers and can be used freely in
the Verilog code 15
VERILOG SYNTAX
¢ Comments: two forms; one-line comment starts
with // and multiple-line comment is
encapsulated between /* and */
// T his is a comment
/* This i s comment line 1 .
This i s comment line 2 .
This i s comment line 3 . * /
16
VERILOG DATA TYPES
¢ Four-valued system:
0: for "logic Low, or a false condition
1: for "logic High", or a true condition
z: for the high-impedance state
x: for an unknown value (in simulations)
18
INTEGER NUMBERS IN VERILOG
¢ Constant numbers can be specified in decimal,
hexadecimal, octal, or binary format
¢ Integer numbers can be specified as:
Syntax: <size>'<radix><value> (size is in number of bits)
Sized or unsized numbers ( Unsized numbers are 32 bits )
In a radix of binary, octal, decimal, or hexadecimal
Radix and hex digits (a,b,c,d,e,f) are case insensitive
Spaces are allowed between the size, radix and value
The character (_) is legal anywhere in a number except as
the first character à so use it for better clarity.
Examples: 12’b1011_1100_0010, ‘hA8, 8’d 15)
When <size> is smaller than <value>, then left-most bits
of <value> are truncated 19
MODULE INSTANTIATION
¢ Two ways to connect the ports of the instantiated
module to the signals in the instantiating
module:
1. By name:
[module-name] [instance-name]
(
. [port-name] ( [signal-name] ) ,
.[port-name] ([signal-name]),
);
2. By order:
eq1 bit0 (a[0] , b [0] , e0 ) ;
20
eq1 bitl (a[1] , b [1] , e1 ) ;
MODULE INSTANTIATION
21
MODULE INSTANTIATION
module Add_rca_16 (output c_out, output [15:0] sum, input [15:0] a, b, input c_in);
wire c_in4, cin8, c_in12;
Add_rca_4 M1 (c_in4, sum[3:0], a[3:0], b[3:0], c_in);
Add_rca_4 M2 (c_in8, sum[7:4], a[7:4], b[7:4], c_in4);
Add_rca_4 M3 (c_in12, sum[11:8], a[11:8], b[11:8], c_in8);
Add_rca_4 M4 (c_out, sum[15:12], a[15:12], b[15:12], c_in12);
endmodule 22
MODULE INSTANTIATION
module Add_rca_4 (output c_out, output [3:0] sum, input [3:0] a, b, input c_in);
wire c_in2, cin3, c_in3;
Add_full M1 (c_in2, sum[0], a[0], b[0], c_in);
Add_full M2 (c_in3, sum[1], a[1], b[1], c_in2);
Add_full M3 (c_in4, sum[2], a[2], b[2], c_in3);
Add_full M4 (c_out, sum[3], a[3], b[3], c_in4);
endmodule
23
MODULE INSTANTIATION
module Comp_2_str (output A_gt,_B, A_lt_B, A_eq_B, input A0, A1, B0, B1);
nor (A_gt_B, A_lt_B, A_eq_B);
or (A_lt_B, w1, w2, w3);
and (A_eq_B, w4, w5);
and (w1, w6, B1);
and (w2, w6, w7, B0);
and (w3, w7, B0, B1);
not (w6, A1);
not (w7, A0);
xnor (w4, A1, B1); 25
xnor (w5, A0, B0);
endmodule
MODULE INSTANTIATION
28
TESTBENCH EXAMPLE
module t_Add_half();
wire sum, c_out;
reg a, b;
Add_half M1 (c_out, sum, a, b);
initial begin
#100 $finish;
end
initial begin
#10 a=0; b=0;
#10 b=1;
#10 a=1;
#10 b=0;
end
endmodule
29
TESTBENCH EXAMPLE
¢ The keyword initial declares a single-pass behavior
that begins executing when the simulator is
activated.
¢ Statements within begin and end block keywords are
called procedural statements.
¢ Procedural statements execute sequentially
¢ # is a delay control operator
¢ A delay control operator preceding procedural
assignment statement suspends its execution and the
execution of subsequent statements for specified delay
time
¢ reg declaration ensures that variables will keep their
value until the next procedural assignment statement
¢ $finish ends simulation
30
TESTBENCH TEMPLATE
module t_DUTB_name(); // substitute the name of the UUT
reg ----; // declaration of register variables for
// primary inputs of the UUT
wire ----; // declaration of primary outputs of UUT
parameter time_out= // provide a value
UUT_name M1 (UUT ports go here);
initial $monitor() // specification of signals to be
// monitored and displayed as text
initial time_out $finish // stopwatch to ensure termination
// of simulation
initial begin
// behavioral statements generating
// wavefroms to input ports
end
endmodule
31
PROPAGATION DELAY
module Add_full_unit_delay(output c_out, sum, input a, b, c_in);
wire w1, w2, w3;
Add_half_unit_delay M1 (w2, w1, a, b);
Add_half_unit_delay M2 (w3, sum, w1, c_in);
or #1 M3 (c_out, w2, w3);
endmodule
32
PROPAGATION DELAY
¢ To set a certain unit for time units, use the
directive ‘timescale
¢ ‘timescale 1ns / 1ps directs the simulator to
interpret numerical time variables as having
units of nanoseconds with a resolution of
picoseconds
33
INERTIAL DELAY
¢ Propagation delay in Verilog obeys inertial delay
model.
¢ Verilog uses the propagation delay of a gate as
minimum width of an input pulse that could
affect output.
34
TRANSPORT DELAY
¢ Propagation delay across a wire is modeled as
transport delay i.e. narrow pulses are not
suppressed
¢ Example
35
TRUTH TABLE MODELS OF COMBINATIONAL
AND SEQUENTIAL LOGIC WITH VERILOG
37
TRUTH TABLE MODELS OF COMBINATIONAL
AND SEQUENTIAL LOGIC WITH VERILOG
38
TRUTH-TABLE MODEL OF A TRANSPARENT
LATCH
¢ The output of a sequential UDP must be declared
to have type reg
primitive latch_rp (output reg q_out, input enable,
data)
// enable data state
q_out/next_state
1 1 : ? : 1;
1 0 : ? : 0;
0 ? : ? : -;
x 0 : 0 : -;
x 1 : 1 : -; 39
TRUTH-TABLE MODEL OF A D-TYPE FLIP-
FLOP
40