Digital Circuit Verification Hardware Descriptive Language Verilog
Digital Circuit Verification Hardware Descriptive Language Verilog
C. Gerousis
© Logic and Computer Design Fundamentals, 3rd Ed., Mano
Prentice Hall
Overview
Hardware Descriptive Language (HDL)
Behavioral vs. Structural Description
Gate-Level Description of a simple circuit
Model Abstractions in Verilog
User Defined Primitives (UDPs)
HDL Examples
Hardware Descriptive Language (HDL)
Uses of HDLs:
– They provide alternative to schematics.
– They can represent Boolean equations, truth tables and
complex operations.
Behavioral Description
– More like high level software language
– Easy to read and understand
– In the early stage of design to test the correctness of
functionality of the design
Structural Description
– Less readable
– Like gate level netlist
– In the late stage of the design, used to generate
netlist.
HDL Example 1
//HDL Example 1
//--------------------------
//Gate-Level Description of a simple circuit
module smpl_circuit(A,B,C,x,y); // building block
input A,B,C; // input port
output x,y; // output port
wire e;
and g1(e,A,B); // AND gate (output, inputs)
not g2(y, C);
or g3(x,e,y);
endmodule
Draw the simple circuit
Model Abstractions in Verilog
Behavioral Level
– High-level that only Describe Functionality
– Automatic Behavioral Synthesis Tools do Exist
User Defined Primitives (UDPs)
module declare_crctp;
reg x,y,z;
wire w;
crctp (w,z,y,z); // produces a circuit that implements
endmodule // w (x,y,z) = (0, 2, 4, 6 ,7)
HDL Example 3
//HDL Example 3
//------------------------------
//Circuit specified with Boolean equations
module circuit_bln (x,y,A,B,C,D);
input A,B,C,D;
output x,y;
assign x = A | (B & C) | (~B & C); // x A BC B ' D
assign y = (~B & C) | (B & ~C & ~D); // y B' C BC ' D'
endmodule
4-bit Adder: Bottom-Up Hierarchical Structure
1. Half-Adder
2. Full-Adder
3. 4-bit Adder
4-bit Adder: Verilog Description
//HDL Example 4
//-----------------------------------------
//Gate-level hierarchical description of 4-bit adder
// Description of half adder
module halfadder (S,C,x,y);
input x,y;
output S,C;
//Instantiate primitive gates
xor (S,x,y);
and (C,x,y);
endmodule
4-bit Adder: Verilog (continued)
//Description of the full adder
module fulladder (S,C,x,y,z);
input x,y,z;
output S,C;
wire S1,D1,D2; //Outputs of first XOR and two AND gates
//Instantiate the halfadder
halfadder HA1 (S1,D1,x,y),
HA2 (S,D2,S1,z);
or g1(C,D2,D1);
endmodule
S1
D1
D2
4-bit Adder: Verilog (continued)
//Description of 4-bit adder
module _4bit_adder (S,C4,A,B,C0);
input [3:0] A,B; // Input vectors A, B with bits 0 through 3
input C0;
output [3:0] S;
output C4;
wire C1,C2,C3; //Intermediate carries
//Instantiate the fulladder
fulladder FA0 (S[0],C1,A[0],B[0],C0),
FA1 (S[1],C2,A[1],B[1],C1),
FA2 (S[2],C3,A[2],B[2],C2),
FA3 (S[3],C4,A[3],B[3],C3);
endmodule
4-bit Adder: Verilog (continued)
`timescale 1 ps / 1 ps
module testbed();
reg c_in;
reg [3:0] y;
reg [3:0] x;
wire c_out;
wire [3:0]sum;
FourBitAdder A1(sum, c_out, x, y, c_in);
initial
begin //SIGNAL x
x = 4'b1001;
#25000
x = 4'b0001;
#25000
;
end
4-bit Adder: Verilog (Final)
initial
begin //SIGNAL y
y = 4'b0001;
#25000
y = 4'b0010;
#25000
;
end
initial
begin //SIGNAL c_in
c_in = 1'b0;
#100000
c_in = 1'b1;
#25000
;
end
initial
#250000 $finish;
endmodule