Verilog HDL: A Guide To Digital Design DS TH I and Synthesis
Verilog HDL: A Guide To Digital Design DS TH I and Synthesis
MODULE + GATE
CIRCUIT
DEVICE G S n+ D n+
What is HDL?
A Hardware Description Language (HDL) is a highhigh level programming language with special language constructs used to model the function of hardware logic circuits. Y can D i and Si l t circuits with a C i it You Design d Simulate i it ith Clike syntax The special language constructs p p g g provide y the ability you y to:
Describe the connectivity (structure) of a circuit Describe the functionality (behavior) of a circuit Describe the timing information and timing constraints of a circuit D Describe a circuit at various l ib i i i levels of abstraction l f b i Express concurrency
Outline
Design Style HDL Modeling Behavioral Modeling Structural Modeling Description Styles Structural styles
Gate level Structural Hierarchy
Sch hematic c
Verilog History
Verilog was created by Phil Moore in 1983 4 at Gateway Design 1983-4 Automation and the first simulator was written a year later. In 1989, Gateway Design Automation was acquired by Cadence Design System. System In 1990, Cadence decided to open the language to the public, and thus OVI (Open Verilog International) was formed. In 1993, I 1993 an IEEE working group was established under th ki t bli h d d the Design Automation Sub-Committee to produce the IEEE Verilog 1364. In D I December 1995 th fi l d ft of V il was approved and b 1995, the final draft f Verilog d d the result is known as IEEE Std. 1364-1995. IEEE 1364-2001 is the latest Verilog HDL standard.
Importance of HDLs
Designs can be described at a very abstract level by use of HDLs. Designers can write their RTL description without choosing a specific fabrication technology. y g g By describing designs in HDLs, functional verification of the design can be done early in the design cycle. Designing with HDL is analogous to the computer programming. programming
Verilog Applications
For system architects Verilog HDL support high level language architects, constructs which can be used to describe and verify the architecture and performance of the system. For ASIC and FPGA designers, Verilog HDL supports RTL designers language constructs which can be used to describe, verify, and synthesize to more detailed level of design abstraction (most often gate-level netlist) gate level For model developers, Verilog supports describing and packaging mechanisms (e.g., module path delay description, code e c ypt o ) for modeling ASIC o FPGA ce s, o higher encryption) o ode g S C or G cells, or g e level components (IPs). For verification engineers, Verilog supports system tasks which can be used to create testbenches for all level of simulation.
Methodology gy
Top-Down Bottom-up
Target
Module 1
Module 2
Module 3
Basic Comp.
Basic Comp.
Basic Comp.
Basic Comp.
Basic Comp.
Basic Comp.
Example
expression True
False F l
statement3
statement2
RTL Model
Identify the combinational portion and registers of the circuit under design Describe the data flow between the registers Timing (clock) is an important issue
combinational
registers
clock
Gate-Level Model
Express the circuit under design as a collection of p g Boolean expressions Logic optimization is performed at this level of description d i ti
FFs
clock
In
Out In
Out O t
Gnd
(a) Schematic
(b) Mask
Architectural
Algorithmic
Increasing level of abstraction
assign rt1 = (11&buserr) | zero; assign sub = rt1 ^| op; assign out1 = i1 & i2 | op;
endmodule
Verilog Module
module module-name (list-of-port);
We first start by creating a module by name of AND2gate. This module consists of an interface of 3 ports, A, B, and F.
module AND2gate(A, B, F); input A; input B i t B; output F;
endmodule
We next specify what type the ports are. In this example, port A and port B are inputs, while port F is an output
module AND2gate(A, B, F); input A; input B; output F; reg F; always @ (A or B) begin F <= A & B; end endmodule
Half ADDER
a b c_out_bar
sum
c_out _
Examples (cont.)
Module name Module ports
module Add_half ( sum, c_out, a, b ) _ _ ); input a, b; Declaration of port output sum, c_out; modes wire i c_out_bar; t b Declaration of internal
signal
xor (sum, a, b); nand (c_out_bar, a, b); not (c_out, c_out_bar); endmodule
Verilog keywords
sum
notXYnotX
X Y X Y Z
XnotY notY
module xorB(Z, X, Y); input X, Y; output Z; reg Z; always @ (X or Y) Z = X ^ Y; // ^ is C operator for xor endmodule;
Examples 2 NAND
Structural model
//structural model of a Nand gate // program nand2.v module NAND(in1, i 2 out2); d l NAND(i 1 in2, t2) input in1,in2; output out2; nand nand2(out2,in1,in2);// first port must be output. endmodule
Example : 1-bit half adder Verilog description of a half adder and schematic
module Add_Half(sum,c_out,a,b); input a,b; output c_out,sum; xor (sum,a,b); and (c_out,a,b); endmodule
*Tips: The output port of primitives must be first in the list of ports.
Behavioral Description p
module Add_half ( sum, c_out, a, b ); input a, b; output sum, c_out; sum c out; a Add_half reg sum, c_out; b always @ ( a or b ) begin sum = a ^ b; // Exclusive or c_out c out = a & b; // And end endmodule
sum c_out
Structural model
Just specifies primitive gates and wires i.e., the structure of a logical netlist You basically know how to do this now now.
Behavioral model
More like a procedure in a programming language Still specify a module in Verilog with inputs and outputs... ...but inside the module you write code to tell what you want to have happen, NOT what gates to connect to make it happen i i.e., you specify th b h i you want, not th structure t do it if the behavior t t the t t to d
b a sel
not(nsel, ( l
sel); l)
and a1(f1, a,nsel); and a2(f2, b, sel); ( , , ); or (f, f1, endmodule f2);
module mux2(f, a,b,sel); d l (f b l) output f; input a,b,sel; a b sel; assign f = (a & ~sel) | (b & sel); endmodule
module mux2(f, a,b,sel); output f; input a,b,sel; reg f; always @(a or b or sel) l @( l) if (sel==1) f = b; else ; f = a; endmodule
Demux Example
2-to-4 demultiplexer with active low
enable 0 1 1 1 1
a x 0 1 0 1
b x 0 0 1 1
z[3] 1 1 1 1 0
z[2] 1 1 1 0 1
z[1] 1 1 0 1 1
z[0] 1 0 1 1 1
// 2-to-4 demultiplexer with active-low outputs module demux1(z,a,b,enable); input a,b,enable; output [3:0] z; wire aba bba i e abar,bbar; // local signals not v0(abar,a), v1(bbar,b); nand n0(z[0],enable,abar,bbar); nand n1(z[1],enable,a,bbar); nand n2(z[2],enable,abar,b); nand n3(z[3],enable,a,b); endmodule
// 2-to-4 demux with active-low outputs // dataflow model module demux2(z,a,b,enable); input a,b,enable; output [3:0] z; assign z[0] = | {~enable,a,b}; assign z[1] = ~(enable & a & ~b); i [1] ( bl b) assign z[2] = ~(enable & ~a & b); assign z[3] = enable ? ~(a & b) : 1'b1; g [ ] ( ) ; endmodule
// 2-to-4 demultiplexer with active-low outputs module demux3(z,a,b,enable); input a,b,enable; a b enable; output [3:0] z; reg z; // not really a register! always @(a or b or enable) case ({enable,a,b}) default: z = 4'b1111; 3'b100: z = 4'b1110; 3 b 0: 3'b110: z = 4'b1101; b 0 ; 3'b101: z = 4'b1011; 3'b111: z = 4'b0111; endcase endmodule d d l
endmodule
Program 2
1 to 2 De multiplexer 1-to-2 De-multiplexer
Select y0 D y0
0 DMUX 1
y1 y1 Select
Select 0 1
y0 D 0
y1 0 D
y0
y1
Select
Example of Flip-flop
module Flip_flop ( q data in clk rst ); Flip flop q, data_in, clk, input data_in, clk, rst; output q; reg q; always @ ( posedge clk ) begin ) ; if ( rst == 1) q = 0; else q = data_in; end endmodule d d l
rst
data_in
clk
Sub Module
Complex circuit Many modules in a circuit Module, sub-module, sub-sub-module,
B1
B2
B3
B1
B2
B3
module half_adder (s, a, b, co); input a, b; output s, co; wire w0, w1, w2; assign w0 = a & b, w1 = ~w0, w2 = a | b 2 b, s = w1 & w2, co = w0; endmodule
w0
w1
s w2
a 0 0 1 1 b 0 1 0 1 s 0 1 1 1 co 0 0 0 1
module full_adder (s, a, b, co, ci); _ ( ) input a, b, ci; output s, co; wire w0, w1, w2; i 0 1 2 assign co = w1 | w2; half_adde i0 a adder 0 (.co(w1), .s(w0), .a(a), .b(b)); half_adder i1 (.co(w2), .s(s), .a(w0), .b(ci)); endmodule
a b w0
i0 a
co
w1
co
HA
b i1 a s
co
w2 s
HA
cii b s
ci a[0] b[0]
i0 ci a b i1 ci a b i2 ci a b i3 ci a b
FA
s co
s[0] w0 s[1] w1
a[1] b[1]
FA
s co
a[2] b[ ] b[2]
FA
s co
s[2] w2
a[3] b[3]
FA
s co
s[3] co
endmodule d d l