Verilog Basics
Verilog Basics
Dr. Vasudeva
ECE Dpt.
MREC (A), Hyderabad
e-mail: [email protected]
August 2023
What is Verilog
• Developed in 1984
ASIC
FPGA Boards
& Software
PLD Systems
Std Parts
Dr. Vasudeva 3 Verilog HDL Basics
Basic Limitation of Verilog
Behavioral
Gate
Layout (VLSI)
• /* Multiple line
comment */
*/
<size>’<radix> <value>
– 8’h ax = 1010xxxx
– 12’o 3zx7 = 011zzzxxx111
wand Y; // declaration
assign Y = A;
A assign Y = B;
Y
B
wor Y; // declaration
assign Y = A;
assign Y = B;
dr
tri Y; // declaration
A Y
assign Y = (dr) ? A : z;
• a = 4’b1010;
b = 4’b1100;
c = a ^ b;
• a = 4’b1010;
b = 2’b11;
Top Level
E.g.
Module
Full Adder
Sub-Module Sub-Module
1 2
f .. // declarations
inN outM .. // description of f (maybe
.. // sequential)
endmodule
A S assign S = A ^ B;
Half assign C = A & B;
B Adder C
endmodule
cin
module full_adder(sum, cout, in1, in2, cin);
output sum, cout;
input in1, in2, cin;
endmodule
Dr. Vasudeva 24 Verilog HDL Basics
Hierarchical Names
ha2.A
cin
module
• Inputs reg or net net
module
module
net net
• Inouts
• Usage:
nand (out, in1, in2); 2-input NAND without delay
and #2 (out, in1, in2, in3); 3-input AND with 2 t.u. delay
not #1 N1(out, in); NOT with 1 t.u. delay and instance name
xor X1(out, in1, in2); 2-input XOR with instance name
endmodule
initial
$display(“I’m first”); Will be displayed
at sim time 0
initial begin
#50;
$display(“Really?”); Will be displayed
end at sim time 50
endmodule
d
initial begin
#5 c = 1; c
#5 b = 0;
#5 d = c; b
end
0 5 10 15
Time
Each assignment is
blocked by its previous one
d
initial begin
fork c
#5 c = 1;
#5 b = 0; b
#5 d = c;
join 0 5 10 15
end Time
Assignments are
not blocked here
All examples and code from Mano “Digital Design” 3rd Ed.
Example: Simple Circuit HDL
module smpl_circuit(A,B,C,x,y);
input A,B,C;
output x,y;
wire e;
and g1(e,A,B);
not g2(y, C);
or g3(x,e,y);
endmodule
Simple Circuit Notes
module smpl_circuit(A,B,C,x,y);
input A,B,C;
output x,y;
wire e;
and g1(e,A,B);
not g2(y, C);
or g3(x,e,y);
endmodule
Input signals
module mux2x1_bh(A,B,select,OUT);
input A,B,select;
output OUT;
reg OUT;
always @ (select or A or B)
if (select == 1) OUT = A;
else OUT = B;
endmodule
HDL Summary