example square wave - mechanical engineering例方波-机械工程

example square wave - mechanical engineering例方波-机械工程

ID:9368812

大小:703.00 KB

页数:15页

时间:2018-04-29

上传者:jjuclb
example square wave - mechanical engineering例方波-机械工程_第1页
example square wave - mechanical engineering例方波-机械工程_第2页
example square wave - mechanical engineering例方波-机械工程_第3页
example square wave - mechanical engineering例方波-机械工程_第4页
example square wave - mechanical engineering例方波-机械工程_第5页
资源描述:

《example square wave - mechanical engineering例方波-机械工程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEEXAMPLESQUAREWAVEOBJECTIVEThisexamplehasthefollowingobjectives:·Reviewtheuseparallelports·IllustratethegenerationofasquarewaveusingPortBoutputandawaitingsequence·Demonstratetheuseofasubroutinetoshortenthelengthofaprogram·ExaminetherelationbetweendisplayedsimulationtimeandclockcyclesinTHRSim11simulatorFigure1Squarewaveschematicsshowingthehalf-waveduration,Dt,andthelow(L)andhigh(H)states.PROGRAMSThisexampleusestwoprogramsthatproducethesameoutput–thegenerationofasquarewaveofprogrammablewavelength.ThewavelengthisprogrammedusingthevariableDELAY.Thesquare-waveelectricalsignalisoutputthroughsecondpinofPortB,i.e.,pinPB1.Thedifferencebetweenthefirstandsecondprogramconsistintheuseofasubroutine.Theuseofasubroutinecompressesthecodeandshortensthetotallengthoftheprogram.Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEProgramsq_wav1InstructionsDefinevariableDELAYat$0000LoadREGBASinreg.XSendlowsignalLoad%00000000inaccAStoreaccAinPortBLoadDELAYintoaccBDecreaseaccBinaloopuntilzeroSendhighsignalLoad%00000010inaccAStoreaccAinPortBLoadDELAYintoaccBDecreaseaccBinaloopuntilzeroBranchbackto(iii)SWIFlowchartCodeDELAYRMB1*StartmainprogramORGPROGRAMSTARTLDX#REGBAS*Begintypingyourcode*SendlowsignalBEGINLDAA#%00000000STAAPORTB,XLDABDELAYLABEL1SUBB#1BHILABEL1*SendhighsignalLDAA#%00000010STAAPORTB,XLDABDELAYLABEL2SUBB#1BHILABEL2BRABEGINSWIFLOWCHARTANDCODETheprogramflowchartisshowtotherightoftheprograminstructions.Notethe‘sendlowsignal’and‘sendhighsignal’blocks.Alsonotethetwowaitblocks,onesendingthelowsignal,theotheraftersendingthehighsignal.Thewaitblocksarenotdetailed,sincetheyhavebeencoveredinapreviousexampleandcanbedirectlyclonedfromthere(the‘codereuse’concept).Theessentialcodeforthisprogramisshowntotheleftoftheflowchart.ThefileSq_wav1.asmistheresultofincorporatingthiscodeinthestandardtemplate.EXECUTIONOpenTHRSim11.ClosetheCommandswindow.Openmemorylist,portregisters,andTHRSim11IObox.OpenandassembleSq_wav1.asm.SetbreakpointatSWIasaninsuranceagainsttheprogramrunningwild.Resettheregisters.Setstandardlabels(Label/SetStandardLabels).SetdisplayofaccAtobinary.SetdisplayofPORTBtobinary.Tilewindows.Arrangewindowsformaximumbenefit:memory$0000only;registersAthroughX;sufficientof.asmand.LSTwindowstoshowthecode.ResetDELAY,A,B,X.Yourscreenshouldlooklikethis:Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEa)Put$04intovariableDELAY.Resetthesimulator.ThePORTBregisteris%00000000,andallthelightsintheTHRSim11IOboxareoff.b)Notetheinitializationreadings:clockcycles=2,simulatedtime=0.0000010sec=1.0ms.ThesevaluesareenteredasN_1andT_1inthe"Initialize"rowofTable1.c)Makeonestepthroughtheprogram.TheREGBASvalueof$1000isbeingloadedintoX.ThiswillassistwithaccessingtheportregistersinExtendedmodeusingregisterX.Yourscreenlookslikethis:Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEa)Thisistheendoftheinitializationcycleandthebeginningofthelow-signalpart,L,ofthesquarewave.Steptwice.Yourscreenlookslikethis:Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEa)Notethestartupreadings:clockcycles=11,simulatedtime=0.0000055sec=5.5ms.ThesevaluesareenteredasN_2andT_2intheInitializerow,andasN_1andT_1inthefirst(L)rowofTable1.Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVETable1a)StepthroughtheprogramuntilPORTBbecomes%00000010andPB1inTHRSim11IOboxturnson.Yourscreenlookslikethis:Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVENotetheclockcyclesandthesimulatedtimeasN_2=40andT_2=20.0thefirst(L)rowofTable1.ComputeDN=29andDT=14.5.AlsocomputeDN/DT=2.000andDT/DN=0.500.EnterthecurrentvaluesN_2=40andT_2=20.0asN_1=40andT_1=20.0inthefirst(H)rowofTable1.a)StepthroughtheprogramuntilPORTBbecomesagain%00000000andPB1inTHRSim11IOboxturnsoff.Yourscreenlookslikethis:Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVENotetheclockcyclesandthesimulatedtimeasN_2=72andT_2=36.0inTable1.ComputeDN=32andDT=16.0.AlsocomputeDN/DT=2.000andDT/DN=0.500.EntertheN_2andT_2valuesofthis(H)rowasN_1andT_1valuesonthenext(L)row.a)Youarenowagaininalow-signalstate.StepthroughtheprogramuntilthelightPB1comesonagain.YourscreenlookslikethisDr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEObservetheN_2andT_2valuesandcomparethemwiththeappropriatevaluesinTable1.a)Repeatthisuntilallthevaluesinthe$04portionofTable1havebeenobserved.NotethattheratiosDN/DTandDT/DNareconsistently2.000and0.500,astheoreticallypredicted.b)Also,notethewavelengthofyoursquarewave.Thelow(L)portionofthesignalhas29cycles,i.e.,14.5ms,whilethehigh(H)portionhas32cycles,i.e.,16.0ms.TheHportionislongersinceinincludesanadditionaloperation,BRA,whichbringsusbacktothebeginningoftheprogram.However,athigherwavelength,thesedifferenceswillfadeaway.TheseobservationsareimportantforfutureuseoftheMCUasatimingdevice.c)Setbreakpointsat$c007and$c011.Thesepointscorrespondtothemomentsjustafterthesendingof%00000000toPORTB,andthesendingof%00000010toPORTB,respectively.Thesebreakpointswillallowustoruntheprogramautomatically,ensuringthatitwillstopeachtimethesignalstatusischanged.d)ResettheMCU.Observeagaintheclockcyclesandthesimulatedtime,andverifythattheycorrespondtotheN_1=2andT_1=1.0onrow‘$04Initialize’inTable1.e)Runtothefirstbreakpoint.VerifyN_2=11andT_2=5.5inTable1.f)Runtothenextbreakpoint.YouhaverunthroughthefirstLlap.VerifyN_2=40andT_2=20.0onthecorrespondingrowinTable1.g)Runtothenextbreakpoint.YouhaverunthroughthefirstHlap.VerifyN_2=72andT_2=36.0onthecorrespondingrowinTable1.h)Repeatuntilyouhaveexhaustedthe$04portionofTable2.ObservetheratiosDN/DTandDT/DNNotethattheratiosDN/DTandDT/DNareconsistently2.000and0.500,astheoreticallypredicted.i)Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEPut$40intothevariableDELAY.Resetthesimulator.RepeattheaboveprocedureandverifythevaluesenteredinTable2underthe$40section.ObservethedurationsoftheLandHhalf-wavesofthesquarewave.Theyare164-165msand166ms,respectively.TheconsistencyoftheLandHpartsofsignalhasgreatlyimproved.ObservetheratiosDN/DTandDT/DNNotethattheratiosDN/DTandDT/DNareconsistently2.000and0.500,astheoreticallypredicted.Programsq_wav2Instructions(i)DefinevariableDELAYat$0000LoadREGBASinreg.XSendlowsignalLoad%00000000inaccAStoreaccAinPortBJumptosubroutineWAITSendhighsignalLoad%00000010inaccAStoreaccAinPortBJumptosubroutineWAITBranchbackto(iii)SWISubroutineWAIT(ii)LoadDELAYintoaccB(iii)DecreaseDELAY(iv)Loopuntilzero(v)ReturnfromsubroutineFlowchartCodeDELAYRMB1*StartmainprogramORGPROGRAMSTARTLDX#REGBASBEGINLDAA#%00000000STAAPORTB,XJSRSR_WAITLDAA#%00000010STAAPORTB,XJSRSR_WAITBRABEGINSR_WAITLDABDELAYLABEL1SUBB#1BHILABEL1RTSSWIFLOWCHARTANDCODETheprogramflowchartisshowtotheleftoftheprograminstructions.Notethe‘sendlowsignal’and‘sendhighsignal’blocks.Also,notethatthetwowaitblocksoftheprogramSq_wav1havebeenreplacedbyasinglesubroutineblockthatisrepeatedlycalled.Theessentialcodeforthisprogramisshowntotheleftoftheflowchart.ThefileSq_wav2.asmistheresultofincorporatingthiscodeinthestandardtemplate.EXECUTIONOpenandassembleSq_wav2.asm.SetbreakpointatSWI,andresetregisters.Setstandardlabels(Label/SetStandardLabels).SetdisplayofaccAtobinary.SetdisplayofPORTBtobinary.Tileandarrangewindowsformaximumbenefit:memory$0000only;registersAthroughX;sufficientof.asmand.LSTwindowstoshowthecode.ResetDELAY,A,B,X.DONOTRESETTHESP(stackpointer)REGISTER,BECAUSE,IFYOUDOSO,ACCESSTOYOURSUBROUTINEWILLNOTWORK.Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEa)Put$04intovariableDELAY.Resetthesimulator.ThePORTBregisteris%00000000,andallthelightsintheTHRSim11IOboxareoff.Stepthroughtheprogramuntilyoureachsubroutine.Yourscreenwilllooklikethis:b)StepthroughthesubroutineuntilyougettoRTSandarereadytojumpbacktotheprogram.Yourscreenlookslikethis:c)Afteranotherstep,youarebackintothemainprogram:Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEa)Asyoustepfurther,youobservethatthePortBpin1istoggled,andthelightPB1intheIOboxcomeson.Themainprogramisagainreadytojumptothesubroutine:b)Furthersteppingtakesyoubackintothesubroutine,andoutagain.c)Runtheprogramonautomatic.YouwillnoticehowthesubroutineisaccessedeverytimethePB1lightchanges.d)PutbreakpointsatthetwoJSRlines.Runtheprogramonautomatic,andrecordinTable2thevaluesrecordedforDELAY=$04,andforDELAY=$40.e)ComparethevaluesfromTable2withthoseinTable1.Youwillnotice:i)Forsamevaluesofdelay(say,DELAY=$04),thedurationofthehalfwavesaredifferent:inTable2(20msand21.5ms)fromthoseinTable1(14.5msand16ms).Thisdifferenceisduetothedifferentwayinwhichthetwoprogramswereconstructed.Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEi)Atlowdelayvalues(DELAY=$04),thedifferencebetweenthedurationsoftheLandHhalfwavesissignificant(7.5%).Asthedelayincreased,thisdifferencefadesaway.AtDELAY=$40,thedifferencehascomedownto0.9%.Table2WHATYOUHAVELEARNEDInthisexample,youhavelearned:·TheuseofPortB·Theuseofdisplayedclockcyclesandsimulatedtime,andtheirrelativeaccuracy·Thefactthattheround-offerrorbecomeslesssevereasthemagnitudeofthenumberincreases·Theusefulnessofsubroutinesforshorteningprograms·TheuseofPortBtogenerateasquarewave·Newwordsandnotations:subroutine,jumptosubroutine(JSR),returnfromsubroutine(RTS),squarewave,wavelength,IO(Input-Output),IObox,accuracy,round-off.Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVE(Thispageisintentionallyleftblank)Dr.VictorGiurgiutiuPage142021/6/21 EMCH367FundamentalsofMicrocontrollersExampleSQUAREWAVEDr.VictorGiurgiutiuPage12021/6/21

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
大家都在看
近期热门
关闭