老外写的ST语言教程很详细课件.ppt_第1页
老外写的ST语言教程很详细课件.ppt_第2页
老外写的ST语言教程很详细课件.ppt_第3页
老外写的ST语言教程很详细课件.ppt_第4页
老外写的ST语言教程很详细课件.ppt_第5页
已阅读5页,还剩49页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1,STLanguage,BasicCourse,2,STLanguage,KeywordIfthereisanyunclearoruncorrected,pleasefeelfreetospeakout,BasicCourse,3,Requirements,HardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers:,pCO3SupernodepCO5pCOcompact,BIOSTosupportSTlanguage,biosversionmustgreaterthan5.0,SoftwareUseaversionof1tool=2.1.x,4,CreationofasolutionSTLanguage,Choosing:-FBD,theapplicationwillbemixed,itwillconsistofamainwithAtoms,Macroblocks.butyoucanuseroutines(functionsandfunctionblocks)writtenintheST-ST,theapplicationwillbedevelopedentirelyusingSTlanguage,5,Basicconcepts,WhenprogramminginST,theapplicationcanbeorganisedusingthreefundamentalprogrammingelementsgenericallycalledProgramOrganizationUnits(POU):PROGRAMFUNCTIONFUNCTIONBLOCK,POU,Note:wecandefinemorefunctionsandfunctionblocks,butonlyoneprogrammain,6,Thebasictypes,Thefollowingtablelistsallthepropertiesofbasictypes(IECType):,7,DeclarationofGlobalvariables,TherearetwowaystodeclareGlobalvariables:VariableListTextualmodeofSTlanguage,Note:ifyouwanttoseethevariableinthepGD,pleasedeclarethevariableintheVariableList,8,Assignmentoperator:=,Syntax,Assigntoavariable:,aconstantvaluethevalueofanothervariabletheresultofanexpression.,Varaible_name:=expression;,Note:thereisa;intheendofstatement,9,Textualdeclaration,TodeclarevariablesinSTyouhavetousethefollowingdeclarationblock:,Note:1.thereisno;intheendofEND_VAR;2.wecangivethedefaultvalueinthedeclaration.,10,Rulesoftheidentifiers(variablesname),a.z,A.Z0.9_,Thenameofanidentifier(variableorconstant)canbeanycombination(seeExample)ofthecharacterslistedbelow:,ExampleRulestocreateidentifiers.,11,ThequalifierCONSTANT,TextualdeclarationofConstants,ThekeywordCONSTANTcandeclareaconstant.TheconstantsdonotoccupyspaceinmemoryasthevariablesDuringcompilationinsteadoftheconstantisreplacedanumericvalue.,12,Comments,CommentusingkeywordREGIONENDREGIONYoucanhideseverallinesofcodeusingthekeywordREGIONENDREGION.Soincreasethereadabilityofthecodeonthescreen.Thecodeisreplacedwithacomment.Clickingoncommentitwillappearagainthecode.,ThecodecommentsYoucanusetwowaystomakeacommentTocommentasinglecodelineuse“”Tocommentmorecodelinesuse“(*”and“*)”,Thereisno_inbetweenENDandREGION,13,ThequalifierRETAIN,TextualdeclarationofglobalvariablesREATAIN(retentive),Example,DeclarationofretentiveGlobalvariables.,RETAINkeyworddeclaresavariableinT-permanentmemory.,Organizationofthevariables.,Note:payattentionofthedefaultvalue,14,CastFunctions,Syntax,Variable_name:=*_TO_*(value);,Theconversionfunctionsareusedtoconvertanyoftheelementarydatatypestoanyother.Theymustbeusedtomakethedatatypeuniformbeforeafunction,wherethisisrequired.,15,SToperators,Fortheevaluationofexpressions,alwaysusebrackets,thisavoidserrorsintheevaluationoftheexpressions.,Example,Tableoftheoperatorspriority,Anexpressionisexecutedonlyaftertheevaluationoftheoperatorspriority.Theexecutionorderofanexpressionanditsresultareinfluencedbytheoperatorspriority.,Suggestion,A:=NOTXANDYORNOTJ;Increasesreadability:A:=NOT(X)AND(YOR(NOTJ);,IfZ=0theothervariableshavenotbeenevaluated.A:=ZANDYAND(NOTJ);,16,Conditionalstatements:IF,IF.THEN.ELSEstatementConditionalconstruct:executesastatementblockdependingonwhetherornotcertainconditionsaresatisfied.,Syntax,Exercize,IfExpression=TRUE,statement_blockisexecutedOtherwisetheconditionsintheELSIFblocksareevaluatedFinally,iftheseareallfalse,thestatementsintheELSEblockareexecuted.,Boolean(AND,OR,NOT,XOR)Comparison(=,=,towriteonavariabletheFBoutputs.,Use:=toassignvaluetotheinput.,36,FUNCTIONBLOCK,FunctionBlockinstanceLocalvariables(VAR),areallocate/deallocateinsideStackateverycallingof:ProgramFunctionAFunctionBlockinstanceshouldbedeclaredGlobal(VAR_GLOBAL)andnotLocal(VAR).AinstanceofFBthatisdeclaredLocal(VAR)couldhaveadifferentbehaviourfromthatexpected.,ExampleInthisexampleaGlobaleandLocalinstanceofTONaredeclared.TheLocalinstancewillneversucceedtofinishthecount,becauseoftheinternalmanagementoftheLocalvariables.,37,FUNCTION_BLOCKinstance,FUNCTION_BLOCKfunctionblock_name(*Input,In_Out,andOutputvariablesdeclaration*)(*Localvariabledeclaration*)(*Implementationcode*)END_FUNCTION_BLOCK,Definitionsynstax,AFunctionBlock:,canbecalledmorethanonceinsideaProgram,aFunctionoraFunctionBlockreceivesoneormoreinputvalues(VAR_INPUTorVAR_IN_OUT)andunlikeFunctions,givesoneormoreoutputvalues(VAR_OUTPUT).thevaluesoftheLocalvariables(VAR)andtheinputandoutputparametersinFunctionBlocksaresavedinthememorybetweencallsofthefunctionblock,andfromoneprogramcycletothenext;inthelattercaseaslongasthefunctionblockinstancehasbeendeclaredasGlobal(VAR_GLOBAL).,InthecallingPOUtheinstanceofthefunctionblockmustbedeclaredFIRST,soastoallocatethememoryrequiredtostorethevaluesoftheinternalvariables(e.g.:useVAR_GLOBAL;takecareifusingVAR).Ifoneoftheinputparametersisomitted(VAR_INPUT),thefunctionblockusesthedefaultvalue(0orFALSEinthefirstprogramcycle)orthelastvalueusedinsidethefunctionblock.ParametersdeclaredasVAR_IN_OUTcannotbeomitted.Recursionisnotallowed.,38,FUNCTION_BLOCKinstance,Recursion,Recursionisnotallowed,thatisaFunctionBlockcannot:,referdirectlyreferindirectlycallaFunctionorFunctionBlockinstancethatreferit.,Directrecursion,Indirectrecursion,39,FUNCTION_BLOCKinstance,Variablesscope:,ThequalifierRETAIN,IfaGlobalinstancehasthequalifierRETAIN,dataaresavedinT-permanentmemory.,40,Thepropertiesofablockarelistedbelow.,FUNCTION_BLOCK:Summary,41,STeventisafunctionwiththefollowingrestrictions:HasauniquenameHasnoReturnvalueHasnoInputparametersHasnoLocalvariablesCanonlymodifyGlobalvariables,youcannotcallFunctionsorFunctionBlocksEventdiffersfromotherfunctions,becausethenameisprecededbythereservedwordEvent_(e.g.:Event_incA)Thereisnolimittothenumberofeventsthatyoucandefine.SyntaxFUNCTIONEvent_NameEvent/CODEEND_FUNCTIONFromMaskEditorispossibletoexecuteaSTevent,specifingintheKeyFunctionEditorDo_ST_Eventstatement.ExampleWhenthePRGbuttonispressed,increaseavariable.3How?IntheStartegyEditorSTdefinetheeventIntheKeyFunctionEditorwithDO_ST_Eventstatementcalltheevent,STEvent,42,HowtousetheAdd_3inFBD?IntheSolutionExploreraddapagetoSubroutineSTnodeEditAdd_3functioncode,payingattentiontotypesofInputparametersandReturnvalue.IntheDependenciesnodeofSolutionExploreraddCore_STlibrary.InsideFBDenvironmentFromCore_STlibraryselectST_CallatomtocallAdd_3functioninsideFDBenvironment.Finallyconnectvariablestopins.,FBDandSTenvironment,RemindersonFBDenvironmentFBDEnvironmentusesonlythebasictypes(Boolean,Integer/Analog)TheSTlanguageissupportedbysomecontrollers(pCO3,Suprnodo,),43,FBDandSTenvironment,HowdoyouchangefirmofyourFunctionorFunctionBlockinFBDStrategyEditor?InFBDStartegyEditorIhaveplacedMy_Addfunction,butihavetoaddanotherparameterYouhavetoaddthenewparametertoMy_Addfunction,andthen,youhavetoselect“Updatefromfirm”inFBDStrategyEditor,1ststepAddIn3toMy_Addfunction,2sdstepInFBDStrategyEditor“Updatefromfirm”,3rdstepInFBDStrategyEditorconnect_In3variable,44,Systemvariable,STLanguageusesspecificlibraryfunctions,inordertoaccesstosystemvariablesoftype:BooleanIntegerSyntaxSet_SystemVariableName(Vaule);Variable:=Get_SystemVariableName();1stExample(Boolean)Set_KEY_PRESSED(1);Alarms:=Get_GLOBAL_ALARM();2sdExample(Integer)Set_KEY_PRESSED(1);BMSAddr:=Get_BMS_ADDRESS();LibraryaccessToaccesslibraryfunctionspressCONTROL+SPACE,45,Base2,Base8andBase16,Anumbercanberepresentedalsointhebases:Binary(Base2)Octal(Base8)Hexadecimal(Base16)SyntaxVariable:=Base#Value;Examplea:=2#10110001;a:=8#767;a:=16#AF0;Moreover,itispossibletoseparatethefigureswithofoptional_,inordertoincreasethereadabilitya:=2#1011_0001;a:=8#7_6_7;a:=16#AF0;a:=16#A_F_0;,46,Arithmetcstatements,STlanguagecanusethefollowingarithmeticoperations:,2sdEsempioTheuseofdivisionoperator.,1stExampleArithmeticoperator:,47,Numericalstatements,Vedianche,LanguageSTallowstousethefollowingnumericalstatements:,48,Debug,Therearetwotypes:ConditionalBreakpointBreakpointDuringthesimulationBreakpointsarenotactiveon:FunctionsnevercallVariables/InstancesneveruseExample,Fordebuggingtheapplicationusethebreakpoint.,DebuggingkeysF5:goestonextbreakpointControl+F10:StepoverControl+F11:StepintoControl+Shift+F11:Stepout,49,Exercises,Ex1:在ST中进行浮点数运算。控制逻辑:对数学表达式进行运算:A=(IN1+1)/(IN2+1)B=-0.024263A2+0.8638A+0.16655Vw=-0.0922B2+1.154B具体要求:在SubroutineST中编写一个函数块,最终在FBD中调用该函数。分别给IN1和IN2赋两组数据,看最终Vw的值是否为计算的最终结果。参考:需要用到的相关语句:+,-,*,/,*,INT_TO_REAL,REAL_TO_INT.,50,Exercises,Ex2:使用ST语言写出机组开关机的功能块。控制要求:以功能块(Functionblock)的形式编写该模块在FBD中调用该功能块具体要求功能块的输入根据机组启动请求来管理机组状态,机组启动的选择方式如下:通过键盘Keyboard_OnOff通过planpLan_OnOff通过数字量输入Dig_In_OnOff,En_Dig_In_OnOff通过时间段Schedule_OnOff,En_Sched_OnOff通过上位机Superv_OnOff,En_Superv_OnOff通过报警状态Alarms功能块的输出变量Unit_OnOff表示机组的状态。仅当上述功能全部启用,即以下全部条件均为真时(Unit_OnOff=1):Keyboard_OnOff=1pLan_OnOff或En_PLan_Onoff=0Dig_In_OnOff=1或En_Dig_In_OnOff=0Schedule_OnOff=1或En_Sched_OnOff=0Superv_OnOff=1或En_Superv_OnOff=0Alarms=0功能块的输入Manual对机组状态不起作用,仅对输出Unit_Status起作用。功能块的输出Unit_Status表示机组的运行状态。Unit_Status的值状态0机组开启(Unit_OnOff=1)1Alarms=02机组因报警而关闭(Alarms=1)3机组通过plan关闭(pLan_OnOff且En_PLan_Onoff)4机组通过上位机关闭(Superv_OnOff=0且En_Superv_OnOff=1)5机组通过时间段关闭(Schedule_OnOff=0且En_Sched_OnOff=1)6机组通过数字量输入关闭(Dig_In_OnOff=0且En_Dig_In_OnOff=1)7通过本地键盘关闭机组(KeyBoard_OnOff=0)8手动操作(Manual=1)请注意,如果同时出现2个或多个上述情况,输出Unit_Status将取最大值。例如,如果机组由于报警关闭,并同时通过数字量输入关闭,则Unit_Status的值为6。功能块的输出Led_OnOff提供LED的状态,该LED表示机组状态。LED_OnOff的值状态0通过键盘关闭机组(KeyBoard_OnOff=0)1机组开启0/1在每个程序周期中,该值从0变为1,再从1变为0。机组由于报警关闭,Plan关闭或通过上位机、时间段或数字量输入关闭。,51,Exercises,Ex3:利用ST编写Pumpdown管理模块要求:要求编写的ST模块与标准库中Pumpdown模块具有相同的功能。步骤:创建一个FBD的工程,利用ST语言

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论