0% found this document useful (0 votes)
10 views5 pages

LAB#1

Uploaded by

Usama Baloch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

LAB#1

Uploaded by

Usama Baloch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DepartmentofComput

er
SystemsEngineering

DigitalSystemDesign

Handout#01
Gate-LevelModellingandSimulation

LabLearningObjectives:

Aftercompletingthissession,studentshouldbeableto:
 UnderstandbasicsofVerilogprogramming.
 Getfamiliarwithstructuraldescription(moduleinstantiation).
 Simulatebasiccombinationalcircuitsusinggate-levelmodelling.

Note:Submitthelabreport(solvedactivitiesandexercises)beforethenextlab.
LabHardwareandSoftwareRequired:

1.Desktop/LaptopComputer with internet connection.

BackgroundTheory:

Gate-levelModelling:
Verilog is both a structural and behavioral language. Internals of each module can
bedefinedatfourlevelsofabstraction,dependingontheneedofthedesign.Therearefourlevels
of abstraction which include switch-level, gate-level, data flow, and behavioral
oralgorithmlevel.

Theswitch-
levelisthelowestabstractionlevel,wheremodulecanbeimplementedintermsofswitch
es,storagenodes,andinterconnectionsbetweenthem.

Thegate-levelmodellingisimplementedintermsoflogicgatesandinterconnections
between these gates. This design method is like describing adesignintermsof
agate-levellogicdiagram.

Verilog allows the designer to mix and match all four levels of design methodologies
indesign. The modules behave identically to the external world identically irrespective
ofthe level of abstraction at which module is described.Therefore, internals of the
modulecanbe changedwithout any changein theenvironment.

In the digital design community, the term register transfer level (RTL) is used for
Verilogdescriptionthatusesacombinationofbehavioralanddataflowmodelling.Normally,the
higher level of abstraction, design will be more flexible and technology
independent.Although, the lower-level description provides high performance therefore
as the designmatures,highlevelmodules arereplacedwith thegate-levelmodelling.
LabActivity:
Wearegoingtousetestbenchlisting1.7(2-
bitcomparatordesignanditstestvector)youhavecovered inchapter#1of the textbook.

Steps:
1. Openhttps://www.edaplayground.com/.
2. Write yourtestbenchcode atthe left and required moduleson theright.
3. Addthesetwolinesafterinitialbegin
$dumpfile("eq2_tb.vcd"); //simulatorgeneratesoutputfileforthewaveformsdata
$dumpvars;
Also,replace$stopwith$finish.

4. SelectIcarusVerilogasyoursimulator.
5. Enable“OpenEPWaveafterrun”.
6. Runthecoding.
7. Aftersuccessfulrun,selectsignalstoshowwaveforms.

Fig#1:EDAplaygroundtestbenchprogrammingandinitialsettings
Exercise:

Designafulladdercircuitalongwithitstestbench.Youmaygivefourinputvectors(fromthetable)
inthetestbench andobservetheoutputfrom waveforms.

a b c_in sum c_out


1 0 0 1
2 1 1 0
3 1 0 1
4 1 1 1

Additionally,youarerequiredtoattachtheinputandoutputwaveformsinyourlabreport.

SOLUTION:

Design code:
module full_adder (
input a, // First input
input b, // Second input
input c_in, // Carry input
output sum, // Sum output
output c_out // Carry output );

assign sum = a ^ b ^ c_in; // XOR operation for sum


assign c_out = (a & b) | (c_in & (a ^ b)); // Carry out logic
endmodule

Testbench:
module testbench;
reg a, b, c_in; // Inputs to the full adder
wire sum, c_out; // Outputs from the full adder
// Instantiate the full adder module
full_adder fa ( .a(a), .b(b), .c_in(c_in), .sum(sum), .c_out(c_out) );
initial begin
// Open VCD file for waveform
$dumpfile("full_adder_tb.vcd");
$dumpvars;
// Display the headers
$display("Time\t a b c_in | sum c_out");
$monitor("%g\t %b %b %b | %b %b", $time, a, b, c_in, sum, c_out);
// Test vector 1
a = 1; b = 0; c_in = 0;
#10;
// Test vector 2
a = 1; b = 1; c_in = 0;
#10;
// Test vector 3
a = 1; b = 0; c_in = 1;
#10;
// Test vector 4
a = 1; b = 1; c_in = 1;
#10;
$finish; // Terminate simulation
end
endmodule

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy