老外写的ST语言教程-很详细.ppt

上传人:xt****7 文档编号:6011482 上传时间:2020-02-14 格式:PPT 页数:53 大小:2.77MB
返回 下载 相关 举报
老外写的ST语言教程-很详细.ppt_第1页
第1页 / 共53页
老外写的ST语言教程-很详细.ppt_第2页
第2页 / 共53页
老外写的ST语言教程-很详细.ppt_第3页
第3页 / 共53页
点击查看更多>>
资源描述
1 STLanguage BasicCourse 2 STLanguage KeywordIfthereisanyunclearoruncorrected pleasefeelfreetospeakout BasicCourse 3 Requirements HardwareTheprogramminglanguageSTisonlyavailableforfollowingprogrammablecontrollers pCO3SupernodepCO5pCOcompact BIOSTosupportSTlanguage biosversionmustgreaterthan5 0 SoftwareUseaversionof1tool 2 1 x 4 CreationofasolutionSTLanguage Choosing FBD theapplicationwillbe mixed itwillconsistofamainwithAtoms Macroblocks butyoucanuseroutines functionsandfunctionblocks writtenintheST ST theapplicationwillbedevelopedentirelyusing STlanguage 5 Basicconcepts WhenprogramminginST theapplicationcanbeorganisedusingthreefundamentalprogrammingelementsgenericallycalled ProgramOrganizationUnits POU PROGRAMFUNCTIONFUNCTIONBLOCK POU Note wecandefinemorefunctionsandfunctionblocks butonlyoneprogrammain 6 Thebasictypes Thefollowingtablelistsallthepropertiesofbasictypes IECType 7 DeclarationofGlobalvariables TherearetwowaystodeclareGlobalvariables VariableList Textualmode ofSTlanguage Note ifyouwanttoseethevariableinthepGD pleasedeclarethevariableintheVariableList 8 Assignmentoperator Syntax Assigntoavariable aconstantvaluethevalueofanothervariabletheresultofanexpression Varaible name expression Note thereisa intheendofstatement 9 Textualdeclaration TodeclarevariablesinSTyouhavetousethefollowing declarationblock Note 1 thereisno intheendofEND VAR 2 wecangivethedefaultvalueinthedeclaration 10 Rulesoftheidentifiers variablesname a z A Z 0 9 Thenameofanidentifier variableorconstant canbeanycombination seeExample ofthecharacterslistedbelow ExampleRulestocreateidentifiers 11 ThequalifierCONSTANT TextualdeclarationofConstants ThekeywordCONSTANTcandeclareaconstant TheconstantsdonotoccupyspaceinmemoryasthevariablesDuringcompilationinsteadoftheconstantisreplacedanumericvalue 12 Comments Commentusingkeyword REGION ENDREGION Youcanhideseverallinesofcodeusingthekeyword REGION ENDREGION 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 Features IFexpressionTHENstatement block ELSIFexpressionTHENstatement block ELSEstatement block END IF Noteexpressioncontainstheoperators Managementofarange 550 950 CwithNTCprobe 17 Conditionalstatements CASE CASE OF statement Syntax Conditionalconstruct selectsthestatementstobeexecuteddependingonthevalueofanintegerexpression CASEexpressionOFselector 1 statement block selector 2 selector 3 statemnt block selector 4 selector 5 statemnt block selector 6 selector 7 selector 8 statemnt block ELSEstatemnt block END CASE Example Speedmanagementofafan 18 TheFunction Itcanbecomparabletoa Blackbox itworksonaInputparametersconfiguration anditalwaysproducesinOutputthesameresultforthesameInputs Itletsnotrepeatmanytimesthesamecodewithintheproject asinsteaditisformacroblocksinFBDenvironment Ateachinvocationofthefunction thesamecodewillbealwaysexecuted WhatdoesaFunctiondo ItreadInputs nooutputs butcanhaveareturnvalueItexecutesthecodeofthefunctionItwritestheresultinaReturnValueAfunctiondoesn thaveamemorystateItalwaysproducesthesameresultforthesameinputs ThefunctionAdd 3 WhatdoesaFunctioncontain ThelistofparametersthatarepassedasinputsProbableLocalvariables onlyforitsinternaluseThecodeofthefunction WhatisaFunction 19 FUNCTIONstatement Thetablebelowlistsallpropertiesofafunction Summary 20 Passbyvalue VAR INPUT InthepassbyvaluetheActualParametersarecopiedinFormalParameters ActualParameters FormalParameters Modificationsdon thaveeffectonActualParameters 21 PassbyReference VAR IN OUT PassbyReference ActualParameters FormalParameters Modification Sometimesitisnecessarytomodifythevariablevaluepassedtothefunction andrendersuchmodificationoutsideimmediatelyvisible Thismodalityiscalled PassbyReference anditisrealizedusingkeywordVAR IN OUT InPassbyReferencetheFormalParameterpointtothesamecellofmemorythatcontainsthevalueofActualParameter 22 Variablesscope 23 RETURNstatement Syntax TheRETURNstatementisusedtoexitfromaFunction FunctionBlockortheProgrambeforetheend FUNCTIONMy functionlist statements 1 RETURN list statements 2 END FUNCTION 1stExample 2sdExample InthecaseofaFunctionorFunctionBlock thestatementinterruptsexecutionafterlist statements 1 andpassescontroltothecallingPOUwithoutexecutinglist statements 2 InthecaseoftheProgram thestatementclosestheProgram 24 ARRAYstatement Syntax Exercize Array name ARRAY elem 1 elem n OFType where Simulation elem 1andelem nareINTnumbersorconstants theycannotbevariables andrepresentthelimitsofthearrayelem n elem 1 thedifference 1indicatesthenumberofelementsinthearrayTypeidentifiestheelementarydatatypeelementsinsidethearrayorStructuretype 25 ArrayBreakthrough exceededlimits Example Run TimeerroronSimulator Run TimeerroronpCOPlace2integervariablesona Mask relatedtolibraryfunctions ThepositionoferrorintheStrategyEditorST goinsimulationandthenpressinsertHighpartandLowpart Whenavariableisusedtoaccesstheelementsofanarray caremustbepaidtoensurethesizeofthearrayisnotexceeded Ifrun timetheindexvalueexceedsthesizeofthearray thiswillentailthere bootofthepCO NoteToreset errorvariables usethislibraryfunctions 26 Iterationstatements FOR FOR DO Statement FORvariable initial expressionTOfinal expression BYincrease expression DOstatement block END FOR FORloopexecutesastatementblockfromaninitialvaluetoafinalvalueofthecontrolvariable Syntax Example Counter 10 27 Iterationstatements WHILE WHILE DO Statement WHILEstatementexecutesastatementblockwhiletheexpressionistrue Syntax WHILEexpressionDOstatement block END WHILE Example Tosearchforanelementwithinanarray 28 Iterationstatements REPEAT REPEAT UNTIL Statement REPEATstatement block UNTILexpressionEND REPEAT Thestatementscontainedintheloopareexecutedatleastonce REPEATstatementexecutesastatementblockwhiletheexpressionistrue Theloopisexecutedatleastonce Syntax 29 Iterationstatements EXIT Syntax 1shExample EXITstatement Toexitbyforloop EXIT TheEXITstatementisusedexclusivelyinsideWHILE REPEAT andFORstatementstointerruptexecutionoftheloopandgotothestatementaftertheendoftheloop END FOR END WHILE END REPEAT 2sdExample Toexitbynestedforloop 30 Iterationstatements Note ComparestatementWhile DoandRepeat Until ComparestatementReturnandExit 31 n dimensionalArray Syntax Exercize Simulation Note Array name ARRAY el 1 el n el 1 el m OFType Therulesseenforone dimensionalarraysarevalidThesyntaxisusedtodeclareamatrixToaccessarrayelements nestedFORloopscanbeused seeexercize 32 Thefieldsofastructurecanbeofelementarytype oftypestructure Array n dimArray notArrayofstructuresAstructuremustbeinstanced beforetobeused insuchwaycomesreservedinmemorythenecessaryspacetoitsdata Thespaceoccupiedbyastructureisgivenbythesumofthespaceoccupiedbyeachsinglefields Inordertoaccess tomodifysinglefieldsofastructurethe isused e g Room Temp Temperature Itispossibletoassignastructuretoanother thusrealizingthecopyofthedata Rememberthetwoinstancesmustbeofthesametype suchastheArrays Thedatatype Structure Thestructuresareusedinordertocreatemorecomplexusertypes ofthenormalelementarytypes Astructureisadatatypethatcontainsapredefinednumberoffields usuallyofdifferenttypes 33 TYPE STRUCTstatement Allowstodefinethedatatype structure DefinitionsyntaxTYPEstructure type STRUCTfield 1 name data type field n name data type value END STRUCT END TYPE InstancedelarationsysntaxVAR GLOBALmy struct1 structure type my struct2 structure type field 1 name value fiel 2 name value END VAR Example Insimulationitispossibletovisualizetheinstances Buildtwostructure Cmpr Info 34 FUNCTIONBLOCK Itusesthepotentialitiesofafunctionandthoseofastructure Itcanbethoughtasa BlackBox endowedof InputParameters passbyValue orInput OutputParameters passbyReference OutputParametersLocalVariables accessibleonlywithintheFB ItisaobjectandhasainternalmemorystateNote Functionsdon thavememoryAFBmustbeinstancedbeforeuse insuchwaytheFBcomesstaticallyallocatedbythecontrollerinRamMemory inordertoreservethespaceforitsdataItispossibletodefinemoreinstancesofthesameFB butthecodecontainedintheapplicationisunique WhatisaFunctionBlock Example UseTONtimerinordertoactivaterelayn 1after2second Use toaccesstoFBelements Use towriteonavariabletheFBoutputs Use toassignvaluetotheinput 35 FUNCTIONBLOCK FunctionBlockinstanceLocalvariables VAR areallocate deallocateinsideStackateverycallingof ProgramFunctionAFunctionBlockinstanceshouldbedeclaredGlobal VAR GLOBAL andnotLocal VAR AinstanceofFBthatisdeclaredLocal VAR couldhaveadifferentbehaviourfromthatexpected ExampleInthisexampleaGlobaleandLocalinstanceofTONaredeclared TheLocalinstancewillneversucceedtofinishthecount becauseoftheinternalmanagementoftheLocalvariables 36 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 37 FUNCTION BLOCKinstance Recursion Recursionisnotallowed thatisaFunctionBlockcannot referdirectlyreferindirectlycallaFunctionorFunctionBlockinstancethatreferit Directrecursion Indirectrecursion 38 FUNCTION BLOCKinstance Variablesscope ThequalifierRETAIN IfaGlobalinstancehasthequalifierRETAIN dataaresavedinT permanentmemory 39 Thepropertiesofablockarelistedbelow FUNCTION BLOCK Summary 40 STeventisafunctionwiththefollowingrestrictions HasauniquenameHasnoReturnvalueHasnoInputparametersHasnoLocalvariablesCanonlymodifyGlobalvariables youcannotcallFunctionsorFunctionBlocksEventdiffersfromotherfunctions becausethenameisprecededbythereservedwordEvent e g Event incA Thereisnolimittothenumberofeventsthatyoucandefine SyntaxFUNCTIONEvent NameEvent CODEEND FUNCTIONFromMaskEditorispossibletoexecuteaSTevent specifingintheKeyFunctionEditor Do ST Event statement ExampleWhenthePRGbuttonispressed increaseavariable 3How IntheStartegyEditorSTdefinetheeventIntheKeyFunctionEditorwith DO ST Event statementcalltheevent STEvent 41 Howtousethe Add 3 inFBD Inthe SolutionExplorer addapageto SubroutineST nodeEdit Add 3 functioncode payingattentiontotypesofInputparametersandReturnvalue Inthe Dependencies nodeof SolutionExplorer add Core ST library InsideFBDenvironmentFrom Core ST libraryselect ST Call atomtocall Add 3 functioninsideFDBenvironment Finallyconnectvariablestopins FBDandSTenvironment RemindersonFBDenvironmentFBDEnvironmentusesonlythebasictypes Boolean Integer Analog TheSTlanguageissupportedbysomecontrollers pCO3 Suprnodo 42 FBDandSTenvironment HowdoyouchangefirmofyourFunctionorFunctionBlockinFBDStrategyEditor InFBDStartegyEditorIhaveplacedMy Addfunction butihavetoaddanotherparameterYouhavetoaddthenewparametertoMy Addfunction andthen youhavetoselect Updatefromfirm inFBDStrategyEditor 1ststepAddIn3toMy Addfunction 2sdstepInFBDStrategyEditor Updatefromfirm 3rdstepInFBDStrategyEditorconnect In3variable 43 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 LibraryaccessToaccesslibraryfunctionspress CONTROL SPACE 44 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 45 Arithmetcstatements STlanguagecanusethefollowingarithmeticoperations 2sdEsempioTheuseofdivisionoperator 1stExampleArithmeticoperator 46 Numericalstatements Vedianche LanguageSTallowstousethefollowingnumericalstatements 47 Debug Therearetwotypes ConditionalBreakpointBreakpointDuringthesimulationBreakpointsarenotactiveon FunctionsnevercallVariables InstancesneveruseExample Fordebuggingtheapplicationusethebreakpoint DebuggingkeysF5 goestonextbreakpointControl F10 StepoverControl F11 StepintoControl Shift F11 Stepout 48 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 49 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关闭或通过上位机 时间段或数字量输入关闭 50 Exercises Ex3 利用ST编写Pumpdown管理模块要求 要求编写的ST模块与标准库中Pumpdown模块具有相同的功能 步骤 创建一个FBD的工程 利用ST语言编写functionblock编写具有F Edge功能的functionblock编写具有Delay功能的functionblock完成Pumpdown功能的逻辑控制将利用ST编写的Pumpdown模块和标准库中的Pumpdowm模块同时拖放到Strategy中 连接变量测试相关ST语句 可能用到的functionblock有F Trig SR TONNote 使用的F Edge和Delay需要自己编写functionblock来实现 51 Exercises Ex4 Asimplecontrol要求 利用ST语言完成简单控制 包括读取温度值 风扇控制 压缩机控制 报警管理 输出变量值 界面显示等 步骤 创建一个ST的工程 利用ST语言编写function编写具有自动回到主界面功能的function编写具有读取模拟量 数字量功能的function编写具有风扇控制功能的function编写具有压缩机控制功能控制的function编写具有报警管理功能的function编写具有变量值输出功能的function完成用户界面的显示功能 52 Exercises 具体控制 当程序中没有进行任何操作 60s后自动回到主界面 模拟量B1读取室内温度的值 数字量Din1为系统开关 0表示开 1表示关 Din2和Din3分别为压缩机的高压报警输入和低压报警输入 模拟量输出Y1为压缩机根据室内温度输出电压值 在室内温度范围34度 压缩机设点减去偏差 偏差1度可设 和36度 压缩机设点加偏差 偏差1度可设 输出0 2v 可设 到2 2v 可设 模拟量输出Y2为当压缩机开启时有一个值输出10v 可设 当压缩机关闭时有一个值输出3 5v 可设 冷凝风机管理利用室内温度使用如下控制曲线 控制曲线温度设点60度 可设 Diff Off为3度 可设 Diff On为0 同时只要压缩机启用 则冷凝风机也开启 蒸发风机管理利用室内温度使用如上控制曲线 温度设点为 15度 可设 Diff Off为3度 可设 Diff On为0压缩机管理利用室内温度使用如上控制曲线曲线 温度设点为35度 可设 Diff Off为2度 Diff On为0 报警管理 具有高低温 和高低压报警管理 当温度大于60度 可设 高温报警 小于55度 设点减偏差 偏差5度可设 可消除报警 当温度低于 15度 可设 低温报警 大于10度 利用和高温报警相同的偏差 可消除报警 高低压报警由数字量输入 53
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!