such as the one shown here. you can still buy this …...3 you would have been taught at least how...

16
1 Welcome to this MSc Lab Experiment. All my teaching materials for this Lab-based module are also available on the webpage: www.ee.ic.ac.uk/pcheung/teaching/MSc_Experiment/ The QR code here provides a shortcut to go to the course webpage. 2 This Lab Experiment is compulsory and its goal is to ensure that ALL students on this course get to a level of competence in digital design, Verilog and FPGAs as expected with our MSc graduates. If you are already experienced with Verilog and/or FPGAs, you will find this experiment quite easy. However, if you have not done either in your UG degree programme, this is a great chance for you to catch up. This Laboratory served as a “levelling” purpose – make sure that all students on the course reach a common level and standard in digital design. The learning outcomes for each of the four parts are: Part 1: Basic competence in using Intel/Altera’s Quartus design systems for Cyclone-V FPGA; appreciate the superiority of hardware description language over schematic capture for digital design; use of case statement to specify combinatorial circuit; use higher level constructs in Verilog to specify complex combinatorial circuits; develop competence in taking a design from description to hardware. Part 2: Use Verilog to specify sequential circuits; design of basic building blocks including: counters, linear-feedback shift-registers to generate pseudo- random numbers, basic state machines; using enable signals to implement globally synchronisation. Part 3: Understand how digital components communicate through synchronous serial interface; interfacing digital circuits to analogue components such as ADC and DAC; use of block memory in FPGAs; number system and arithmetic operations such as adders and multipliers; digital signal generation. Part 4: Understand how to implement a FIFO using counters as pointer registers and Block RAM as storage; implement a relatively complex digital circuit using different building blocks including: counters, finite state machines, registers, encoder/decoder, address computation unit, memory blocks, digital delay elements, synchronisers etc.; learn how to debug moderately complex digital circuits.

Upload: others

Post on 25-Apr-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

1

WelcometothisMScLabExperiment.AllmyteachingmaterialsforthisLab-basedmodulearealsoavailableonthewebpage:

www.ee.ic.ac.uk/pcheung/teaching/MSc_Experiment/

TheQRcodehereprovidesashortcuttogotothecoursewebpage.

2

ThisLabExperimentiscompulsoryanditsgoalistoensurethatALLstudentsonthiscoursegettoalevelofcompetenceindigitaldesign,VerilogandFPGAsasexpectedwithourMScgraduates.IfyouarealreadyexperiencedwithVerilogand/orFPGAs,youwillfindthisexperimentquiteeasy.However,ifyouhavenotdoneeitherinyourUGdegreeprogramme,thisisagreatchanceforyoutocatchup.ThisLaboratoryservedasa“levelling”purpose– makesurethatallstudentsonthecoursereachacommonlevelandstandardindigitaldesign.Thelearningoutcomesforeachofthefourpartsare:Part1: BasiccompetenceinusingIntel/Altera’sQuartusdesignsystemsforCyclone-VFPGA;appreciatethesuperiorityofhardwaredescriptionlanguageoverschematiccapturefordigitaldesign;useofcasestatementtospecifycombinatorialcircuit;usehigherlevelconstructsinVerilogtospecifycomplexcombinatorialcircuits;developcompetenceintakingadesignfromdescriptiontohardware.Part2: UseVerilogtospecifysequentialcircuits;designofbasicbuildingblocksincluding:counters,linear-feedbackshift-registerstogeneratepseudo-randomnumbers,basicstatemachines;usingenablesignalstoimplementgloballysynchronisation.Part3: Understandhowdigitalcomponentscommunicatethroughsynchronousserialinterface;interfacingdigitalcircuitstoanaloguecomponentssuchasADCandDAC;useofblockmemoryinFPGAs;numbersystemandarithmeticoperationssuchasaddersandmultipliers;digitalsignalgeneration.Part4: UnderstandhowtoimplementaFIFOusingcountersaspointerregistersandBlockRAMasstorage;implementarelativelycomplexdigitalcircuitusingdifferentbuildingblocksincluding:counters,finitestatemachines,registers,encoder/decoder,addresscomputationunit,memoryblocks,digitaldelayelements,synchronisersetc.;learnhowtodebugmoderatelycomplexdigitalcircuits.

Page 2: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

3

Youwouldhavebeentaughtatleasthowtoimplementdigitalcircuitsusinggatessuchastheoneshownhere.YoucanstillbuythischipwithFOURNANDgatesinonepackageandthisisknownasdiscretelogic.Wegenerallydonotusetheseanymore.Itisslow,expensive,consumeslotsofenergyandveryhardtouse.

Nevertheless,itisgoodtolearnaboutNANDandNORgatesbecause,usingDeMorgan’stheorem,youcouldintheorydesignandimplementaPentiummicroprocessorusingusetwoinputNANDorNORgatesalone.Itisthereforecouldberegardedasthebuildingblockofalldigitalcircuits.Similarly,youcouldintheorybuildacarusingonlybasicLegoblocks.Unfortunatelysuchacarwouldnotbeverygood.

4

Inearlydaysofintegratedcircuits,designersstartedusingrowsofbasicgates(shownasthedarkstuffherearrangedinrows).Theseareeithercompletelycustomised(full-custom)oritismadewithstandardrowsofgatesbutleavingthegatesunconnected.Foraspecificdesign,thegatesareconnectthroughwiresinthewiringchannels.Thereforethecustomisationisonlyinthewiringmetallayersandnotthelayerswithtransistors.Thisisknownas“semi-custom” application-specificintegratedcircuits(ASICs).

Page 3: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

5

Ofcourseyoucanalsocustomiseeverything– eachtransistorandeachwiringconnectinafull-custommanner.HereisthelayoutofInteli7microprocessor(with4cores).Designingsuchacircuitisveryexpensive,highlyrisky,andoncedesigned,itcannotbechanged.

Mostapplicationsinelectronicindustrycannotaffordtoembarkonsuchadesign.ThisdrivestheriseoftheFieldProgrammableGateArray.

6

SowhatisanFPGA?YoucameacrosstheideaofProgrammableLogicDeviceinthefirstyear,wheretheusercanprogramwhatthelogicgatedoes(beitaNANDorNORorsomeformofSUM-of-PRODUCTimplementation)oranadder,youasauser,can“program” thechiptoperformthatlogicfunction.Nowwecanaddanotherlayerofuserprogrammability– youcanprogramhowtheselogicgatesareconnectedtogether!Inthatway,wehaveageneralprogrammablelogicchip.Unlikethemicroprocessorwheretheprogramisjusttheinstructiontofixdigitalhardware,hereyoucanprogramthehardwareitself!

ThefirstFPGAwasintroducedbyXilinxin1985.Ithasarraysoflogicblockswhichareprogrammable.ItissurroundedbyPROGRAMMABLEROUTINGRESOURCES,whichallowstheusertodefinetheinterconnectionsbetweenthelogicblocks.Italsohaslotsofveryflexibleinputandoutputcircuits(programmableforTTL,CMOSandotherinterfacestandards).

Nowadays,therearetwomajorplayersintheFPGAdomain:XilinxandAltera(nowpartofIntel).Thesetwodomains90%oftheFPGAmarketwithroughlyequalshare.

Page 4: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

7

LetuslookinsideanFPGA.Considerthelogicblockshowninblueinthelastslide(AlteracallstheirlogicblockaLogicElement(LE)).TypicallyanLEconsistsofa4-inputLook-upTable(LUT)andaD-flipflop.LetusfornowNOTtoworryabouthowthe4-LUTisimplementedinternally.Justtreatthisasa4-inputcombinatorialcircuitwhichproducesoneoutputsignalasshownhere.TheIMPORTANTcharacteristicisthatthe4-LUTcanbeuserdefined(orprogrammable)toimplementANY4-inputBooleanfunction.Aswewillseelater,thelookuptableisactuallyimplementedwithabunchofmultiplexers.

8

TheLogicElementsaresurroundedbylotsofroutingwiresandinterconnectionswitches.TypicallyasignalwiretotheLogicBlockorLogicElementcanbeconnectedtoanyofthesewiringchannelsthroughaprogrammableconnection(essentiallyadigitalswitch).XilinxFPGAsalsohavededicatedswitchblocksshownhere.Horizontalandverticalwirescanbeconnectedthroughsuchasswitchblockwithprogrammableswitches(don’tworryfornowhowthat’sdone).

FPGAshavehugeamountoftheseprogrammableresourcesandswitches.Typicallyaverysmallpercentageofthesearebeingconnected(i.e.ON)foragivenapplication.

Themainadvantageand“power” ofFPGAcomesfromtheprogrammableinterconnect– moresothantheprogrammablelogic.

Page 5: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

9

ProgramminganFPGAiscalled“configuration”.Inprogrammingacomputerormicroprocessor,wesendtothecomputerinstructioncodesas‘1’sand‘0’’s.Theseareinterpreted(ordecoded)bythecomputerwhichwillfollowtheinstructiontoperformtasks.Themicroprocessorneedstobefedtheseprogramcodescontinuouslyforittofunction.

InFPGAs,youonlyneedtoconfigure thechipONCEonpower-up.YoudownloadtothechipaBITSTREAM (alsobitsin‘1’sand‘0’s),whichdeterminesthelogicfunctionsperformedbytheLogicElements,andtheinterconnectingswitchesinordertoconnectthedifferentLEstogethertomakeupyourcircuit.Oncethebitstreamisreceived,theFPGAnolongerneedstoreadthe1’sand0’sagain,veryunlikeamicroprocessorwhichhastocontinuallydecodingthemachineinstructions.That’swhywesometimessaythatweconfigure anFPGA(insteadofprogramminganFPGA,althoughthetwowordsareusedinterchangeably).

WhathappenswhenyouconfigureanFPGA?Letusconsiderthe4-inputLUTscircuit.Thisistypicallyimplementusingatreeoffourlayersof2-inputto1-outputmultiplexers.Theentirecircuitisbehavinglikea16-to-1multiplexerusingthe4inputsABCDasthecontroloftheMUXtree.Forexample,ifABCD=0000,thenthetopmostinputoftheMUXisroutedtoYoutput.

Inthisway,ABCDformstheinputcolumnsofatruthtable.For4-inputs,thetruthtablehas16entries.TheoutputYforeachofthetruthtableentrycorrespondstotheinputoftheMUX.Configurationinvolvesfixingtheinputstothe16-to-1MUXbystoring‘1’ or‘0’ intheregistersR.Changingthe16valuesstored,youcanchangetotruth-tabletoanythingyouwant.

10

Toconfiguretheprogrammablerouting,letuslookathowtheroutingcircuitworks.TakeXilinxSWITCHBLOCKcircuit(greenblocksinslide7).Thisblockcontrolstheconnectionsbetweenfourhorizontalchannelsandfourverticalchannels.Thediamondshapedblockisapotentialinterconnectsite.Insidetheswitchblockcircuit,thereare6transistorswitcheswhichareinitiallyallOFF(oropencircuit).

ThegateinputofEACHswitchiscontrolledbytheoutputofa1-bitregister(e.g.a1-bitD-FF).Iftheregisterstoresa‘1’,theroutingtransistorwillhaveitsgatedrivenhigh.SincethetransistorisannMOStransistor,itwillbecomeconducting.Inthisway,configuringtheroutingresourcessimplymeansthatthecorrect‘1’sand‘0’sarestoredintheregistersthatcontroltheseroutingtransistors.

Asyouwouldexpect,typicallyanFPGAwouldhavehundredsofthousandsoftheseroutingswitches,mostoftheseareOFF.Onceprogrammed,theinterconnectionsaremade.Theboldlinesinthediagramabove(afterprogramming)showstheprogrammedconnections.

Bitsteaminformationusedforconfigurationpurposeareusuallystoredonaflashmemorychip,whichisdownloadtotheFPGAduringpower-up– similarto“bootingupacomputer”.Oncethisisdone,theFPGAisprogammedtoperformaspecificuserfunction(e.g.yourdesignintheVERIexperiment).

AlternativelyyoucansendthebitstreamtotheFPGAviaacomputerconnectiontothechip.OntheDE1-SOCboard,itdoesboth.PowerupDE1willconfiguretheCycloneVFPGAchiptoa“waiting”mode,whichmakestheDE1boardtalktothecomputerviatheUSBportwhileflashingthelightsONandOFF.YouthensendtotheboardabitstreamofyourdesignviatheUSBport.

Page 6: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

11

LetusnowlookattheFPGAthatyouwilluseforthiscourse.TheAlteraCycloneVFPGAhasamoreadvancedprogrammablelogicelementthanthesimple4-inputLUTthatwehaveconsidereduptonow.ThecallthisaAdaptiveLogicModuleorALM.

AnALMcantakeupto8Booleaninputsignalsandproducesfouroutputswithorwithoutaregister.Additionally,eachALMalsocanperformthefunctionofa2-bitbinaryfulladder.

AsauseroftheCycloneVFPGA,youdon’tactuallyneedtoworrytoomuchaboutexactlyhowtheALMisconfiguredtoimplementyourdesign.TheCADsoftwarewilltakecareofthemappingbetweenyourdesignandthephysicalimplementationusingtheALMs.Itishoweverusefultoknowthatasthetechnologyevolves,moreandmorecomplicatedprogrammablelogicelementsarebeingdevelopedbythemanufacturersinordertoimprovetheareautilizationoftheFPGAs.

TheCycloneVontheDE1-SOCboardhas32,000ALMs,whichcouldbeestimatedtobeequivalentto85K+theoldstyleLEs.Puttingthisincontext,youcouldputontothisonechip2,00032-bitbinaryaddercircuits!

12

TheCycloneVismuchmorethanjustanFPGAwithabunchofLogicElements(orALMs).OurchipintheDE1-SOCboardhas32,000ALMs,whichisaround85Koldstyle4-inputLUTLEs.Ontopofthat,italsohasover4Mbitofembeddedmemory,87DSPblocks(todomultiply-accumulateoperationsneededforsignalprocessing),andevenadual-coreARMmicroprocessor!

Ithashard-logictoimplementPCIeinterface(tofastperipherals)andexternalmemoryinterfacetoconnecttoexternalmemory.Itisatrulypowerfulchipontowhichonecouldimplementanentiredigitalelectronicsystem.ThereforeAlteracallthisCycloneVSystem-on-Chip(SoC).

Page 7: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

13

Forthislab-basedmodule,youwillbedesigningcircuitsusingthefreeversionofthedesignsuiteknownasQuartusPrimeLitefromIntel/Altera.Youcandownloadyourowncopyontoyournotebookmachine,oryoucanusetheversionsthatareinstalledinanyPCslocatedanywhereinthedepartment.

ThisverypowerfuldesigntoolcontainseverythingyouneedtodesignacomplexdigitalsystemONYOUROWNCOMPUTER!However,thesoftwareonlyrunsoneitheraMSWindowsoraLinuxoperatingsystem.IfyouareusingaMac,youwouldneedtorunaVirtualMachineapplications(suchasVirtualBox)andinstallWindowsorLinuxbeforeinstallingQuartusIIsoftware.

Bewarethatthesoftwareisverylarge– youneedtohaveseveralGBoffreediskspace.TheminimumrequiredRAMis4GB,and8GBisrecommended.

Ifyourlaptopissuitable,dodownloadthissoftwareandplaywithitathome.

14

ThisslideshowsyouthefunctionalblocksoftheDE1-SoCboard.Thishaseverythingyouneedtestbasicdesignsinvolvingswitches,7-segmentdisplaysandevenaVGAoutput.

Page 8: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

15

Ialsoprovideapurpose-builtADC/DACboardtosupportthelabexperiment.Thisadd-onboardinonlyneededinweek3onwardsduringthelaboratorysessions.Sofornow,youcanignoreit.

16

Youareveryfamiliarwithschematiccapture.Inthefirstyear,youusedSPICEforsimulatinganaloguecircuitsandQuartusIIforyourdigitalexperimentwhereyoucreateschematiccircuitswithgates.

HowevermoderndigitaldesignmethodsingeneralDONOTuseschematics.Insteadanengineerwouldspecifythedesignrequirementorthealgorithmtobeimplementedinsomeformofcomputerlanguagespeciallydesignedtodescribehardware.Thesearecalled“HardwareDescriptionLanguages”(HDLs).

ThemostimportantadvantagesofHDLasameansofspecifyingyourdigitaldesignare:1)Youcanmakethedesigntakeonparameters(suchasnumberofbitsinanadder);2)itismucheasiertousecompilationandsynthesistoolswithatextfilethanwithschematic;3)itisverydifficulttoexpressanalgorithmindiagramform,butitisveryeasywithacomputerlanguage;4)youcanusevariousdatapathoperatorssuchas+,*etc.;5)youcaneasilyedit,storeandtransmitatextfile,andmuchhardwarewithaschematicdiagram.

Fordigitaldesigns,schematicisNOTanoption.AlwaysuseHDL.Inthislecture,Iwilldemonstratetoyouwhywithanexample.

Page 9: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

17

IhavechosentouseVerilogHDLasthehardwaredescriptionlanguageforthecourse.VerilogisverysimilartotheClanguage,whichyoushouldalreadyknowfromyourfirstyearcourse.However,youmustalwaysrememberthatYOUAREUSINGITTODESCRIBEHARDWAREANDNOTACOMPUTERPROGRAMME.

YoucanuseVerilogtodescribeyourdigitalhardwareinthreedifferentlevelofabstraction:1) BehaviouralLevel – youonlydescribehowthehardwareshouldbehavewithoutANYreferencetodigitalhardware.2) Register-Transfer-Level(RTL)– Herethedescriptionassumetheexistenceofregistersandtheseareclockedbyclocksignal.Thereforedigitaldataistransferredfromoneregistertothenextonsuccessfulclockcycles.Timing(intermsofclockcycles)isthereforeexplicitlydefinedintheVerilogonce.Thisisthelevelofdesignweuseonthiscourse.3) GateLevel– thisisthelowleveldescriptionwhereeachgateisdescribedandhowtheseareconnectedtogetherisspecified.VerilogisnotonlyaspecificationlanguagewhichtellstheCADsystemwhathardwareissupposetodo,italsoincludesacompletesimulationenvironment.AVerilogcompilerdoesmorethanmappingyourcodetohardware,italsocansimulate (orexecute)yourdesigntopredictthebehaviourofyourcircuit.Itisthepredominantlanguageusedforchipdesign.

18

ThisisaVerilogcodemodulethatspecifiesa2-to-1multiplexer.ItisrathersimilartoaCfunction(exceptforthemodule keyword).

ItisimportanttorememberthebasicstructureofaVerilogmodule.Thereisamodulename:mux2to1.Thereisalistofinterfaceports:3inputsa,bandsel,and2outputsoutandoutbar.Alwaysusemeaningfulnamesforbothmodulenameandvariablenames.

Youmustspecifywhichportisinputandwhichportisoutput,similartothedatatypedeclarationinaCprogramme.

Finally,the2-to-1multiplexingfunctionisspecifiedintheassignstatementwithaconstructthatisfoundinC.Thisisabehaviouraldescriptionofthemultiplexer– nogatesareinvolved.Thelaststatementspecifiestherelationshipbetweenout andoutbar.ItisimportanttorememberthatVerilogdescribesHARDWAREnotinstructioncode.Thetwoassign statementsspecifyhardwarethat“execute” orperformthetwohardwarefunctionsinparallel.Thereforetheirorderdoesnotmatter.

Page 10: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

19

Continuousassignmentspecifiescombinationalcircuits– outputiscontinuouslyreflectingtheoperationsappliedtotheinput,justlikehardware.Rememberthatunlikeaprogramminglanguage,thetwocontinuousassignmentstatementshereAREspecifyinghardwareinPARALLEL,notinseries.HerewealsoseetheconditionalassignmentstatementthatisfoundinC.Thismapsperfectlytothefunctionofa2-to-1multiplexerinhardwareandiswidelyusedinVerilog.Furthermore,therearemanyotherBooleanandarithmeticoperatorsdefinedinVerilog(asinC).HereisaquicksummaryofalltheVerilogoperators(usedinanexpression).

20

WhilethepreviousVerilogcodeforthe2-to-1muxonlyspecify“behaviour”,hereisonethatspecifyagateimplementationofthesamecircuit.Threetypesofgatesareused:and,orannotgates.Thereareinternalnets(declaredaswire)whichtakeonanynames.

Keywordssuchasand,or andxor arespecial– theyspecifyactuallogicgates.Theyarealsospecialinthatthenumberofinputstotheand-gatecanbe2,3,4,…..Anylength!

NotethatthismoduleusesTWOANDgates,andtheyhavedifferentnames:a1anda2.ThereareTWOseparateinstancesoftheANDgate.Forsoftwarefunctions,“calling” afunctionsimpleexecutethesamepieceofprogrammecode.Herethetwolines“anda1(out1,…” and“anda2(out2…” producetwoseparatepieceofhardware.Wesaythateachlineis“instantiating” anANDgate.

Wiringupthegatesisthroughtheuseofportsandwires,anddependsonthepositionsofthese“nets”.Forexample,out1istheoutputnetoftheANDgatea1,anditisconnecttotheinputoftheORgateo1byvirtualofitslocationinthegateportlist.

Page 11: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

21

SofarwehaveusedVeriloginaveryhardwarespecificway.“assign” andusinggatespecificationarespecialtoVerilog.

HereissomethingthatismorelikeC– anditiscalled“proceduralassignment”.Typicallyweusesomethingcalled“always” blocktospecifya“procedure” orcollectionofsequentialstatementswhicharesandwichedbetweenbegin-endconstruct.

Thealwaysblockneedsasensitivelist– alistofsignalssuchthatifANYofthesesignalchanges,thealwaysblockwillbeinvoked.Youmayreadthisblockas:

“alwaysatanychangesinnetsa,borsel,dothebitsbetweenbeginand end”Actually,ifyouaredefiningacombinationalcircuitmodule,anevenbetterwaytodefinethealwaysblockistouse:…..always@*....//alwaysatanychangewithanyinputsignals

Insidethebegin-endblock,youareallowedtouseC-likestatements.Inthiscase,weusetheif-elsestatement.Allstatementsinsidethebegin-endblockareexecutedsequentially.

22

NotethatVerilogkeywordreg doesnotimpliesthatthereisaregistercreatedinthehardware.Itismuchmorelikedeclaringavariablethatholdsavalue.ItisaruleinVerilogthatassignmentINSIDEanalwaysblockMUSTbedeclaredreg,andNOTanet(wire).ThisisoneofthefewpeculiaritiesofVerilogthatcanbeconfusingtostudents.

Page 12: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

23

ThisslideshowshowtheproceduralstatementismappedtothebasicMUXcircuit.ThecontinuousassignmentstatementcorrespondstotheNOTgate.

24

ThisisyetanotherwaytospecifytheMUXcircuit.Itisstillaproceduralassignmentwiththe“always” block.However,wereplacetheif-elsestatementwitha“case”statement.Thecasevariableissel.Sinceselisa1-bitsignal(ornet),itcanonlytakeon0or1.

Notethatthevariouscasevaluescanbeexpressedindifferentnumberformatsasshownintheslide.Forexample,consider2’b10.The2isthenumberofbitsinthisnumber.‘bmeansitisspecifiedinbinaryformat.Thevalueofthisnumberis10inbinary.

Page 13: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

25

Thisslidedemonstrateswhylanguagespecificationofhardwareissomuchbetterthanschematicdiagrams.Bysimpledeclaringthesignalsasamulti-bitbus(8bits[7:0]),wechangethismoduletoonethatspecifies8separate2-to-1multiplexers.

Anotherusefulwaytospecifyabusisusingtheconcatenationoperator:{….}asshownabove.

Theconcatenationoperatorisparticularlyusefulinconvertingdigitalsignalsfromonewordlength(i.e.numberofbitsinaword)toanother.Forexample,toconvertan8-bitunsignednumbera[7:0]toa13-bitunsignednumberb[12:0],youcansimpledothis:

assign b[12:0] = {5’b0, a[7:0]};

26

Hereisasimpleexample:thedesign ofa4-bithexcodeto7segmentdecoder.Youcanexpressthefunctionofthis7-segmentdecoderinthreeforms:1)asatruthtable(notethatthesegmentsarelowactive);2)as7separateK-maps(shownhereisforout6segmentonly);3)asBooleanequations.

ThisisprobablythelasttimeyouseeK-maps.Inpracticaldigitaldesign,youwouldrelyheavilyonCADtools.Inwhichcase,thelogicsimplificationsaredoneforyouautomatically– youneverneedtouseK-mapstodothatmanually!

Page 14: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

27

Hereisatediousimplementationintheformofschematicofinterconnectedgates.Veryhardtodoandverypronetoerrors.

28

OnecouldtakeagroupofgatesandspecifythegatesinVeriloggateprimitivessuchasand,oretc.Stillverytedious.Hereistheimplementationfortheout6output.

Page 15: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

29

Insteadofspecifyingeachgateseparately,hereisusingcontinuousassignmentstatement,mappingtheBooleanequationdirectiontoasingleVerilogstatement.Thisisbetter.

30

Hereisthecompletespecificationofthehex_to_7segmoduleusingcontinuousassignment.ItshowshowoneshouldwriteVerilogcodewithgoodcommentsandcleardocumentationofinputandoutputports.

Page 16: such as the one shown here. You can still buy this …...3 You would have been taught at least how to implement digital circuits using gates such as the one shown here. You can still

31

Finallythe4th methodisthebest.Weusethecaseconstructtospecifythebehaviourofthedecoder.Hereonedirectlymapsthetruthtabletothecasestatement – easyandelegant.

Insteadofusing:always@(in),youcouldalsousealways@*

32

HowisaVerilogdescriptionofahardwaremoduleturnedintoFPGAconfiguration?ThisflowdiagramshowsthevariousstepstakeninsidetheQuartus IICADsystem.

FortheLabExperiment,youwillbeworkinginpairs.Inothertoensurethatyougettoknoweachother,IhaverandomlypairedyoutogetherwithsomeoneelseasLabPartnerforthismodule.