LAB#1
LAB#1
er
SystemsEngineering
DigitalSystemDesign
Handout#01
Gate-LevelModellingandSimulation
LabLearningObjectives:
Aftercompletingthissession,studentshouldbeableto:
UnderstandbasicsofVerilogprogramming.
Getfamiliarwithstructuraldescription(moduleinstantiation).
Simulatebasiccombinationalcircuitsusinggate-levelmodelling.
Note:Submitthelabreport(solvedactivitiesandexercises)beforethenextlab.
LabHardwareandSoftwareRequired:
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.
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 );
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