Академический Документы
Профессиональный Документы
Культура Документы
In addition to elementary and complex data types, you can also define parameter types for formal
parameters that are transferred between blocks. STEP 7 recognizes the following parameter types:
x TIMER or COUNTER: this specifies a particular timer or particular counter that will be used
when the block is executed. If you supply a value to a formal parameter of the TIMER or
COUNTER parameter type, the corresponding actual parameter must be a timer or a counter,
in other words, you enter "T" or "C" followed by a positive integer.
x BLOCK: specifies a particular block to be used as an input or output. The declaration of the
parameter determines the block type to be used (FB, FC, DB etc.). If you supply values to a
formal parameter of the BLOCK parameter type, specify a block address as the actual
parameter. Example: "FC101" (when using absolute addressing) or "Valve" (with symbolic
addressing).
x POINTER: references the address of a variable. A pointer contains an address instead of a
value. When you supply a value to a formal parameter of the parameter type POINTER, you
specify an address as the actual parameter. In STEP 7, you can specify a pointer in the pointer
format or simply as an address (for example, M 50.0). Example of a pointer format for
addressing the data beginning at M 50.0: P#M50.0
x ANY: this is used when the data type of the actual parameter is unknown or when any data
type can be used. For more information about the ANY parameter type, refer to the sections
"Format of the Parameter Type ANY" and "Using the Parameter Type ANY".
A parameter type can also be used in a user-defined data type (UDT). For more information about
UDTs, refer to the section "Using User-Defined Data Types to Access Data".
The permitted number of blocks, timers, and counters is dependent on the type of your S7 CPU.
You will find more information on the permitted number of timers and counters and on the
maximum number of available blocks in the data sheets for your CPU in the "S7-300
Programmable Controller, Hardware and Installation Manual" or in the "S7-400 Programmable
Controller, Hardware and Installation Manual."
The offset 0.0 has no influence. Output 10.0 is calculated from 8.7 (AR1) plus the offset 1.1. The
result is 10.0 and not 9.8, see pointer format.
L P# I8.7 Load the value of the pointer and the area identification in
accumulator 1.
LAR1 Load memory area I and the address 8.7 into AR1.
L P# Q8.7 Load the value of the pointer and the area identification in
accumulator 1.
LAR2 Load memory area Q and the address 8.7 into AR2.
A [AR1, P#0.0] Query the signal state at input bit I 8.7 and
= [AR2, P#1.1] assign the signal state to output bit Q 10.0.
The offset 0.0 has no influence. Output 10.0 is calculated from 8.7 (AR2) plus the offset 1.1. The
result is 10.0 and not 9.8, see pointer format.
VAR_INPUT
Bit_Byte : BOOL ; //0: Bit address, 1: byte address
Inc_Value : INT ; //Increment (if value neg. => decrement/if value
pos. => increment)
END_VAR
VAR_IN_OUT
Pointer : DWORD ; //Pointer to be changed
END_VAR
VAR_TEMP
Inc_Value1 : INT ; //Interim value increment
Pointer1 : DWORD ; //Interim value pointer
Int_Value : DWORD ; //Auxiliary variable
END_VAR
BEGIN
NETWORK
TITLE =
//The block intercepts changes that change the area information of the
pointer
//or that lead to "negative" pointers automatically.
SET ; //Set RLO to 1 and
R #RET_VAL; //reset overflow
L #Pointer; //Supply value to temporary
T #Pointer1; //interim value pointer
L #Inc_Value; //Supply value of temporary
T #Inc_Value1; //interim value increment
A #Bit_Byte; //If =1, byte address instruction
JC Byte; //Jump to byte address calculation
L 7; //If value of increment > 7,
L #Inc_Value1;
<I ;
S #RET_VAL; //then set RET_VAL and
JC End; //jump to End
L -7; //If value of increment < -7,
<I ;
S #RET_VAL; //then set RET_VAL and
JC End; //jump to End
A L 1.3; //If bit 4 of the value = 1 (Inc_Value negative)
JC neg; //then jump to bit address subtraction
L #Pointer1; //Load pointer address information
L #Inc_Value1; //and add the increment
+D ;
JU test; //Jump to test for negative result
neg: L #Pointer1; //Load pointer address information
L #Inc_Value1; //Load the increment
NEGI ; //Negate the negative value,
-D ; //subtract the value
JU test; //and jump to test
Byte: L 0; //Start of byte address change
L #Inc_Value1; //If increment >=0, then
<I ;
JC pos; //jump to addition, otherwise
L #Pointer1; //Load pointer address information,
L #Inc_Value1; //load the increment,
NEGI ; //negate the negative value,
SLD 3; //shift the increment 3 digits to the left,
-D ; //subtract the value,
JU test; //and jump to test
pos: SLD 3; //Shift the increment 3 digits to the left
L #Pointer1; //Load pointer address information
+D ; //Add increment
test: T #Int_Value; //Transfer results of calculation to Int_Value
A L 7.3; //If invalid byte address (too large or
S #RET_VAL; //negative), then set RET_VAL
JC End; //and jump to End,
L #Int_Value; //otherwise transfer result
T #Pointer; //to pointer
End: NOP 0;
END_FUNCTION
The repetition factor identifies a quantity of the indicated data type to be transferred by the
parameter type ANY. This means you can specify a data area and also use arrays and structures
in conjunction with the parameter type ANY. STEP 7 identifies arrays and structures as a number
(with the help of the repetition factor) of data types. If, for example, 10 words are to be transferred,
the value 10 must be entered for the repetition factor and the value 04 must be entered for the data
type.
The address is stored in the format Byte.Bit where the byte address is stored in bits 0 to 2 of
byte 7, in bits 0 to 7 of byte 8, and in bits 3 to 7 of byte 9. The bit address is stored in bits 0 to 2 of
byte 9.
With a null pointer of the type NIL all bytes from byte 1 are assigned 0.
The following tables show the coding of the data types or of the memory areas for the parameter
type ANY.
The following table shows the coding of the data types for the parameter type ANY for parameter
types.
In this example, FC100 has three parameters (in_par1, in_par2, and in_par3) declared as the ANY
data type.
x When FB10 calls FC100, FB10 transfers an integer (the static variable speed), a word
(MW100), and a double word to DB10 (DB10.DBD40).
x When FB11 calls FC100, FB11 transfers an array of real numbers (the temporary variable
"Thermo"), a Boolean value (M 1.3), and a timer (T2).
STL Explanation
FUNCTION FC10: VOID
VAR_TEMP
Source : ANY;
Target : ANY;
END_VAR
BEGIN
LAR1 P#Source; Load the start address of the ANY pointer in AR1.
LAR1 P#Target; Load the start address of the ANY pointer in AR1.
STEP 7 restricts the assignment of formal parameters of an FC as actual parameters for the formal
parameters of a different FC. You cannot, for example, assign parameters with complex data types
or a parameter type as the actual parameter.
The following table shows the permitted data types (z) when one FC calls another FC.
Input ! Input z -- -- -- -- -- --
Input ! Output -- -- -- -- -- -- --
Input ! In/out -- -- -- -- -- -- --
Output ! Input -- -- -- -- -- -- --
Output ! Output z -- -- -- -- -- --
Output ! In/out -- -- -- -- -- -- --
In/out ! Input z -- -- -- -- -- --
In/out ! Output z -- -- -- -- -- --
In/out ! In/out z -- -- -- -- -- --
STEP 7 restricts the assignment of the formal parameters of an FB to the formal parameters of an
FC. You cannot, for example, assign parameters of the parameter type as actual parameters. The
following table shows the permitted data types (z) when an FB calls an FC.
STEP 7 restricts the assignment of formal parameters of an FC to the formal parameters an FB.
You cannot, for example, assign parameters with a complex data type as actual parameters. You
can, however, assign input parameters of the parameter types TIMER, COUNTER, or BLOCK to
the input parameters of the called FB.
The following table shows the permitted data types (z) when an FC calls an FB.
Valid Data Types for the Call of a Function Block by a Function Block
You can assign the formal parameters of a calling FB to the formal parameters of a called FB. The
following figure illustrates the formal parameters of FB10 that are assigned as actual parameters to
the formal parameters of FB12.
STEP 7 restricts the assignment of the formal parameters of an FB to the formal parameters of
another FB. You cannot, for example, assign input and output parameters with complex data types
as the actual parameters for the input and output parameters of a called FB. You can, however,
assign input parameters of the parameter types TIMER, COUNTER, or BLOCK to the input
parameters of the called FB.
The following table shows the permitted data types (z) when an FB calls another FB.