Lab 4 Verilog Gate Level Modelling
Lab 4 Verilog Gate Level Modelling
Lab No. 4
Introduction:
A hardware description language (HDL) used in the design, verification, and implementation of
digital logic chips. It used to describe electronic circuits and digital systems. In practice it is
generally used for simulating, testing, and programming PLD (programmable logic devices) or
other similar hardware.
On paper it is almost impossible to check the working of a circuit containing hundreds or
thousands of gates.
A hardware description language is used for describing and testing logic circuits. It is a text based way to
talk about designs.
Verilog HDL:
Verilog is very much similar to C, it is used by hardware designers in industry and academia. It is
an easy to learn language. Verilog HDL although looks similar to C but it is not a software
programming language, rather it is a hardware description language. It is important for verilog
programmers to know about the hardware.
Simulator:
The simulator that we will use is the ModelSim simulator.
------------------------------------------------------------------------------------------------------------------------
Verilog Program
A verilog program consists of two parts;
1. Device Under Test (DUT).
2. Stimulus
Verilog •C/C++
void main()
module name (portlist); {
endmodule }
Modules start with keyword module and end with keyword endmodule.
Module Ports:
These are similar to the pins on chip.
Ports provide a way of communication with outside world.
The Ports of a module can be input, output or inout.
Module Declarations:
METHOD # 1 METHOD # 2
module name (in1, in2,out); module name (input in1,in2,
output out);
input in1,in2;
output out;
endmodule endmodule
Decimal (default)
w = 12; r = 14;
Binary
w = 4’b1100; r = 4’b1110;
Time Control
The programmer can insert delays in the code by placing #<number>. On encountering this
statement, the simulation halts the execution of the statement until <number> time units have
passed. The Control is released from that statement or block so that other processes can
execute.
Initial block:
Initial block executes only once starting at t=0 simulation time.
Example
module my_mux21_gate(in1,in2,sel,out);
input in1,in2,sel;
output out;
wire out1,out2,out3;
not aa(out3,sel);
and bb(out1,in1,out3);
and cc(out2,sel,in2);
or dd(out,out1,out2);
endmodule
module stim_mux21_gate;
reg in1,in2,sel;
wire out;
my_mux21_gate rr(in1,in2,sel,out);
initial
begin
in1=0;
in2=1;
sel=0;
#20 in1=1;
in2=0;
sel=0;
#20 in1=1;
in2=0;
sel=1;
end
endmodule
-------------------------------------------------------------------
Example
module stim_circuit;
reg a,b;
wire o;
my_circuit dd(a,b,o);
initial
begin
a=0;
b=0;
#20 a=0;
b=1;
#20 a=1;
b=0;
#20 a=1;
b=1;
end
endmodule
A B C Q
1 0 1 0
0 0 1 1
1 1 1 1
3. Implement the following circuit using gate level modeling.
A B C D O
0 0 0 0 0
0 0 0 1 1
1 0 1 0 0