1、Lesson 1 - Using Functions and Function Blocks11.2.1 DescriptionThis lesson describes how to use Functions and Function Blocks in the different languages.11.2.2 ObjectivesOn completion of this lesson you will be able to: Use Functions and Function Blocks in the different languages.11.2.3 The differe
2、nce between Functions and Function Blocks11.2.3.1 Function Have a value. Can be used in expressions. Do not retain their old values and do always give the same value when the input parameters have the same value.11.2.3.2 Function block Have both input and output parameters. Can give several output v
3、alues using parameters. Retain their values, from the last call, when called the second time. Can give different output values even if the input values are the same. Have to be made into an instance.11.2.4 Inserting librariesRight click on the Libraries icon and select Insert Library to insert a lib
4、rary to your project.11.2.5 Some standard functions and function blocksThe library SystemLib contains a number of predefined Functions and Function Blocks.11.2.5.1 Data type conversionThe are a number of predefined data converters in the library SystemLib. For example bool_to_dint, and real_to _dint
5、.11.2.5.2 Mathematical functionsThe are a number of predefined mathematical functions in the library SystemLib. For example sin, cos, add, ln, sqrt.11.2.5.3 Counters and timersThe are a number of predefined counters and timers in the library SystemLib. For example CTU (Counter Up), CTD (Counter Down
6、), TOn (Timer on delay), Tof (Timer off delay).11.2.6 Using Functions in different languages11.2.6.1 ST and SFCA function call in ST is done by writing the name of the function in the editor or by using the button, pressing or selecting (Insert Function). An example with the function Add in ST:11.2.
7、6.2 FBDUse the toolbar button , or select (InsertFunction/Function block.) or press to display the dialog box containing the available functions and function blocks. If the function or function block is extensible, i.e. can be called with a varying number of inputs, you can enter the number in the P
8、roperties Size field. An example with the function Add in FBD:11.2.6.3 ILA function call in IL is done by writing the name of the function in the instruction field or using the button, press or select (Insert Function).An example with the function Add in IL:11.2.6.4 LDUse one of the toolbar buttons
9、Left, Right, Parallel Function/Function block.) to display the dialog box containing the available functions and function blocks. If the function or function block is extensible, i.e. can be called with a varying number of inputs, you can enter the number in the Properties Size field.An example with
10、 the function Add in LD:11.2.7 Instantiating / Using FB Instances in different languages11.2.7.1 ST and SFCYou must create an instance of the function block before it is used in the ST or SFC editor. The instance is created like this: Click on the Function blocks tab of the Program, Control Module T
11、ype or Function block type. Write the name of the function block you intend to use in the Function Block Type field or press . Give the function block a suitable name in the Name field. Write a description in the Description field. Call for the function block by writing like this in the code block w
12、ere you intend to use it: TimerCloseDoor( A new window like the one below will be visible. Write suitable variables in the Actual Parameter field.11.2.7.2 FBDSam as using functions in FBD. It is not necessary to declare a function or function block before using it in the FBD editor.11.2.7.3 ILYou mu
13、st create an instance of the function block before it is used in the IL editor. The instance is created like this:Ctrl J Call for the function block by writing like this in the code block.11.2.7.4 LDIt is not necessary to declare a function or function block before using it in the FBD editor. Use th
14、e toolbar buttonsLeft, Right, Parallel Function/Function block.), to display the dialog box containing the available functions and function blocks. The Insert Function / Function Block command displays a dialog box showing functions and function blocks available for insertion. The dialog box is the
15、same as the one in the FBD editor (above). Declare suitable variables with correct data types to the parameters of the function block. Connect the pins of the function block with the variables.11.3 Exercise 11.1 Using Function BlocksPlease do exercise 11.111.4 Lesson 2 - Creating Function Blocks11.4
16、.1 DescriptionThis lesson describes how to declare user defined Function Blocks in libraries.11.4.2 Objectives11.4.3 Creating a user libraryRight click on the Libraries icon and select New Library to insert a library to your project.11.4.3.1 Why using libraries?It is recommended to create own librar
17、ies when you work in a larger project, because then you get a better structure of the project. Another major advantages of creating own libraries are that it is possible to reuse the Data types, Function Block types and Control Module types in other projects.11.4.4 Creating a Function block typeRigh
18、t click on the Function Block Types icon and select New Function Block Type to create a new Function Block Type. This could be done in an application or a library.11.4.4.1 Why creating Function Block Types?It is recommended to create own Function block types, because then you make it possible to reu
19、se the code later.11.4.4.2 Function Block Type EditorThe content of the function block type is displayed in an editor. You can define function block types, which can be used in other POU:s. Parameters, variables and function blocks that are used must be declared in the declaration pane. Code is ente
20、red in the code pane. A function block type typically uses the following elements, which are declared in separate tabs in the declaration pane: Parameters Variables that passes values in or out from the program. The options are: in, out and in_out. It is not allowed to set an initial value on a para
21、meter Local Variables used in the function block. External variables Globally defined variables in the application editor must be specified as external variables to be accessed by the function block. Function blocks. You must explicitly declare function blocks to use them (not necessary in the FBD a
22、nd LD editors).11.4.5 Move FB between librariesIt is possible to move functions or function blocks between libraries or applications, by using the copy and paste function.11.5 Exercise 11.2 Creating Function BlocksPlease do exercise 11.2Du kan tag bort denna osynliga text men ltnedanstende Page Brea
23、k ligga kvar !Lt ven den efterfljande sidan ligga kvar !This page is intentionally left blankOsynlig text:Nsta sida mste brja p UDDA sidnummerLmna EN eller TV tomma sidor hr OVANFR.Nedanstende Section Break fr INTE tas bort !Komplettera tom sida vid behov med nedanstende textTABLE OF CONTENTSChapter
24、 11 Function and Function Blocks 111.1 General Information 111.1.1 Description 111.1.2 Objectives 111.1.3 Reference Documentation 111.2 Lesson 1 - Using Functions and Function Blocks 211.2.1 Description 211.2.2 Objectives 211.2.3 The difference between Functions and Function Blocks 211.2.3.1 Functio
25、n 211.2.3.2 Function block 211.2.4 Inserting libraries 211.2.5 Some standard functions and function blocks 311.2.5.1 Data type conversion 311.2.5.2 Mathematical functions 311.2.5.3 Counters and timers 311.2.6 Using Functions in different languages 311.2.6.1 ST and SFC 311.2.6.2 FBD 311.2.6.3 IL 411.
26、2.6.4 LD 411.2.7 Instantiating / Using FB Instances in different languages 411.2.7.1 ST and SFC 411.2.7.2 FBD 511.2.7.3 IL 511.2.7.4 LD 611.3 Exercise 11.1 Using Function Blocks 611.4 Lesson 2 - Creating Function Blocks 711.4.1 Description 711.4.2 Objectives 711.4.3 Creating a user library 7 711.4.4 Creating a Function block type 711.4.4.2 Function Block Type Editor 811.4.5 Move FB
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2