Verilog - Mano
Verilog - Mano
Verilog - Mano
Salahuddin Ahmed
Gate-Level Minimization
HDL
HDL describes the hardware of digital systems.
It describes hardware structures and behavior.
It represents logic diagrams, Boolean functions
and other more complex digital circuits.
To simulate a digital system, the design is first
described in HDL and then verified by simulating
the design and checking it with a test bench.
Logic synthesis is the process of deriving a netlist
from the model of a digital system written in HDL.
There are two standard HDLs:
VHDL and Verilog HDL.
Module Representation
Verilog uses about 100 keywords predefined,
lowercase, identifiers that defines the language
constructs. e.g.
module, endmodule, input, output, wire, and, or, not
etc.
Comments start with two slashes (//)
Blank spaces are ignored
Names are case sensitive
Each statement is terminated with a ;
Output is always listed first, followed by inputs
Verilog Example
// description of simple circuit A e
g1
module smpl_circuit( x, y, A, B, C );
B x
input A, B, C; g3
output x, y; C y
wire e; g2
and g1( e, A, B );
not g2( y, C );
or g3( x, e, y );
endmodule
Gate Delays
Simulator defaults to certain time unit,
usually 1 ns but could be changed with
`timescale 1ns / 100ps
Delay is specified in terms of time units
and the symbol #
and #(10) gate1(e, A, B)
Test Bench Example
A e
// description of test bench g1
module smpl_ckt_tb; B g3
x
reg A, B, C; y
C
wire x, y;
g2
smpl_circuit inst1(x,y,A,B,C);
// description of simple circuit
initial module smpl_circuit( x, y, A, B, C );
begin input A, B, C;
A=1b0; B=1b0; C=1b0; output x, y;
#100 A=1b1; B=1b1; C=1b1; wire e;
#100 $finish; and #(30) g1( e, A, B );
end not #(20) g2( y, C );
or #(10) g3( x, e, y );
endmodule endmodule
An HDL description that provides the stimulus to a design is called a test bench
Boolean Expression in Verilog
// Circuit with Boolean expression
module smpl_circuit( x, y, A, B, C ); A e
input A, B, C; g1
output x, y; B g3
x
assign y = ~C; C y
assign x = (A & B) | (~C); g2
endmodule
User Defined Primitives (UDP)
// User defined primitive (UDP) // Instantiate primitive
primitive crctp (x, A, B, C); module test_crctp;
output x; reg x, y, z;
input A, B, C; wire w;
// truth table for x(A,B,C) = (0,2,4,6,7) crctp (w, x, y, z);
table endprimitive
// A B C : x
0 0 0 : 1;
0 0 1 : 0;
The system recognizes the variables
0 1 0 : 1;
by the order that they are listed in the
0 1 1 : 0;
input declaration.
1 0 0 : 1;
1 0 1 : 0; User-defined primitive can be employed
1 1 0 : 1; in construction of other digital circuits
1 1 1 : 1; just as the system primitives are used.
endtable
endprimitive
UDP (cont.)
Declared with keyword primitive followed by a name and
port list.
Only one output must be listed first in the port list and
declared with output keyword.
Any number of inputs allowed order in the input must
be same as the values in the table that follows.
Truth table is enclosed within table and endtable.
Values of inputs end with a colon (:) Output is the last
entry in a row followed by a semicolon (;)
UDP ends with the keyword endprimitive.
and, or, not etc. gates are referred to as system primitive
Combinational Logic
HDL Models
Verilog module can be described in any of
the following modeling techniques:
Gate level modeling using instantiation of
primitive gates and user defined modules.
Dataflow modeling using continuous
assignment statements with keyword assign.
Behavioral modeling using procedural
assignment statements with keyword always.
Used to describe digital systems at a higher level
of abstraction.
Gate Level Modeling
Specifies circuit by its logic gates and their
interconnections.
Provides textual description of schematic
diagram.
Verilog recognizes 12 basic gates as
predefined primitives.
and, nand, or, nor, xor, xnor, not, buf
4 are tri-state type: bufif1, bufif0, notif1, notif0
Output is listed first, followed by inputs.
Primitive Gates
Two more logic values other than 0 and 1
Unknown (x)
Unassigned or ambiguous value
High Impedance (z)
Unconnected wire or output of a disabled tri-state gate
0 0 0 0 0 0 0 1 x x 0 0 1 x x 0 1
1 0 1 x x 1 1 1 1 1 1 1 0 x x 1 0
x 0 x x x x x 1 x x x x x x x x x
z 0 x x x z x 1 x x z x x x x z z
Example
// gate level description of a 2-to-4 decoder
Net represents the data types of wire, wor, wand, tri, suply1 and supply0
wire takes values of 0 or 1 tri takes values of 0, 1 or z
wor is wired-OR wand is wired-AND
supply1 is power supply supply0 is ground
Verilog HDL Operators
Operator Operation Operator Operation
Symbol Symbol
Type Performed Type Performed
+ Addition >> Shift Right
Subtraction Shift << Shift Left
Arithmetic * Multiplication {,} Concatenation
/ Division > Greater than
% Modulus < Less than
~ Complement == Equality
Logic & AND != Inequality
(reduction) Relational
(bit-wise) | OR Greater than
>=
^ XOR or equal
! Negation Less than or
<=
Logical && AND equal
|| OR Conditional ?:
Dataflow Modeling
// description of a 2-to-4 decoder // description of a 4-bit adder
module decoder_2to4 (Yb, A, B, E); module _4bit_adder (S, C4, A, B, C0);
input A, B, E; input [3:0] A, B;
output [3:0] Yb; input C0;
assign Yb[0] = ~(~A & ~B & ~E), output [3:0] S;
Yb[1] = ~(~A & B & ~E), output C4;
Yb[2] = ~(A & ~B & ~E),
Yb[3] = ~(A & B & ~E); assign {C4, S} = A + B + C0;
endmodule endmodule
initial initial
begin begin
A = 0; B = 0; D = 3b000;
#10 A = 1; repeat (7)
#20 A = 0; B = 1; #10 D = D + 3b001;
end end
Test Bench System Tasks
Built in system functions begin with the symbol $
System tasks useful for display are:
$display
display values of variables or strings and goes to next line
$write
Same as $display w/o going to next line
$monitor
Display variables whenever a value changes
$time
Displays simulation time
$finish
Terminates the simulation
Test Bench
// stimulus for mux_2to1
module testmux;
reg TA, TB, TS; // inputs for mux
wire Y; // output from mux Simulation log
// instantiate mux
mux_2to1 mx (TA, TB, TS, Y); select = 1 A = 0 B = 1 Y = 0 time = 0
initial select = 1 A = 1 B = 0 Y = 1 time = 10
begin select = 0 A = 1 B = 0 Y = 0 time = 20
TS = 1; TA = 0; TB = 1; select = 0 A = 0 B = 1 Y = 1 time = 30
#10 TA = 1; TB = 0;
#10 TS = 0;
#10 TA = 0; TB = 1;
end
initial
$monitor(select = %b A = %b B = %b Y = %b time = %0d,
TS, TA, TB, Y, $time);
endmodule
Test Bench
Assuming design module for circuit of Fig 4-2 is defined as:
module analysis (F1, F2, A, B, C);
In the absence of an assigned value, the Verilog compiler assumes that the
value of A caused by the if statement must be maintained until the next time
this if statement is evaluated. This notion of implied memory is realized by
instantiating a latch in the circuit.