DFB function blocks. Schneider Electric PL7 Micro/Junior/Pro
Reklāma
Reklāma
DFB function blocks
10
Presentation
Subject of this chapter
What's in this
Chapter?
This chapter describes how to program DFB user function blocks.
This chapter contains the following topics:
Topic
Presenting DFB function blocks
How to set up a DFB function block
Defining DFB type function block objects
Definition of DFB parameters
Definition of DFB Variables
Coding rules for DFB types
Creating DFB Instances
Rules for using DFBs in a program
Using a DFB in a ladder language program
Using a DFB in a program in instruction list or text language
Running a DFB instance
Example of how to program DFB function blocks
Page
35015365.01 07/2008
217
DFB function blocks
Presenting DFB function blocks
Role Pro PL7 software offers the user the possibility of creating his own function blocks corresponding to the specific needs of his applications.
These user function blocks are designed for structuring an application. They will be used when a programming sequence is repeated several times within an application, or to freeze standard programming (e.g.: command algorithm for a motor including taking local safeguards into account).
They can be transmitted to all the programmers and used in the same application or in any other application (export/import function).
Examples of use Using a DFV function block in an application allows you to: z z z z simplify the program design and entries, increase the readability of the program, enable debugging (all the variables changed by the DFB type are identified on its interface), reduce the amount of code generated (the code corresponding to the DFB is only changed once, however many calls there are on the DFB in the program).
Comparison with the sub-program.
In relation to the sub-program they enable: z z z the parameters of the process to be set more easily, the internal variables belonging to the DFB and therefore independent of the application to be used, testing independent of the application.
They offer a graphic display of the block in ladder language, making programming and debugging easier.
Also, DFB function blocks use residual data.
Areas of use The table below describes the DFB areas of application.
Function
PL7s the DFBs can be used with.
DFB creation software
Area
Premium
PL7 Pro
Software the DFBs can be used with.
Pro PL7 or Junior PL7
Programming language used to create DFB code. structured text language and ladder
Programming languages the DFBs can be used with.
ladder, structured text and instruction list
218
35015365.01 07/2008
DFB function blocks
How to set up a DFB function block
Procedure Setting up a DFB function block is done in 3 main steps:
Step
1
2
3
Action
Designing the DFB model (called: DFB Type).
Creating an image of this block called instance for using each time in the application.
Using the instance in the PL7 program.
Designing the
DFB type
Consists of defining and coding all the elements that make up the DFB model, using the DFB editor.
The following illustration shows how a DFB model is made up.
DFB type name
Inputs Outputs
Inputs/
Outputs
Public variables
Private variables
Code
A DFB type function block is made up: z z z z z z of a name, parameters: z inputs, z z outputs, inputs/outputs, variables: z public variables, z private variables, code in structured text language or ladder, comments, a descriptive form.
35015365.01 07/2008
219
DFB function blocks
Creating a DFB instance
Using the DFBs
Once the DFB type is designed the user defines a DFB instance using a variables editor or when calling up the function in the program editor.
This block instance is used next as a standard function block in ladder language or as an elementary function in structured text language or instruction list language.
It can be programmed in the various tasks (except in event tasks) and sections of the application.
220
35015365.01 07/2008
DFB function blocks
Defining DFB type function block objects
General characteristics of DFB objects
These objects are internal DFB data. They can be purely symbolic (no addressing under address form).
DFBs use 2 types of object: z z parameters variables
Syntax For each parameter or variable used, the designer of the DFB type function block defines: z z z z a name with a maximum of 8 characters (non-accented letters, figures, the character "_", are allowed. The first character must be a letter; key words and symbols are not allowed), an object type (see table below), an optional comment with up to 80 characters, an initial value (except for Input/Output parameters).
35015365.01 07/2008
221
DFB function blocks
Types of objects The table below describes the list of different object types possible when declaring the parameters and variables for the DFB type.
Type Name Examples Action on…
Bits
Words
Tables
BOOL
EBOOL
Boolean
Extended
Boolean
The BOOL type does not manage the edges. If edge management is not necessary in the process it is preferable to use the BOOL type.
Example of a BOOL type object in PL7 language:
%MWi:Xj which does not manage the edges but which takes up less memory than the EBOOL type.
The EBOOL type manages the edges. Therefore it is possible to run RE and FE edge instructions on this type of parameter or variable.
if you wish to associate an EBOOL type with an input/output parameter when it is being used, it must be an EBOOL type in the DFB.
Example of a EBOOL type object in PL7 language:
%Mi,%Ixy.i,%Qxy.i.
WORD
DWORD
REAL
AR_X
AR_W
AR_D
All 16 bits
All 32 bits
Real
Bit table
Example of a WORD type object in PL7 language:
%MWi, %KWi,
Example of a DWORD type object in PL7 language: %MDi, %KDi,
Example of a REAL type object in PL7 language:
%MFi, %KFi
Example of an AR_X type object in PL7 language:
%Mi:L, %Ix.i:L
Table of all 16 bits
Example of an AR_W type object in PL7 language:
%MWi:L, %KWi:L
Table of all 32 bits
Example of an AR_D type object in PL7 language:
%MDi:L, %KDi:L
AR_R Table of reals Example of an AR_R type object in PL7 language:
%MFi:L, %KFi:L
STRING Character string
Example of a STRING type object in PL7 language:
%MBi, %KBi
222
35015365.01 07/2008
DFB function blocks
Note: z tables: the length of a table must be mentioned for outputs and public and private variables, on the other hand it is not necessary to define them for input parameters and input/output parameters.
z the initial values can be defined for inputs (if they are not table type), for outputs and for public and private variables.
35015365.01 07/2008
223
DFB function blocks
Definition of DFB parameters
Illustration The following illustration shows examples of parameters
Inputs Check
DWORD
Gap
WORD
Speed
BOOL
Enable
WORD
Actions
WORD
Accel
BOOL
Error
Outputs
Inputs/
Outputs
Description of parameters
The table below describes the role of each type of parameter.
Parameter Maximum number
Inputs 15 (1)
Role
This is data to be supplied to the DFB by the application program.
These read only parameters cannot be modified in the DFB code.
Outputs 15 (2)
Inputs/ outputs
15
This is data calculated by the DFB to be sent to the application program.
These are input parameters which can be modified in the DFB code.
Key:
(1) Number of inputs + Number of inputs/outputs less than or equal to 15
(2) Number of outputs + Number of inputs/outputs less than or equal to 15 z z
Note: all the DFB block must have at least one Boolean input.
it is only possible to modify a DFB interface (public variables or parameters) if it is not instanced and used in the application.
224
35015365.01 07/2008
DFB function blocks
Definition of DFB Variables
Description of
Variables
The table below describes the role of each type of variable.
Variable Maximum number
Public 100
Role
Internal variables used in the process which can be accessed by the user for adjustment or by the application program outside the
DFB code (for a DFB instance public variable, see below:
Accessing public variables).
Private 100 Internal variables in function block code. These variables are calculated and used right inside the DFB but do not have any link with the outside of the DFB.
These variables are useful for programming the block but are of no interest for the user of the block (e.g.: intermediate variable for sending back one combination expression to another, result of an intermediate calculation, etc.).
Note: it is only possible to modify a DFB interface (public variables or parameters) if it is not instanced and used in the application.
Accessing
Public Variables.
Only output parameters and public variables can be accessed as objects in the application program and outside the function block body.
Their syntax is as follows:
Name_DFB.Name_parameter
Or Name_DFB is the name given to the DFB instance used (32 characters maximum) and Name_parameter is the name given to the output parameter or the public variable (8 characters maximum).
Example: Gap.check
for the gap output of the DFB instance named Check .
35015365.01 07/2008
225
DFB function blocks
Saving and
Restoring Public
Variables
Public variables, modified by the program or by adjustment, can be saved in the location and sets initialization values (defined in the DFB instances) by setting system bit %S94 to 1.
Replacement only takes place if authorization for it has been given at the level of each variable by validating the S field in the DFB public variables definition screen.
These saved values are re-applied by setting system bit %S95 to 1 or by reinitializing the PLC.
It is possible to disable the " Save/Restore " function globally for all DFB function blocks (dialogue box Properties of DFB types ).
226
35015365.01 07/2008
DFB function blocks
Coding rules for DFB types
General points
Programming rules
The code defines the processing the DFB block must carry out depending on the parameters declared.
The DFB function block code is programmed in text or ladder language.
As far as text language is concerned, the DFB is made up of a single text sequence of unlimited length.
All language instructions and advanced functions are permitted except for: z z z z z z calling up standard function blocks, calling up other DFB function blocks, connecting to a JUMP label, calling up a sub-program, the HALT instruction, instructions using input/output module variables (e.g.: READ_STS , SMOVE ...).
The code uses DFB parameters and variables defined by the user.
The DFB block function code cannot use either input/output objects (%I,%Q...), or global application objects (%MW,%KW...) except for the system bits and words %S and %SW.
Note: it is not possible to use a label
Specific functions
The table below describes functions that have been specifically adapted to be used in the code.
Functions Role
FTON, FTOF, FTP, FPULSOR These timing functions are meant to be used instead of standard timing function blocks.
LW, HW, COCATW These instructions are used to manipulate words and double words.
LENGTH_ARW, LENGTH_ARD,
LENGTH_ARR
These instructions are used to calculate the length of tables.
35015365.01 07/2008
227
DFB function blocks
Example of the code
The following program gives an example of text code
CHR_200:=CHR_100;
CHR_114:=CHR_104;
CHR_116:=CHR_106;
RESET START;
(*CHR_100 is incremented 80 times*)
FOR CHR_102:=1 TO 80 DO
INC CHR_100;
WHILE((CHR_104-CHR_114)<100)DO
IF(CHR_104>400) THEN
EXIT;
END_IF;
INC CHR_104;
REPEAT
IF(CHR_106>300) THEN
EXIT;
END_IF;
INC CHR_106;
UNTIL ((CHR_100-CHR_116)>100)
END_REPEAT;
END_WHILE;
(*Loop continues as far as CHR_106)
IF (CHR_106=CHR_116)
THEN EXIT;
ELSE
CHR_114:=CHR_104;
CHR_116:=CHR_106;
END_IF;
END_FOR;
INC CHR_200;
228
35015365.01 07/2008
DFB function blocks
Creating DFB Instances
General
Rules
A DFB instance is a copy of the DFB type: z z it uses the DFB type code (there is no duplication of the code), it creates a field for specific data for this instance which is a copy of the parameters and variables of the DFB type. This field is in the given space in the application.
Each DFB instance is located by a name of no more than 32 characters defined by the user.
The characters allowed are identical to those allowed for symbols, i.e. the following are allowed: z z z non-accented letters, figures, the character "_".
The first character must be a letter; key words and symbols are not allowed.
It is possible to create as many instances as you wish, using the same DFB type.
However, the number of DFB instances must not use more than 32 K words of the
PLC's internal memory.
The initial values of the public variables defined for DFB type function blocks can be modified for each instance.
35015365.01 07/2008
229
DFB function blocks
Rules for using DFBs in a program
General points DFB instances can be used in all languages (ladder, text and instruction list) and in all parts of the application: sections, sub-programs, Grafcet modules (except in event tasks).
General rules for use
The following rules must be observed whatever language used: z z z all the table type input parameters as well as input/output parameters must be entered.
input parameters which have not been hardwired keep the value of the previous call or the initialization value if the block has never been called before this input has been made or hardwired.
all the objects assigned to input, output and input/output parameters must be of the same type as those defined when the DFB type was set up (e.g.: if the WORD type is defined for the "speed" input parameter, the double words %MDi, %KDi are not allowed to be allocated to it).
The only exceptions are the BOOL and EBOOL types for input or output parameters (not for input/output parameters) which can be mixed.
Example : the "Validation" input parameter can be defined as BOOL and can be associated with an internal bit %Mi which is an EBOOL type. On the other hand, in the internal code of the DFB type, the input parameter will have BOOL type properties. It cannot manage edges.
230
35015365.01 07/2008
Allocating the parameters
DFB function blocks
The following table summarizes the different parameter allocation possibilities in the various programming languages:
Parameter
Inputs
Inputs/
Outputs
Outputs
Type
Boolean
Numeric
Table
Boolean
Numeric
Table
Boolean
Numeric
Table
Parameter allocation
Hardwired (1)
Object or expression
Object
Object
Object
Object
Hardwired (1)
Object
Object
Allocation optional (2) optional compulsory compulsory compulsory compulsory optional optional optional
(1) hardwired in ladder, or object in Boolean or text language
(2) in ladder, any DFB block must have at least one hardwired Boolean (binary) input.
35015365.01 07/2008
231
DFB function blocks
Using a DFB in a ladder language program
Principle
Example
There are two ways of calling up a DFB function block: z z a text call in an operation block, the syntax and the constraints on the parameters are the same as those in text language.
a graphic call, see the example below.
Graphic DFB function blocks have inputs/outputs which are assigned directly by objects or expressions. These objects or expressions take up one cell in the graphic network.
2 DFB function blocks connected in series must be separated by at least 2 columns.
The following illustration shows a simple example of how to program a DFB.
%Q2.5
ABS(%MD0)
10000
%MW100
Control_port_1
Check
DWORD
Gap
WORD
Accel
WORD
Speed
BOOL
Error
BOOL
Enable
WORD
Actions
%MW8
%MW100
%Q2.1
232
35015365.01 07/2008
35015365.01 07/2008
DFB function blocks
The table below locates the different elements of the DFB.
2
3
4
5
6
Address Role
1 Name of the DFB
Name of the DFB type
Effective parameter for the first input
Input parameters (name and type)
Output parameters (name and type)
Input/output parameters (name and type) z z
Note: a DFB function block must have at least one hardwired Boolean input.
the numerical inputs, outputs or inputs/outputs of the block are not hardwired.
The objects mentioned in the cell opposite the contact are associated with these contacts.
233
DFB function blocks
Using a DFB in a program in instruction list or text language
General points
General syntax
Calling up the DFB function block constitutes an action which can be put in a sequence just like any other action in the language.
The DFB programming syntax is as follows:
DFB_Name
(E1,...,En,ES1,...,ESn,S1,...,Sn);
The following table describes the role of the instruction parameters.
Parameters
E1, ..., En
ES1, ..., ESn
S1, ..., Sn
Role
Expressions (except for BOOL/EBOOL type objects), objects or immediate values using effective parameters for input parameters.
Effective parameters corresponding to inputs/outputs. They are always read/write language objects.
Effective parameters corresponding to outputs. They are always read/write language objects.
Text syntax
Instruction list syntax
Instructions in text language have the following syntax:
Name_DFB (E1,...,En,ES1,...,ESn,S1,...,Sn);
Example: Cpt_bolts(%I2.0,%MD10,%I2.1,%Q1.0);
Instructions in instruction list language have the following syntax:
[Name_DFB (E1,...,En,ES1,...,ESn,S1,...,Sn)]
Example:
LD TRUE
[Cpt_bolts(%I2.0,%MD10,%I2.1,%Q1.0)]
234
35015365.01 07/2008
DFB function blocks
Running a DFB instance
Operation Running a DFB instance is done in the following order:
Step
1
2
3
4
5
Action
Loading the input and input/output parameters using the actual parameters.
Any input left free takes on the initialization value defined in the DFB type when being initialized or starting from cold, then the current value of the parameter.
Going through input parameter values (except for table type).
Going through input/output parameter addresses.
Running the text code.
Writing the output parameters.
Debugging tools PL7 software offers several debugging tools for the PL7 program and the DFBs: z z z animation table: all parameters and public variables are displayed and animated in real time. It is possible to modify and force required objects, break point, step by step and diagnostic program, operating screens: for unit debugging.
35015365.01 07/2008
235
DFB function blocks
Example of how to program DFB function blocks
General points
DFB type characteristics
This example is given in a technical capacity. The DFB to be programmed is a counter.
The counter is made up from the following DFB type:
Counter_parts
EBOOL
Reset to zero
DWORD
Presel
EBOOL
Count
DWORD
V_current
BOOL
Done
The table below describes the characteristics of the DFB type to be programmed.
Characteristics
Name
Inputs
Outputs
Public variable
Values
Counter_parts z z z
Reset to zero
Presel
Count
: resetting the counter to zero
: value of counter preselection
: input count
Done : output value of the preselection
V_cour : Current variable incremented by the input Count
236
35015365.01 07/2008
Counter operation
DFB code
DFB function blocks
The following table describes the functions that the counter must have.
Phase
1
2
3
Description
This block counts the rising edges on the input Count .
The result is put in the variable V_curr , this value is reset to zero by a rising front on the input Reset to zero .
Counting is done up to the preselected value. When this value is reached the output Done is set to 1, it is reset to 0 on the rising edge on the input Reset to zero .
Programming a DFB type code is given below.
!(*Programming DFB counter_parts*)
IF RE Reset to zero THEN
V_curr:=0;
END_IF;
IF RE Count THEN
V_curr:=V_curr+1;
END_IF;
IF(V_curr>=Presel) THEN
SET Done;
ELSE
RESET Done;
END_IF;
Example of use In this example, the DFB type created is used 3 times (3 DFB instances) for counting
3 types of parts.
When the number of parts programmed (in words %MD10, %MD12, and %MD14) is reached, the counter output stops the supply system of the corresponding parts.
35015365.01 07/2008
237
DFB function blocks
The following program uses 3 instances of DFB type Counter_parts: Counter_bolts,
Counter_nuts, Counter_screws.
Counter_bolts
%I1.0
%Q2.1
Counter_parts
EBOOL
Reset to zero
BOOL
Done
%MD10
%I1.1
DWORD
Presel
EBOOL
Count
%I1.2
%I1.3
%MD12
Counter_nuts
Counter_parts
EBOOL
Reset to zero
BOOL
Done
DWORD
Presel
EBOOL
Count
%Q2.2
%I1.4
%I1.5
%MD14
Counter_screws
Counter_parts
EBOOL
Reset to zero
BOOL
Done
DWORD
Presel
EBOOL
Count
%Q2.3
238
35015365.01 07/2008
Lejupielādēt
Reklāma