$[ADCoutput - (-20,285)] / (49,931) * (120°C) + (-20°C)</p></li><li><p>TT101−(−20,285)=TT101Raw/49,931=TT101Frac∗120=TT101Span+(−20)=TTDegC</p></li></ul><h5id="7eca1296−e8cc−4b40−a78a−876b4273786e"data−toc−id="7eca1296−e8cc−4b40−a78a−876b4273786e"collapsed="false"seolevelmigrated="true">TemperatureControl</h5><p>Rung1usesasubtractinstructiontosubtractthetemperaturetransmitter′ssignal(TT101)from-20 285.TheoutputofthisinstructionisstoredastagTT101Raw(realnumber).</p><p>Rung2usesadivideinstructiontodivideTT101Rawby49 931.TheoutputofthisinstructionisstoredastagTT101Frac(realnumber).</p><p>Rung3usesamultiplicationinstructiontomultiplyTT101Fracby120.0.TheoutputofthisinstructionisstoredastagTT101Span(realnumber).</p><p>Rung4usesanadditioninstructiontoadd-20.0toTT101Span.TheoutputofthisinstructionisstoredastagTT101DegC(realnumber).</p><p>Rung5setstagLowtotrueifthetemperatureisbelow47°C.</p><p>Rung6setstagHightotrueifthetemperatureisabove53°C.</p><p>Rung7turnsontheheateriftagLowissettotrueandturnsofftheheaterifTagHighistrue.</p><p>∗NOTE:Theon/offswitch(TS)mustalsobeclosed.</p><p>TheLDprogramusedfourmathinstructionstoperformtherequiredoperations.Programmablelogiccontrollermanufacturersgenerallyprovideamathinstructionthatcanperformmultiplemathstepsinasingleinstruction.Thisinstructionhasaprogrammablepop−upwindowinwhichthecalculationissetoutinmuchthesamewayyouuseacalculator.</p><h4id="eb9685e4−3715−401a−86c5−ad07c740f4f6"data−toc−id="eb9685e4−3715−401a−86c5−ad07c740f4f6"collapsed="false"seolevelmigrated="true">ProportionalIntegralDerivativeInstruction</h4><p>Proportionalintegralderivative(PID)controlisfeedbackcontrolthatusesaPIDcontrolalgorithm.Inafeedbackcontrolsystem,theprocessvariable(PV)iscomparedtothesetpoint(SP)thatdeterminesanerror(e).ThePIDalgorithmactstoreducethemagnitudeoftheerrorbycalculatingacontrolleroutput(CO)signalwhichinturnaffectsthevalueofthePV.</p><ul><li><p>PIDControlAlgorithm:SP−e−PID−CO−PV</p></li></ul><p>TheSPisanoperator−generatedvaluethatindicatesthedesiredvalueatwhichtheoperatorwantsthePVtobe.ThePVisameasuredsignalthatmustbecommunicatedtothecontroller.TheCOisasignalfromthecontrollerthatmustbecommunicatedtothefinalcontrolelement(FCE).</p><p>YoucanprogramaPLCtoperformfeedbackcontrolwithoutusinganyspecializedinstructions;however,PLCvendorsprovideaPIDinstructionforthispurpose.ComplexinstructionssuchasthisarenotinIEC1131−3and,therefore,arevendor−specific.</p><h5id="363e041c−f15e−4c69−91f2−1fe6e2a5eac7"data−toc−id="363e041c−f15e−4c69−91f2−1fe6e2a5eac7"collapsed="false"seolevelmigrated="true">Arguments</h5><ul><li><p>TheENandENOargumentsallowtheinstructiontobeinsertedintoanLDrung.TheinstructionexecutesifENistrue;theENOargumentissettoequaltheENargument.</p></li><li><p>Theinstructionneedstobegivenatagname(forthisexampleTIC101).Whenthistagnameiscreatedinthetagbaseeditor,itmustbeofdatatypePID.</p></li><li><p>Thephysicaladdressortagfortheprocessvariable(PV)needstobespecified.</p></li><li><p>Thephysicaladdressortagforthecontroller′soutput(CO)needstobespecified.</p></li><li><p>Theconfigurationbuttonwhenactivatedbringsupapop−upwindowtoallowforconfigurationoftheoperationoftheinstructionforaspecificapplication.</p></li></ul><p>APIDinstructiongenerallyrequiresoperatorinteraction.Forexample,theoperatormaywishtodooneofthefollowing:</p><ul><li><p>TochangetheSP.</p></li><li><p>ToputthePIDinstructioninmanualmode,sothatheorshecanmanuallyadjusttheoutputsignaltotheFCE.</p></li><li><p>ToputthePIDinstructioninautomaticmode,sothattheinstruction′scalculatedoutputgoestotheFCE.</p></li><li><p>TochangethetuningparametersthataffecttheautomaticoperationofthePIDinstruction.</p></li></ul><h5id="e610eca8−faec−431f−989c−30bc5c081e63"data−toc−id="e610eca8−faec−431f−989c−30bc5c081e63"collapsed="false"seolevelmigrated="true">LegacySetup</h5><p>ThePIDinstructionisprogrammedusingthephysicaladdressfortheseinputsandoutputs.</p><ul><li><p>ThePIDinstructionisgivenatagname(TIC101)thatiscreatedintheeditorofthetagbase.</p></li><li><p>ThePIDinstruction′sPVisprogrammedforaphysicaladdress<1:50>towhichtheanaloginputchannelthePVsignal(TT101)isconnected.</p></li><li><p>ThePIDinstruction′sSPisprogrammedforaphysicaladdress<1:51>,theanaloginputchanneltowhichthemanualSPadjustdeviceisconnected.</p></li><li><p>ThePIDinstruction′sTiebackisprogrammedforaphysicaladdress<1:52>,theanaloginputchanneltowhichthemanualoutputadjustdeviceisconnected.</p></li><li><p>ThePIDinstruction′smodeisprogrammedforaphysicaladdress<1:30.00>,thedigitalinputbittowhichtheauto/manualswitchisconnected.</p></li><li><p>ThePIDinstruction′sCOisprogrammedforaphysicaladdress<0:61>,theanalogoutputchanneltowhichtheFCE(TY101)isconnected.</p></li></ul><p>Wheninautomatic,thePIDinstructioncalculatesthevalueofCOfromitsPVandSPinputs.Wheninmanual,theoperator−adjustedinput(Tieback)isusedastheCOoftheinstruction.ThedashedarrowindicatesthatthisvalueisalsousedbythePIDinstructiontoprovidebumplesstransfer.</p><h5id="5da36908−9ee3−4af2−a854−eb787fb49d3d"data−toc−id="5da36908−9ee3−4af2−a854−eb787fb49d3d"collapsed="false"seolevelmigrated="true">ModernSetup</h5><p>ThePIDinstructionissetupusingonlythephysicaladdressforthePVinputandCOoutput.</p><ul><li><p>ThePIDinstructionisgivenatagname(TIC101)whichiscreatedintheeditorofthetagbase.</p></li><li><p>ThePIDinstruction′sPVisprogrammedforaphysicaladdress<1:50>towhichtheanaloginputchannelthePVsignal(TT101)isconnected.</p></li><li><p>ThePIDinstruction′sCOisprogrammedforaphysicaladdress<0:61>towhichtheanalogoutputchanneltheFCE(TY101)isconnected.</p></li></ul><p>WhenaPIDinstructionisgivenatagname(TIC101inthisexample),amemorymapiscreatedthatcanbeaccessedfromanHMI(operatorstationortouchpanel)throughacommunicationnetwork(Ethernet/IPinthisexample).TheHMIwritestoandreadsfromthememoryofthePIDinstruction.</p><ul><li><p>BywritingtotagTIC101.SP,thePIDinstruction′sSPargumentcanbechanged.</p></li><li><p>BywritingtotagTIC101.SWN,thePIDinstruction′smode(auto/manual)canbechanged.</p></li><li><p>BywritingtotagTIC101.OUT,thePIDinstruction′sCOargumentcanbechanged.</p></li></ul><p>ThevalueofthePV,SP,andCOaredisplayedontheHMIfortheoperatortosee.Thesevaluesarereadfromtheappropriatememorylocation.Inaddition,theHMIallowspersonneltochangeotherinternaltagsassociatedwiththePIDinstruction,suchasitstuningparameters.Inthisexample,TIC101.KPistheproportionalgainparameter,TIC101.KIistheintegralgainparameter,andTIC101.KDisthederivativegainparameter.</p><h4id="10b5e207−6b1a−4b16−a26f−5936d8d8b668"data−toc−id="10b5e207−6b1a−4b16−a26f−5936d8d8b668"collapsed="false"seolevelmigrated="true">InstructionConfiguration</h4><p>AfteraPIDinstructionisinsertedintoanLD,givenatagnameanditsI/Opoint′ssetup,youuseitsconfigurationtabs(pop−upwindows)tofinishitsconfiguration.ThissetsupthePIDinstructionforitsspecificapplication.WhenyouuseanHMI,alltheseparametersarechangeablefromtheHMI.</p><p>OnceyouhaveinsertedthePIDinstructioninanLDprogramtoconfigure,youmustchangeparametersin:</p><ul><li><p>PIDConfiguration</p></li><li><p>tuning,</p></li><li><p>algorithmconfiguration,</p></li><li><p>alarms,and</p></li><li><p>scaling.</p></li></ul><h5id="f7d94cb2−37cc−4ace−b7a2−da575f8ac436"data−toc−id="f7d94cb2−37cc−4ace−b7a2−da575f8ac436"collapsed="false"seolevelmigrated="true">TuningTab</h5><p>Thetuningtaborwindowallowsyoutoentertheinitialtuningparametersfortheinstruction,suchasproportionalgain,integralgain,andderivativegain.Thevalueforthesetpointandmode(autoormanual)ofoperationistypicallyadjustablewithinthistab.</p><h5id="cee262d4−05bb−4bb5−9beb−3e423a6b1631"data−toc−id="cee262d4−05bb−4bb5−9beb−3e423a6b1631"collapsed="false"seolevelmigrated="true">AlgorithmConfiguration</h5><p>ThealgorithmconfigurationtaborwindowallowsyoutoconfigurethePIDoperation.Someoftheoptionsinclude:</p><ul><li><p>thePIDequationtype(interacting,non−interacting,orparallel),</p></li><li><p>thecontroller′saction(directorreverse),</p></li><li><p>thederivativeactionoftheerrororPV,</p></li><li><p>theSPtrackingofthePVinmanualmode,</p></li><li><p>thehighandlowlimitforthecontroller′soutput(tominimizeresetwindup)</p></li><li><p>thecascadeoperation,and</p></li><li><p>theloopupdatetime.</p></li></ul><p>Theloopupdatetimeishowoftenthisinstructionisexecuted.Youmustaccuratelysetthisfortheintegralandderivativeactiontoperformcorrectly.</p><h5id="2bee1627−8c94−424e−8da4−959198fd4d74"data−toc−id="2bee1627−8c94−424e−8da4−959198fd4d74"collapsed="false"seolevelmigrated="true">Alarms</h5><p>Thealarmtaborwindowallowsyoutoconfigurethetypicalalarmsusedwithfeedbackcontrol,suchasPVhighandlowalarmsandPVdeviationfortheSPalarms.TheHMIcanaccessthesealarmsbytheirtagname.Forexample,TIC101.PVHisthetagnameforthePVhighalarmforaPIDinstructionwiththetagnameTIC101.YoucanalsoprogramthePLCtoenergizeanoutputusingthealarmstagnameintheLDprogram.</p><h5id="8251a12b−d983−4067−b0bd−77090a1d095d"data−toc−id="8251a12b−d983−4067−b0bd−77090a1d095d"collapsed="false"seolevelmigrated="true">Scaling</h5><p>Thescalingtaborwindowscalestheprocessvariable,controlleroutput,andtiebackvariabletomatchthePIDinstruction′sinternalcalculationrequirements.Howyoudothisdependsonhowtheanaloginputmoduleandanalogoutputmoduleareconfigured.</p><p>LegacyPIDinstructionstypicallyrequirethatthePV,CO,andtiebackvariablesbescaledtoanunsigned12−bitintegervalue(0to4095).ThiswasrequiredbecausethePIDcalculationwasdesignedtooperateasa12−bitmachine.MostPIDinstructionsnowoperateusingfractionalrealnumbersand,therefore,requirescalingtoconverttoandfromthisfractionalformat.Forexample,foratemperaturecontrolloop:</p><ul><li><p>the16−bitanaloginputchannelforthePVissetupwithscalingtomatchitsengineeringrange(-50°Cto150°C),</p></li><li><p>the16−bitanalogoutputchannelfortheCOissetupwithoutscaling,and</p></li><li><p>notiebacksignalisused.</p></li></ul><p>BecausetheanaloginputchannelscalesthePVtoengineeringunits(realnumber),thePIDinstructionneedsthelowerandupperrangevaluestoconvertthePVtoafractionalnumber.ThisrequiresyoutoconfigurethePIDinstructionPVparameterasfollows.</p><ul><li><p>ThePVunscaledmaximum(max)andengineeringunitmaximumaresettothesamevalueof150°C.</p></li><li><p>ThePVunscaledminimum(min)andengineeringunitminimumaresettothesamevalueof-50°C.</p></li></ul><p>BecausetheanalogoutputchanneldoesnotscaletheCOtoengineeringunits,thePIDinstructionneedsthelowerandupperrangesignedintegervaluesthatcorrespondto4mAand20mA.Ifthe16−bitanalogoutputcardissetupfor0mAto21mA(0 mA is -32 768and21mA is +32 767),thentherequiredscalingis:</p><ul><li><p>theCOmin(0-20 285 (4 mA),and</p></li><li><p>theCOmax(100+29 646 (20 mA).</p></li></ul><p>∗PIDInstruction:LoopUpdateTimemustmatchExecutionTime.AIandAOofPIDmustbeexecutedorupdated10xfasterthanPIDinstruction.</p><h5id="21fa631a−6834−4e40−8c70−ba2969d30c09"data−toc−id="21fa631a−6834−4e40−8c70−ba2969d30c09"collapsed="false"seolevelmigrated="true">InstructioninPeriodicTask</h5><p>Periodictasksareseparateprogramsthatrunatpredefinedintervals.</p><p>Aperiodictaskhasanexecutiontimeunlikeacontinuoustask.ThePLCcontrollerexecutesacontinuoustaskduringeveryscancycle.</p><p>Forexample,ifthescancycletakes125 msandtheperiodictaskexecutiontimeis250 ms,thenthecontinuoustask(LDprogram)isexecutedevery125 ms,whiletheperiodictaskisexecutedevery250 ms.Aperiodictask(LDprogram)isexecutedonitsconfiguredtime.Thistimeintervalismoreprecisethanwhenyouuseatimerinacontinuoustaskprogram.ThePIDinstructionisexecutedonlywhentheperiodictaskisexecuted.</p><p>∗Periodictaskconfiguredtimeismoreprecisethanatimerinacontinuoustaskprogram.</p><h3id="32fc5c7f−0f43−4e79−953f−fb3fc9a4d2f0"data−toc−id="32fc5c7f−0f43−4e79−953f−fb3fc9a4d2f0"collapsed="false"seolevelmigrated="true">ObjectiveTwo:Subroutines</h3><p>Subroutinesareself−containedprogramsthatperformaspecificoperationwithablockofprogramlogic.Whenasubroutineiscalled,controlistransferredtothesubroutinefromitsmasterroutine.Attheconclusionofthesubroutine,controlrevertsbacktothemasterroutine.Subroutineshelporganizecomplexprogramsortorepeatanoperationseveraltimeswithinoneroutine.</p><p>TheinstructionsthatthePLCvendorsusetojumptoandfromsubroutinesvarieswidely.It′simportanttoinformyourselfontheoperationforyourspecificPLC.ThismoduleusesthefollowingLDblockinstructions:</p><ul><li><p>jumptosubroutine(JSR),</p></li><li><p>subroutine(SBR),and</p></li><li><p>return(RET).</p></li></ul><p>Theseinstructionsareusedtojumptoasubroutine,passdatatothesubroutine,executethesubroutine,andreturnresultstothemasterroutine.</p><p>∗Subroutinesorganizecomplexprogramsorhelptorepeatanoperationseveraltimeswithinoneroutine.</p><p>Forexample,ifrung2ofthemasterroutineistrue,thenthejumptosubroutine(JSR)instructionjumpstothesubroutinewiththatname.Theexecutionofrung3inthesubroutinereturnsprogramexecutionbacktothemasterroutine.Themasterroutineisexecuted,startingattherungaftertheJSRinstruction(rung3).Whenthesubroutineisbeingexecuted,alldatainthemasterroutineremainsthesameasitwasonleavingunlessthesubroutinechangessomeofit.WhentherungthatcontainstheJSRinstructiongoesfalse,alllocaloutputsinthesubroutineareheldintheirlaststate.</p><p>Subroutinesarenotinthemasterormainroutinebutarecreatedasaseparateroutineandgivenauniquename.</p><h4id="af697ee2−c148−42b8−a210−47eb9896d121"data−toc−id="af697ee2−c148−42b8−a210−47eb9896d121"collapsed="false"seolevelmigrated="true">JumptoSubroutineInstruction</h4><p>Ifrung2ofthemasterroutineistrue,theJSRinstructionjumpstothenamedsubroutine.Rung3inthesubroutinereturnsprogramexecutiontothemasterroutine,whichresumesattherungaftertheJSRinstruction(rung3).Datainthemasterroutineremainsunchangedunlessalteredbythesubroutine.WhentheJSRinstruction′srunggoesfalse,subroutinelocaloutputsholdtheirlaststate.</p><h4id="b901361f−785e−4693−a4cc−1a3fdf5c7824"data−toc−id="b901361f−785e−4693−a4cc−1a3fdf5c7824"collapsed="false"seolevelmigrated="true">SubroutineInstruction</h4><p>Firstrungofthesubroutinemustcontainthesubroutine(SBR)instructionthatassignsitslocaltagstothevalueofthepassedinputparameters</p><h4id="425d3d14−eb39−4c10−b616−980ddadb390d"data−toc−id="425d3d14−eb39−4c10−b616−980ddadb390d"collapsed="false"seolevelmigrated="true">ReturnInstruction</h4><p>Lastrungofthesubroutineoftenhasareturn(RET)instruction,returnsexecutionbacktothemainprogramandpassesthevalueoftagResultasitsfirstreturnparameter</p><h4id="dbc94ae3−6c0c−4c6c−aa25−23135eb8584d"data−toc−id="dbc94ae3−6c0c−4c6c−aa25−23135eb8584d"collapsed="false"seolevelmigrated="true">SubroutineInstructionsExample</h4><p>Forthisexample,assumethevalueofInput1(taginmainroutine)is25andthevalueofInput2(taginmainroutine)is15.</p><ul><li><p>TheJSRinstructioninRung1ofthemainprogramcallsthesubroutineRoutineAandpassesthevalueofitstwoinputparameters(Input1andInput2).</p></li><li><p>Thefirstrungofthesubroutine(Rung1)mustcontainthesubroutine(SBR)instructionthatassignsitslocaltags(valueAandvalueB)tothevalueofthepassedinputparameters.Therefore,valueA=25(valueofInput1)andvalueB=15(valueofInput2).</p></li><li><p>Rung2stores15inthetagResult(calculates25−15).</p></li><li><p>IfinstructionAistrue,thenrung3,whichhasareturn(RET)instruction,returnsexecutionbacktothemainprogramandpassesthevalueoftagResultasitsfirstreturnparameterRETPar.</p></li><li><p>ThereturnedparameterisassignedtothetagOutputinthemainroutineandthenthenextrungofthemainroutineisexecuted.ThevalueassignedtoOutputis15.</p></li></ul><p>IfinstructionAisfalse,thenrung3ofthesubroutineisnotexecuted.Therefore,rung4isexecuted,whichstores40inthetagResult(calculates25+15).IfinstructionBinrung5istrue,thenthesubroutinepasses40backtothemainroutine.Inthiscase,thevalueassignedtooutputis40.</p><p>IfbothinstructionAandinstructionBarefalse,thenrung6isexecuted;thispasses50backtothemainroutine.Inthiscase,thevalueassignedtooutputis50.</p><h5id="7ac89647−c460−4364−b1b6−d87d433299f8"data−toc−id="7ac89647−c460−4364−b1b6−d87d433299f8"collapsed="false"seolevelmigrated="true">Restrictions</h5><p>Therearenorestrictionsonthenumberofinputoroutputparametersthatsubroutineinstructionscanconfigure.However,youmustfollowthefollowingpointswhenusingsubroutines.</p><ul><li><p>Thedatatypefortheinputparameterspassedtoasubroutinemustmatchthedatatypeforthecorrespondingtaginthesubroutine.</p></li><li><p>Thedatatypeforthereturnparameterspassedtothemainroutinemustmatchthedatatypeforthecorrespondingtaginthemainroutine.</p></li><li><p>Theorderoftheparameters(toptobottom)intheinstructiondetermineswhichvalueisassignedtoit.</p></li></ul><h4id="ce5527e7−aec5−4245−a33b−dc86b5a4a8e5"data−toc−id="ce5527e7−aec5−4245−a33b−dc86b5a4a8e5"collapsed="false"seolevelmigrated="true">NestedSubroutines</h4><p>Nestedsubroutinesallowyoutodirectprogramflowfromthemainroutinetoasubroutineandthentoanothersubroutine(nestedsubroutine).Nestedsubroutinescanmakecomplexprogrammingeasier.</p><ul><li><p>Theprogramexecutionisdirectedtoasubroutineifrung2ofthemainprogramistrue.</p></li><li><p>Thesubroutinedirectsprogramexecutiontoanestedsubroutineifrung3ofthesubroutineistrue.</p></li><li><p>Rung3ofthenestedsubroutinedirectsprogramexecutionbacktorung4ofthesubroutine.</p></li><li><p>Rung4ofthesubroutinedirectsprogramexecutionbacktoRung3ofthemainroutine.</p></li></ul><h4id="bb5c0566−ecff−4523−ae57−a3f917af901a"data−toc−id="bb5c0566−ecff−4523−ae57−a3f917af901a"collapsed="false"seolevelmigrated="true">RepetitiveCalculationExample</h4><p>TheanaloginputsTT101andTT102arenotscaledbytheAImodule.ThescalingisdoneinasubroutinecalledConvert,ratherthaninthemainroutinebecausethisisarepetitiveblockoflogic.</p><p>TheAImodulehasa16−bitADCthatproducesasignedintegeroutputbetween−32,768and32,767froma0mAto21mAinputsignal.A4mAsignalproducesa−20,285output,whilea20mAsignalproducesa29,646output.Theengineeringrangeforthetemperaturetransmittersis-50°Cto150°C.</p><p>IftherawADCvaluefromTT101is1543,itstemperatureinengineeringunitsis37.4°C.IftherawADCvaluefromTT102is8250,itstemperatureinengineeringunitsis64.3°C$$.
The JSR instruction in rung 1 of the main program calls the subroutine Convert and passes the value in address <1:50>, which is 1543 for its first input parameter IN_Par.
The first rung of the subroutine (rung 1) must contain the SBR instruction that assigns its local tag InRaw to the value of the passed input parameter IN_Par. Therefore, InRaw has a value of 1543.
Rung 2 of the subroutine uses the I/O formula to calculate the temperature in engineering units and assigns it to the local tag OutScale. Therefore, OutScale has a value of 37.4.
Rung 3 of the subroutine has the RET instruction that returns execution back to the main program and passes the value of tag OutScale as its first return parameter RET_Par.
The returned parameter is assigned to the tag TT101 in the main routine and then the next rung of the