Professional Documents
Culture Documents
WaqarNabi/NidaRasheed
Session1: ThislabsessionisdesignedtofamiliarizeyouwiththeuseoftheXilinxISE10.1.Afterthislab youshouldbeabletodesignaverilogmodule,synthesizeitandsimulateinXilinxISE10.1. Exercise1.1:GettingStarted In this exercise you are going to start using Xilinx ISE 10.1. The top level modules and the testbenchforexercise1.1areprovidedsothatyoucaneasilyexploretheXilinxtool. counter.visatoplevelmodule,itisa4bitcounterthatcountsfrom0to15andgoesbackto zero.testbench_counter.visatestbenchtotestthecounter. Exercise1.2:DesignHalfAdder Completethefollowingsteps 1. Complete/writethehalfaddermodulethatwasdescribedinthelecture.Thediagram ofhalfadderisshowninfigure1.1.
Figure1.1:HalfAdder
2. Writeatestbenchforthehalfadder. 3. Checkandverifytheresultsforthecounter.
Page|2
sum
Mux32_4_1
32 c_out
c_out
Figure2.1:Multiplexer4to1
Figure2.2:4bitRippleCarryAdder
Page|3
Exercise2.3:2bitbinarycompa arator comparator compares t two bit bina words, A and B, and asserts ou ary A utputs indic cating A 2bit c whetherthedecimalequivalentofwordAis slessthan,g greaterthan n,orequalto othatofwo ordB. ethefollowingsteps Complete
gure2.3:2b bitBinaryCo omparator Fig 1. W Writethecod defor2bit comparator rusinggate levelmodeling,blockd diagramissh hown in nfigure2.3. 2. W Writethetestbenchfort thetoplevel lmoduleand dverifytheresults.
Pag ge|4
Session3: Inthissessionyouwilllearnsimulationcontrol,behavioralmodelingusingcontinuous assignment,andproceduralblocksforcombinationallogic. Exercise3.1:Behavioralmodelsof4to1Multiplexer As you have completed the lab exercise 2.1 now you have to design same 4to1 multiplexer usingthebehavioralmodeling.Completethefollowingsteps 1. Design4to1multiplexerusingcontinuousassignmentstatements. 2. Design4to1multiplexerusingalways@module. 3. Testandverifytheresultsofbothmodulesusingthetestbenchofexercise2.1. Exercise3.2:FullSubtractorusingBooleanEquations A full subtractor has three 1bit inputs x, y, and z (previous borrow) and two 1bit outputs D (difference)andB(borrow).ThelogicequationsforDandBareasfollows:
D=x'.y'.z+x'.y.z'+x.y'.z'+x.y.z B=x'.y+x'.z+y.z
1. WritethefullVerilogdescriptionofthefullsubtractormodule,includingI/Oports. 2. Instantiate the full subtractor inside a stimulus and test all possible inputs and verify themfromthetable3.1. Table3.1:Truthtableforfullsubtractor
x
0 0 0 0 1 1 1 1
y
0 0 1 1 0 0 1 1
z
0 1 0 1 0 1 0 1
B
0 1 1 1 0 0 0 1
D
0 1 1 0 1 0 0 1
Page|5
Session4: Afterthissessionyoushouldbeabletodotimebasedandeventbasedcontrol,synchronous sequentiallogic,blockingandnonblockingassignments,tasksandfunctions. Exercise4.1:clockgenerationusingalways All behavioral statements inside an always statement constitute an always block. The always statementstartsattime0andexecutesthestatementsinthealwaysblockcontinuouslyina looping fashion. This statement is used to model a block of activity that is repeated continuouslyinadigitalcircuit. Designaclockgeneratorthatdoesnthaveanyinputandasingleoutputi.e.clock. Exercise4.2:+veandveclockedflipflops There is only one way to model either a positive edgetriggered flipflop or negative edge triggered flipflop. In this lab you have to model two flipflops one with positive edgetrigger andtheotherwithnegativeedgetrigger. 1. Writethecodeforthediagramshowninfigure4.1.
A0 D0 8 Q Y1
Clock Q
A1 D1 8 Q Y2
Figure4.1:PositiveandNegativeedgetriggeredflipflops 2. Writetestbenchandalsoverifytheresults.
Page|7
Exercise4.3:Synchronousreset,ASynchronousresetandenable Write a code to show the diagram as shown in figure 4.2. Also check the behavior of Synchronousreset,Asynchronousresetandenablesignals.Followthestepsgivenbelow 1. WriteverilogcodeforSynchronousreset. 2. WriteverilogcodeforAsynchronousreset. 3. Addenablesignalinthemodule.
Exercise4.5:BehaviorofBlockingandnonBlockingStatements After this lab exercise you should be able to understand the behavior of blocking and non blockingstatements. Writeaverilogcodeforthediagramgivenbelowandcheckthebehaviorofblockingandnon blockingstatementsusingstimulus.
1
Data_in
D Q
1
internal
D D Q
Data_out Clock
Q Q
Figure4.3:Blockingandnonblockingbehavior You have to notice the behavior of both environments blocking and nonblocking. Notice the changeofdataatoutputaccordingtotheinputchanged.
Page|9
5: Session5 Inthislab byouwillde esignusingc conditionals statements,loops,mode elingmuxes, , encoders s/decoders. Exercise5.1:Priority yEncoder 1. W Writeacodeforpriority encodershowninfigur re5.1.Youc canuseifstatementsor ralso th hecasexstat tements. Note that the con nditional (if) statements have an im ) mpliedprior of execu rity ution, andthatthe casexstatementscomb binedwithx xinthecase eitemsimpl liedpriority also. atements ignores x and z in bits of the case it d f tem and the are treate as ey ed The casex sta dontcares.
Figure5.1 1:PriorityEn ncoder Writeastimu ulustocheck kyourresult ts. 2. W Exercise5.2:BCDtosevensegm mentdisplay The sevensegment lightemitt t ting diode (LED) display is a ve useful circuit in m ery many applicatio onsusingpr rototypingboards.
Page e|10
Yourmoduleshouldtake4bitBCDinputandgivea7bitoutputtodisplayadigitontheseven segment.AssignyouroutputsforthesevensegmentLEDdisplaywhichisshowninfigure5.2.
Figure5.2:SevenSegmentLEDDisplay
Page|11
Session6 6: Inthisse essionofthelabyouwill ldesignafin nitestatema achine.Youwillmodelc countersand dalso shiftregisters. Exercise6.1:Univers salShiftReg gister rsalshiftreg gisterwithfo ollowingfeat tures Designa4bitUniver 1. 2. 3. 4. 5. 6. 7. Sy ynchronousreset. Parallelinput ts. uts. Paralleloutpu de. BidirectionalserialinputfromLSBsid BidirectionalserialinputfromMSBside. utfromLSBs side. Bidirectionalserialoutpu utfromMSBside. Bidirectionalserialoutpu
Statemachin ne(CarSpee edControl) Exercise6.2:FiniteS Designastatemachi ineofcarsp peedcontrollercorrespo ondingtothe estatemach hineinfigure e6.1. Alsowrit teatestbenc chforthisFS SM.
Figure6.1 1:Statediag gramforcar rspeedcont troller Exercise6.3:3bitup p/downcou unter Designa3bitcounte erasshowninfigure6.2 2.Thecountershouldincludefollow wingfeatures s 1. It tshouldcountinbothdi irectionsi.e. .up/down. 2. It tshouldload dsomedatatostartcou untingfromt thatvalue.
Page e|13
Data a_in
Page|14 e
Page|15
Session8: ThissessionisovertheRISCcontrollerfromCilettisbook,thatwasdiscussedinclass. Exercise8.1:TheRISCprocessor Firstofall,opentheRISCexample,runityourselfandseethatyouhaveatleastareasonably goodideaofhowitworks.(Atthispointthereisntenoughtimetolookateachandeveryline ofcode,butthatwouldbeagoodexerciseforlater) Exercise8.2:CarryflagintheRISCprocessor Now modify the design so that the Processors ALU creates a carry flag, asserted when the resultofanadditionoperationhasacarryout. YouwillneedtoaddaLoadsignalthatiscreatedinControl_Unit,andisinputtotheProcessor. Youwillneedtocreatacarrysignal,thatiscreatedinALU,loadedinaRegisterinProcessor, andfedtotheControlUnit. Note:thatalladditionsinthecodeforthiscarryflagwilllookverysimilartothewaytheZero flagisimplemented,soyoucanusethatasareference. Changethetestbenchtoensurethatduringtheprogramexecution,thecarryflagistested.
Page|16
Page|17
Page|18