老外寫的ST語言教程_第1頁
老外寫的ST語言教程_第2頁
老外寫的ST語言教程_第3頁
老外寫的ST語言教程_第4頁
老外寫的ST語言教程_第5頁
已閱讀5頁,還剩49頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、ST Language Basic Course 1實用精品課件PPT ST LanguageKey wordIf there is any unclear or uncorrected, please feel free to speak out Basic Course2實用精品課件PPTRequirements HardwareThe programming language ST is only available for following programmable controllers: pCO3 Supernode pCO5 pCO compactBIOSTo support

2、ST language, bios version must greater than 5.0SoftwareUse a version of 1tool = 2.1.x pCO3pCO5Supernode3實用精品課件PPTCreation of a solution ST LanguageChoosing :- FBD, the application will be mixed, it will consist of a main with Atoms, Macroblocks . but you can use routines (functions and function bloc

3、ks) written in the ST- ST, the application will be developed entirely using ST language 4實用精品課件PPTBasic concepts When programming in ST, the application can be organised using three fundamental programming elements generically called Program Organization Units (POU): PROGRAM FUNCTION FUNCTION BLOCKP

4、OU typeKeywordDescriptionProgramPROGRAM mainEND_PROGRAMMain program that includes: read/write I/O definition of local variables calls to Functions or Function BlocksFunctionFUNCTIONEND_FUNCTIONST statements block with input variables, local variables, and if specified a return value. This can be cal

5、led at different points of the program. Recursion is not allowed.F u n c t i o n blockFUNCTION_BLOCKEND_FUNCTION_BLOCKST statements block with input variables, local variables, and output variables. This can be called at different points of the program. Recursion is not allowed. POUNote: we can defi

6、ne more functions and function blocks, but only one program main5實用精品課件PPTThe basic types KeywordData typeLower limitUpper limitMemory SpaceBOOLBooleanFALSE (0)TRUE (1)8 BitBYTEBit string02558 BitWORDBit string06553516 BitDWORDBit string04.294.967.29532 BitSINTShort Integer-1281278 BitUSINTUnsigned

7、Short Integer02558 BitINTInteger-327683276716 BitUINTUnsigned Integer06553516 BitDINTDouble Integer -231(231)-132 BitUDINTUnsigned Double Integer0232 -132 BitREALReal Number-1038103832 BitBitstringIntegersThe following table lists all the properties of basic types (IECType):6實用精品課件PPTDeclaration of

8、Global variables There are two ways to declare Global variables: Variable List Textual mode of ST languageButton UserButton ExtendIECType BOOL INT REALIECType BOOL INT REALVariable ListTextual modeCarelType Boolean Integer/AnalogGlobal variables declarationUsable in any environmentUsable only in the

9、 Strategy Editor ST (no: MASK, FBD Strategy Editor)You dont see these variables in Variable ListNote: if you want to see the variable in the pGD, please declare the variable in the Variable List7實用精品課件PPTAssignment operator :=SyntaxAssign to a variable:In assignment operations “:=” the variables inv

10、olved must all be the same type, each statement must use “;” as the statement terminator. In assignment operations with BOOL values, 1 or TRUE, or 0 or FALSE can be used indifferently. a constant value the value of another variable the result of an expression.Varaible_name := expression ;Assignment

11、operatorStatement terminatorNote: there is a ; in the end of statement8實用精品課件PPTTextual declaration To declare variables in ST you have to use the following declaration block:Global variables declared in text mode will not be visible in the Variable List.TypeSyntaxDescritionGloabalVAR_GLOBALEND_VARD

12、eclares a group of global variables, shared by program, functions or function blocks.LocalVAREND_VARDeclares a group of local variables to a program, function or function block.Note: 1. there is no ; in the end of END_VAR; 2. we can give the default value in the declaration.9實用精品課件PPTRules of the id

13、entifiers (variables name) a.z, A.Z 0.9 _ Valid identifiersInvalid identifiersNoteMn22MnThe 1st character must not be numeric._3exit_3exit.1“.” is not included in the set of characters.Enrg_offEnrg offSpaces are not allowed. _Drill_DrillOnly single underscores “_” are allowed.Valve, VALVENot case-se

14、nsitive. The variable names are not case-sensitive Valve, VaLVe e VALVE are the same variable. The name of an identifier (variable or constant) can be any combination (see Example) of the characters listed below:ExampleRules to create identifiers.10實用精品課件PPTThe qualifier CONSTANT Textual declaration

15、 of Constants The keyword CONSTANT can declare a constant. The constants do not occupy space in memory as the variables During compilation instead of the constant is replaced a numeric value.TypeSyntaxDescriptionCostantiLocaliVAR CONSTANTEND_VARDeclares a group of local constants to a program, funct

16、ion or function block.CostantiGlobaliVAR_GLOBAL CONSTANTEND_VARDeclares a group of global constants, shared by program, functions or function blocks.11實用精品課件PPTCommentsComment using keyword REGION ENDREGION You can hide several lines of code using the keyword REGION ENDREGION. So increase the readab

17、ility of the code on the screen. The code is replaced with a comment. Clicking on comment it will appear again the code. The code comments You can use two ways to make a comment-To comment a single code line use “”-To comment more code lines use “(*” and “*)”There is no _ in between END and REGION12

18、實用精品課件PPTThe qualifier RETAINTextual declaration of global variables REATAIN (retentive)ExampleDeclaration of retentive Global variables.RETAIN keyword declares a variable in T-permanent memory.TypeSyntaxDescriptionG l o b a l RetentiveVAR_GLOBAL RETAINEND_VARDeclares a group of retain global variab

19、les, shared by program, functions or function blocks.It is not possible to initialize a retain variable to a default value at the time of declaration.The initialisation of a variable in T-memory must be performed using the Variable Wizard, which implies creation of the .DEV file.Organization of the

20、variables. Note: pay attention of the default value13實用精品課件PPTCast FunctionsSyntaxParameterDescriptionVariable_nameVariable that holds the result of the conversion.*_TO_*Conversion function.* indicates the data type of the variable being to convert.* indicates the converted data type (e.g.: INT_TO_R

21、EAL)valueValue or variable to be converted.SymboloDescription*_TO_BOOLconversion from type* to type BOOL*_TO_BYTEconversion from type * to type BYTE*_TO_WORDconversion from type * to type WORD*_TO_DWORDconversion from type * to type DWORD*_TO_SINTconversion from type * to type SINT*_TO_USINTconversi

22、on from type * to type USINT*_TO_INTconversion from type * to type INT*_TO_UINTconversion from type * to type UINT*_TO_DINTconversion from type * to type DINT*_TO_UDINTconversion from type * to type UDINT*_TO_REALconversion from type * to type REALVariable_name := *_TO_*(value); The conversion funct

23、ions are used to convert any of the elementary data types to any other. They must be used to make the data type uniform before a function, where this is required.14實用精品課件PPTST operatorsFor the evaluation of expressions, always use brackets, this avoids errors in the evaluation of the expressions.Exa

24、mpleTable of the operators priorityPrioritOperatoreDescrizione1(.)Expression in brackets.2nome_POU (.);Call a function or function block.3*Raise to the power.4-NOTNegationBoolean complement5*/MODMultiplication Division Module6+-AdditionSubtraction7, , =Comparison operators 8=EqualityInequality 9ANDB

25、oolean AND10XORBoolean XOR11ORBoolean ORIn the case of Boolean AND, OR boolean (not bitwise), if the result of the operation can already be determined after having evaluated the first operand, the second is not evaluated (Short-Circuit Boolean Expressions). An expression is executed only after the e

26、valuation of the operators priority. The execution order of an expression and its result are influenced by the operators priority. SuggestionA:= NOT X AND Y OR NOT J;Increases readability: A:= NOT(X) AND (Y OR (NOT J);If Z=0 the other variables have not been evaluated. A := Z AND Y AND (NOT J);15實用精

27、品課件PPTConditional statements: IFIF . THEN . ELSE statement Conditional construct: executes a statement block depending on whether or not certain conditions are satisfied.SyntaxExercizeShort-Circuit Boolean Expressions If Expression=TRUE, statement_block is executed Otherwise the conditions in the EL

28、SIF blocks are evaluated Finally, if these are all false, the statements in the ELSE block are executed. Boolean (AND, OR, NOT, XOR) Comparison (=, , , =, , = elem_1, the difference +1 indicates the number of elements in the arrayType identifies the elementary data type elements inside the array or

29、Structure type24實用精品課件PPTArray Breakthrough (exceeded limits)This type of error is not detectable at compile time by the compiler. The error can be detected only at run-time.ExampleRun-Time error on SimulatorRun-Time error on pCO Place 2 integer variables on a Mask related to library functions: The

30、position of error in the Strategy Editor ST: go in simulation and then press insert High part and Low partWhen a variable is used to access the elements of an array, care must be paid to ensure the size of the array is not exceeded. If run-time the index value exceeds the size of the array, this wil

31、l entail the re-boot of the pCO. Exceeds the size of the array.NoteTo reset error variables use this library functions:25實用精品課件PPTIteration statements: FORFOR . DO . StatementFOR variable := initial_expression TO final_expression BY increase_expression DO statement_block;END_FOR;FOR loop executes a

32、statement block from an initial value to a final value of the control variable.SyntaxParameterTypeDescriptionVariableSINT, INT, DINTControl variable that is increased/decreased by increase_expression.initial_expressionSINT, INT, DINTExpression that initialises the control variable.final_expressionSI

33、NT, INT, DINTFinal value of the control variable.increase_expressionSINT, INT, DINTExpression processed each cycle that increases (if result 0) or decreases (if result to write on a variable the FB outputs.INPTQETLocal VarMemoryMy_Timer_1Use := to assign value to the input.34實用精品課件PPTFUNCTION BLOCK

34、Function Block instance Local variables (VAR), are allocate/deallocate inside Stack at every calling of: Program Function A Function Block instance should be declared Global (VAR_GLOBAL) and not Local (VAR). A instance of FB that is declared Local (VAR) could have a different behaviour from that exp

35、ected.It doesnt count correctlyExampleIn this example a Globale and Local instance of TON are declared. The Local instance will never succeed to finish the count, because of the internal management of the Local variables.Local instance allocated in the StackGlobal instance allocated in Ram35實用精品課件PP

36、TFUNCTION_BLOCK instanceFUNCTION_BLOCK functionblock_name (* Input, In_Out, and Output variables declaration *) (* Local variable declaration *) (* Implementation code*)END_FUNCTION_BLOCKDefinition synstaxA Function Block:- can be called more than once inside a Program, a Function or a Function Bloc

37、k- receives one or more input values (VAR_INPUT or VAR_IN_OUT) and unlike Functions, gives one or more output values (VAR_OUTPUT).- the values of the Local variables (VAR) and the input and output parameters in Function Blocks are saved in the memory between calls of the function block, and from one

38、 program cycle to the next; in the latter case as long as the function block instance has been declared as Global (VAR_GLOBAL).11201525 OffsetMy_FB1In1In2Out_1Out_2Visible only inside FB.In the calling POU the instance of the function block must be declared FIRST, so as to allocate the memory requir

39、ed to store the values of the internal variables (e.g.: use VAR_GLOBAL; take care if using VAR).If one of the input parameters is omitted (VAR_INPUT), the function block uses the default value (0 or FALSE in the first program cycle) or the last value used inside the function block. Parameters declar

40、ed as VAR_IN_OUT cannot be omitted.Recursion is not allowed.36實用精品課件PPTFUNCTION_BLOCK instanceRecursionRecursion is not allowed, that is a Function Block cannot: refer directly refer indirectly call a Function or Function Block instance that refer it.Direct recursionIndirect recursion37實用精品課件PPTFUNC

41、TION_BLOCK instanceType of variableAccess by calling POUAccess inside the functionNoteMemoryVARNoRWVisible only to the function where it was declared. YesVAR_INPUTRWRAn input variable is visible to the calling POU and is written by it. Inside the function where it is defined, its value is not modifi

42、ed.YesVAR_OUTPUTRWAn output variable is visible to the calling POU and can only be read by this. It can be read and written inside the Function BlockYesVAR_IN_OUTRWRWAn input/output variable combines the characteristics of the VAR_INPUT and VAR_OUTPUT variables: both visible and can be read and modi

43、fied inside or outside of the function where it is defined.YesVAR_GLOBALRWRWGlobal variables are accessible from all POUs. YesIt is possible (but not recommended) to declare a Local variable in a program with the same identifier as a Global variable. Inside the program the processor will consider th

44、e Local variable (whose value is initialised between one program cycle and the next) and not the Global variable.Variables scope:The qualifier RETAINIf a Global instance has the qualifier RETAIN, data are saved in T-permanent memory.Care must be paid when RETAIN qualifier is used, in fact at each ca

45、ll of the Function Block a possible change of data will produce a writing in the Flash memory.38實用精品課件PPT Function BlockDeclarationThe declaration must be made in two way:using “Subroutine ST” nodebefore the PROGRAM statementFUNCTION_BLOCK FB_name.END_FUNCTION_BLOCKInstanceFunction blocks must be in

46、stanced before being used in a POU. A function block can be instanced before the PROGRAM statement, if it is a global instance, or within any POU, if it is a local instance.CallA function block can be called one or more times in a program, function or in another function block. Recursion is not allo

47、wed.MemoryFor each instance of a function block declared as Local variable is allocated space in Stack. The data are stored for just one program cycle (e.g.: within the PROGRAM or within a FUNCTION).For each instance of a function block declared as Global variable is allocated space in RAM. The data

48、 are stored for all program cycles. If the Global variable has the RETAIN qualifier, the data are also stored after the controller is switched off.UseControl functions that remain over time (e.g.: PID, counters).Input parametersThe parameters are sent to the function block with their identifier. Thi

49、s allows some VAR_INPUT and VAR_OUTPUT parameters to be omitted. The position of the parameters in the call does not need to correspond to the position of the parameters in the declaration. VAR_IN_OUT parameters cannot be omitted. The parameters are used as elements in a structure (function_block_in

50、stance.parameter_name).OutputparametersFunction blocks can return one or more output values. The output parameters may be elementary data types, arrays or structures.The properties of a block are listed below. FUNCTION_BLOCK: Summary39實用精品課件PPTST event is a function with the following restrictions:H

51、as a unique nameHas no Return valueHas no Input parametersHas no Local variablesCan only modify Global variables, you can not call Functions or Function BlocksEvent differs from other functions, because the name is preceded by the reserved word Event_ (e.g.: Event_incA)There is no limit to the numbe

52、r of events that you can define. Syntax FUNCTION Event_NameEvent /CODE END_FUNCTIONFrom Mask Editor is possible to execute a ST event, specifing in the Key Function Editor Do_ST_Event statement.ExampleWhen the PRG button is pressed, increase a variable. 3How?In the Startegy Editor ST define the even

53、t1.In the Key Function Editor with DO_ST_Event statement call the eventST EventEvent name.40實用精品課件PPTHow to use the Add_3 in FBD?1.In the Solution Explorer add a page to Subroutine ST node2.Edit Add_3 function code, paying attention to types of Input parameters and Return value. 3.In the Dependencie

54、s node of Solution Explorer add Core_ST library.Inside FBD environment1.From Core_ST library select ST_Call atom to call Add_3 function inside FDB environment.2.Finally connect variables to pins.FBD and ST environmentReminders on FBD environment FBD Environment uses only the basic types (Boolean, In

55、teger/Analog) The ST language is supported by some controllers (pCO3, Suprnodo, )The inputs / outputs of functions / function blocks must be compatible with Boolean, Integer/Analog types. To ensure compatibility you must use the types BOOL and INT.41實用精品課件PPTFBD and ST environmentHow do you change f

56、irm of your Function or Function Block in FBD Strategy Editor? In FBD Startegy Editor I have placed My_Add function, but i have to add an other parameter You have to add the new parameter to My_Add function, and then, you have to select “Update from firm” in FBD Strategy Editor1st stepAdd In3 to My_

57、Add function2sd stepIn FBD Strategy Editor “Update from firm”3rd stepIn FBD Strategy Editor connect _In3 variable42實用精品課件PPTSystem variableST Language uses specific library functions, in order to access to system variables of type: Boolean IntegerSyntaxSet_SystemVariableName (Vaule); Variable := Get

58、_SystemVariableName ( ); 1st Example (Boolean) Set_KEY_PRESSED(1); Alarms:= Get_GLOBAL_ALARM( );2sd Example (Integer) Set_KEY_PRESSED(1); BMSAddr := Get_BMS_ADDRESS( );Library access To access library functions press CONTROL+SPACE43實用精品課件PPTBase 2, Base 8 and Base 16A number can be represented also

59、in the bases: Binary (Base 2) Octal (Base 8) Hexadecimal (Base 16)SyntaxVariable := Base#Value;Examplea:=2#10110001;a:=8#767;a:=16#AF0;Moreover, it is possible to separate the figures with of optional _ , in order to increase the readability a:=2#1011_0001;a:=8#7_6_7;a:=16#AF0; a:=16#A_F_0;BaseKeywo

60、rdDescriptionBinary2#A number according to 2 or Binary Base is expressed.Octal8#A number according to 8 or Octal Base is expressed.Hexadecimal16#A n u m ber acco r d i n g t o 1 6 o r Hexadecimal Base is expressed.44實用精品課件PPTArithmetc statementsST language can use the following arithmetic operations

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論