版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、1,ST Language,Basic Course,2,ST Language,Key word If there is any unclear or uncorrected, please feel free to speak out,Basic Course,Corso Base Linguaggio ST,3,Requirements,Hardware The programming language ST is only available for following programmable controllers:,pCO3 Supernode pCO5 pCO compact,
2、BIOS To support ST language, bios version must greater than 5.0,Software Use a version of 1tool = 2.1.x,Corso Base Linguaggio ST,4,Creation of a solution ST Language,Choosing : - FBD, the application will be mixed, it will consist of a main with Atoms, Macroblocks . but you can use routines (functio
3、ns and function blocks) written in the ST - ST, the application will be developed entirely using ST language,Corso Base Linguaggio ST,5,Basic concepts,When programming in ST, the application can be organised using three fundamental programming elements generically called Program Organization Units (
4、POU): PROGRAM FUNCTION FUNCTION BLOCK,POU,Note: we can define more functions and function blocks, but only one program main,Corso Base Linguaggio ST,6,The basic types,The following table lists all the properties of basic types (IECType):,Corso Base Linguaggio ST,7,Declaration of Global variables,The
5、re are two ways to declare Global variables: Variable List Textual mode of ST language,Note: if you want to see the variable in the pGD, please declare the variable in the Variable List,Corso Base Linguaggio ST,8,Assignment operator :=,Syntax,Assign to a variable:,a constant value the value of anoth
6、er variable the result of an expression.,Varaible_name := expression ;,Note: there is a ; in the end of statement,Corso Base Linguaggio ST,9,Textual declaration,To declare variables in ST you have to use the following declaration block:,Note: 1. there is no ; in the end of END_VAR; 2. we can give th
7、e default value in the declaration.,Corso Base Linguaggio ST,10,Rules of the identifiers (variables name),a.z, A.Z 0.9 _,The name of an identifier (variable or constant) can be any combination (see Example) of the characters listed below:,Example Rules to create identifiers.,Corso Base Linguaggio ST
8、,11,The qualifier CONSTANT,Textual declaration 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.,Corso Base Linguaggio ST,12,Comments,Comment using keyword REG
9、ION ENDREGION You can hide several lines of code using the keyword REGION ENDREGION. So increase the readability 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 si
10、ngle code line use “” To comment more code lines use “(*” and “*)”,There is no _ in between END and REGION,Corso Base Linguaggio ST,13,The qualifier RETAIN,Textual declaration of global variables REATAIN (retentive),Example,Declaration of retentive Global variables.,RETAIN keyword declares a variabl
11、e in T-permanent memory.,Organization of the variables.,Note: pay attention of the default value,Corso Base Linguaggio ST,14,Cast Functions,Syntax,Variable_name := *_TO_*(value);,The conversion functions are used to convert any of the elementary data types to any other. They must be used to make the
12、 data type uniform before a function, where this is required.,Corso Base Linguaggio ST,15,ST operators,For the evaluation of expressions, always use brackets, this avoids errors in the evaluation of the expressions.,Example,Table of the operators priority,An expression is executed only after the eva
13、luation of the operators priority. The execution order of an expression and its result are influenced by the operators priority.,Suggestion,A:= 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);,Cor
14、so Base Linguaggio ST,16,Conditional statements: IF,IF . THEN . ELSE statement Conditional construct: executes a statement block depending on whether or not certain conditions are satisfied.,Syntax,Exercize,If Expression=TRUE, statement_block is executed Otherwise the conditions in the ELSIF blocks
15、are evaluated Finally, if these are all false, the statements in the ELSE block are executed.,Boolean (AND, OR, NOT, XOR) Comparison (=, , , =, , =).,Features,IF expression THEN statement_block; ELSIF expression THEN statement_block ; ELSE statement_block ; END_IF;,Note expression contains the opera
16、tors:,Management of a range -550,950 C with NTC probe.,Corso Base Linguaggio ST,17,Conditional statements: CASE,CASE . OF . statement,Syntax,Conditional construct: selects the statements to be executed depending on the value of an integer expression.,CASE expression OF selector_1 : statement_block;
17、selector_2, selector_3 : statemnt_block; selector_4 . selector_5 : statemnt_block; selector_6, selector_7 . selector_8 : statemnt_block; ELSE statemnt_block; END_CASE;,Example,Speed management of a fan.,Corso Base Linguaggio ST,18,The Function,It can be comparable to a Black box: it works on a Input
18、 parameters configuration, and it always produces in Output the same result for the same Inputs. It lets not repeat many times the same code within the project, as instead it is for macroblocks in FBD environment. At each invocation of the function, the same code will be always executed.,What does a
19、 Function do?,It read Inputs, no outputs, but can have a return value It executes the code of the function It writes the result in a Return Value A function doesnt have a memory state It always produces the same result for the same inputs.,The function Add_3,What does a Function contain?,The list of
20、 parameters that are passed as inputs Probable Local variables, only for its internal use The code of the function,What is a Function?,Corso Base Linguaggio ST,19,FUNCTION statement,The table below lists all properties of a function.,Summary,Corso Base Linguaggio ST,20,Pass by value (VAR_INPUT),In t
21、he pass by value the Actual Parameters are copied in Formal Parameters.,Actual Parameters,Formal Parameters,Modifications dont have effect on Actual Parameters.,Corso Base Linguaggio ST,21,Pass by Reference (VAR_IN_OUT),Pass by Reference,Actual Parameters,Formal Parameters,Modification,Sometimes it
22、is necessary to modify the variable value passed to the function, and render such modification outside immediately visible. This modality is called Pass by Reference and it is realized using keyword VAR_IN_OUT. In Pass by Reference the Formal Parameter point to the same cell of memory that contains
23、the value of Actual Parameter.,Corso Base Linguaggio ST,22,Variables scope,Corso Base Linguaggio ST,23,RETURN statement,Syntax,The RETURN statement is used to exit from a Function, Function Block or the Program before the end.,FUNCTION My_function list_statements_1; RETURN; list_statements_2; END_FU
24、NCTION,1st Example,2sd Example,In the case of a Function or Function Block, the statement interrupts execution after list_statements_1, and passes control to the calling POU without executing list_statements_2. In the case of the Program, the statement closes the Program.,Corso Base Linguaggio ST,24
25、,ARRAY statement,Syntax,Exercize,Array_name: ARRAYelem_1.elem_n OF Type; where:,Simulation,elem_1 and elem_n are INT numbers or constants (they cannot be variables) and represent the limits of the array elem_n = elem_1, the difference +1 indicates the number of elements in the array Type identifies
26、the elementary data type elements inside the array or Structure type,Corso Base Linguaggio ST,25,Array Breakthrough (exceeded limits),Example,Run-Time error on Simulator,Run-Time error on pCO Place 2 integer variables on a Mask related to library functions: The position of error in the Strategy Edit
27、or ST: go in simulation and then press insert High part and Low part,When 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 will entail the re-boot of the pCO.,Note
28、 To reset error variables use this library functions:,Corso Base Linguaggio ST,26,Iteration statements: FOR,FOR . DO . Statement,FOR variable := initial_expression TO final_expression BY increase_expression DO statement_block; END_FOR;,FOR loop executes a statement block from an initial value to a f
29、inal value of the control variable.,Syntax,Example,Counter=10,Corso Base Linguaggio ST,27,Iteration statements: WHILE,WHILE . DO . Statement,WHILE statement executes a statement block while the expression is true.,Syntax,WHILE expression DO statement_block; END_WHILE;,Example,To search for an elemen
30、t within an array.,Corso Base Linguaggio ST,28,Iteration statements: REPEAT,REPEAT . UNTIL . Statement,REPEAT statement_block; UNTIL expression END_REPEAT;,The statements contained in the loop are executed at least once.,REPEAT statement executes a statement block while the expression is true. The l
31、oop is executed at least once.,Syntax,Corso Base Linguaggio ST,29,Iteration statements: EXIT,Syntax,1sh Example,EXIT statement,To exit by for loop.,EXIT;,The EXIT statement is used exclusively inside WHILE, REPEAT, and FOR statements to interrupt execution of the loop and go to the statement after t
32、he end of the loop (END_FOR, END_WHILE, END_REPEAT).,2sd Example,To exit by nested for loop.,Corso Base Linguaggio ST,30,Iteration statements,Note: Compare statement While Do and Repeat Until; Compare statement Return and Exit.,Corso Base Linguaggio ST,31,n-dimensional Array,Syntax,Exercize,Simulati
33、on,Note:,Array_name: ARRAY el_1.el_n, el_1.el_m OF Type;,The rules seen for one-dimensional arrays are valid The syntax is used to declare a matrix To access array elements, nested FOR loops can be used (see exercize),Corso Base Linguaggio ST,32,The fields of a structure can be of elementary type, o
34、f type structure, Array, n-dim Array, not Array of structures A structure must be instanced, before to be used, in such way comes reserved in memory the necessary space to its data. The space occupied by a structure is given by the sum of the space occupied by each single fields. In order to access/
35、to modify single fields of a structure the . is used (e.g.: Room_Temp.Temperature). It is possible to assign a structure to another, thus realizing the copy of the data. Remember the two instances must be of the same type (such as the Arrays).,The data type Structure,The structures are used in order
36、 to create more complex user types, of the normal elementary types. A structure is a data type that contains a predefined number of fields, usually of different types.,Corso Base Linguaggio ST,33,TYPE STRUCT statement,Allows to define the data type structure.,Definition syntax TYPE structure_type :
37、STRUCT field_1_name : data_type; field_n_name : data_type :=value; END_STRUCT; END_TYPE,Instance delaration sysntax VAR_GLOBAL my_struct1 : structure_type; my_struct2 : structure_type :=(field_1_name:=value, fiel_2_name:=value); END_VAR,Example,In simulation it is possible to visualize the instances
38、,Build two structure Cmpr_Info.,Corso Base Linguaggio ST,34,FUNCTION BLOCK,It uses the potentialities of a function and those of a structure. It can be thought as a Black Box endowed of: Input Parameters (pass by Value) or Input_Output Parameters (pass by Reference) Output Parameters Local Variables
39、 (accessible only within the FB) It is a object and has a internal memory state Note: Functions dont have memory A FB must be instanced before use, in such way the FB comes statically allocated by the controller in Ram Memory, in order to reserve the space for its data It is possible to define more
40、instances of the same FB, but the code contained in the application is unique.,What is a Function Block?,Example,Use TON timer in order to activate relay n1 after 2 second.,Use . to access to FB elements:,Use = to write on a variable the FB outputs.,Use := to assign value to the input.,Corso Base Li
41、nguaggio ST,35,FUNCTION BLOCK,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 dif
42、ferent behaviour from that expected.,Example In 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.,Corso Base Linguaggio ST,36,FUNCTION_BLOCK instance,FUNCTION_BLOCK func
43、tionblock_name (* Input, In_Out, and Output variables declaration *) (* Local variable declaration *) (* Implementation code*) END_FUNCTION_BLOCK,Definition synstax,A Function Block:,can be called more than once inside a Program, a Function or a Function Block receives one or more input values (VAR_
44、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 program cycle to the next; in the latter c
45、ase as long as the function block instance has been declared as Global (VAR_GLOBAL).,In the calling POU the instance of the function block must be declared FIRST, so as to allocate the memory required to store the values of the internal variables (e.g.: use VAR_GLOBAL; take care if using VAR). If on
46、e 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 declared as VAR_IN_OUT cannot be omitted. Recursion is not allowed.,Corso Base Linguaggio ST,37,FUNCTION_BL
47、OCK instance,Recursion,Recursion is not allowed, that is a Function Block cannot:,refer directly refer indirectly call a Function or Function Block instance that refer it.,Direct recursion,Indirect recursion,Corso Base Linguaggio ST,38,FUNCTION_BLOCK instance,Variables scope:,The qualifier RETAIN,If
48、 a Global instance has the qualifier RETAIN, data are saved in T-permanent memory.,Corso Base Linguaggio ST,39,The properties of a block are listed below.,FUNCTION_BLOCK: Summary,Corso Base Linguaggio ST,40,ST event is a function with the following restrictions: Has a unique name Has no Return value
49、 Has no Input parameters Has no Local variables Can only modify Global variables, you can not call Functions or Function Blocks Event differs from other functions, because the name is preceded by the reserved word Event_ (e.g.: Event_incA) There is no limit to the number of events that you can defin
50、e. Syntax FUNCTION Event_NameEvent /CODE END_FUNCTION From Mask Editor is possible to execute a ST event, specifing in the Key Function Editor Do_ST_Event statement. Example When the PRG button is pressed, increase a variable. 3 How? In the Startegy Editor ST define the event In the Key Function Edi
51、tor with DO_ST_Event statement call the event,ST Event,Corso Base Linguaggio ST,41,How to use the Add_3 in FBD? In the Solution Explorer add a page to Subroutine ST node Edit Add_3 function code, paying attention to types of Input parameters and Return value. In the Dependencies node of Solution Exp
52、lorer add Core_ST library. Inside FBD environment From Core_ST library select ST_Call atom to call Add_3 function inside FDB environment. Finally connect variables to pins.,FBD and ST environment,Reminders on FBD environment FBD Environment uses only the basic types (Boolean, Integer/Analog) The ST
53、language is supported by some controllers (pCO3, Suprnodo, ),Corso Base Linguaggio ST,42,FBD and ST environment,How do you change firm 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
54、 the new parameter to My_Add function, and then, you have to select “Update from firm” in FBD Strategy Editor,1st step Add In3 to My_Add function,2sd step In FBD Strategy Editor “Update from firm”,3rd step In FBD Strategy Editor connect _In3 variable,Corso Base Linguaggio ST,43,System variable,ST La
55、nguage uses specific library functions, in order to access to system variables of type: Boolean Integer Syntax Set_SystemVariableName (Vaule); Variable := Get_SystemVariableName ( ); 1st Example (Boolean) Set_KEY_PRESSED(1); Alarms:= Get_GLOBAL_ALARM( ); 2sd Example (Integer) Set_KEY_PRESSED(1); BMS
56、Addr := Get_BMS_ADDRESS( ); Library access To access library functions press CONTROL+SPACE,Corso Base Linguaggio ST,44,Base 2, Base 8 and Base 16,A number can be represented also in the bases: Binary (Base 2) Octal (Base 8) Hexadecimal (Base 16) Syntax Variable := Base#Value; Example a:=2#10110001;
57、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;,Corso Base Linguaggio ST,45,Arithmetc statements,ST language can use the following arithmetic operations:,2sd Esempio Th
58、e use of division operator.,1st Example Arithmetic operator:,Corso Base Linguaggio ST,46,Numerical statements,Vedi anche,Language ST allows to use the following numerical statements:,Corso Base Linguaggio ST,47,Debug,There are two types: Conditional Breakpoint Breakpoint During the simulation Breakp
59、oints are not active on: Functions never call Variables/Instances never use Example,For debugging the application use the breakpoint.,Debugging keys F5: goes to next breakpoint Control+F10: Step over Control+F11: Step into Control+Shift+F11: Step out,Corso Base Linguaggio ST,48,Exercises,Ex1: 在ST中進行浮點數(shù)運算。 控制邏輯: 對數(shù)學(xué)表達式進行運算: A= (IN1+1) / (IN2+1) B= -0.024263A2 + 0.8638A + 0.16655 Vw= -0.0922B2 + 1.154B 具體要求: 在Subroutine ST中編寫一個函數(shù)塊,最終在FBD中調(diào)用該函數(shù)。分別 給IN1和IN2賦兩組數(shù)據(jù),看最終Vw的值是否
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年建筑公司內(nèi)部工程承包合同范本5篇
- 2025年度農(nóng)家樂鄉(xiāng)村旅游服務(wù)合同范本3篇
- 2024租賃期滿設(shè)備回收合同
- 二零二五年租房合同涉及的環(huán)保要求3篇
- 二零二五版出租車行業(yè)駕駛員勞動合同執(zhí)行規(guī)范6篇
- 二零二五年度基礎(chǔ)設(shè)施建設(shè)項目測繪管理合同范本3篇
- 二零二五版草原承包權(quán)流轉(zhuǎn)與農(nóng)業(yè)產(chǎn)業(yè)結(jié)構(gòu)調(diào)整合同3篇
- 2024版工程建設(shè)廉政合同協(xié)議書范本
- 二零二五版互聯(lián)網(wǎng)內(nèi)容審核與管理合同范本3篇
- 2024年管理咨詢標(biāo)準化服務(wù)合同模板版B版
- 安全生產(chǎn)培訓(xùn)資料-20220703152820
- 3-U9C操作培訓(xùn)-MRP基礎(chǔ)
- 2024至2030年中國銅制裝飾材料行業(yè)投資前景及策略咨詢研究報告
- 中金公司在線測評真題
- 高中英語新課程標(biāo)準解讀課件
- 2024供應(yīng)商大會策劃方案
- 旅游活動碳排放管理評價指標(biāo)體系構(gòu)建及實證研究
- 2024小學(xué)語文六年級上冊第四單元:大單元整體教學(xué)課件
- 12S108-1 倒流防止器選用及安裝
- 人教版六年級下冊數(shù)學(xué)期末測試卷附答案【達標(biāo)題】
- 員工工作狀態(tài)分析
評論
0/150
提交評論