Description
The "Calculate" instruction is used to define and execute an expression for the calculation of mathematical operations or complex logic operations depending on the selected data type.
You can select the data type of the instruction from the "???" drop-down list of the instruction box. Depending on the selected data type, you can combine the functionality of specific instructions to execute a complex calculation. The expression to be calculated is specified via a dialog you can open via the "Calculator" icon at the top of the instruction box. The expression can contain the names of the input parameters and the syntax of the instructions. It is not permitted to specify operand names or operand addresses.
In its initial state, the instruction box contains at least 2 inputs (IN1 and IN2). The number of inputs can be extended. The inserted inputs are numbered in ascending order in the box.
The values of the inputs are use to execute the specified expression. Not all defined inputs have to be used in the expression. The result of the instruction is transferred to the box output OUT.
|
Note If one of the mathematical operations fails in the expression, then no result is transferred to the OUT output and the ENO enable output has the signal state "1". |
If, in the expression, you use inputs that are not available in the box, these inputs are automatically inserted. Provided that there are no gaps in the numbering of the inputs that are to be newly defined in the expression. You cannot, for example, use the input IN4 in the expression if the input IN3 is not defined.
Enable output ENO has the signal state "0" if one of the following conditions applies:
-
Enable input EN has the signal state "0".
-
The result or an interim result of the "Calculate" instruction is outside the range permitted for the data type specified at output OUT.
-
A floating-point number has an invalid value.
-
An error occurred during the execution of one of the instructions specified in the expression.
The following table shows the instructions that, depending on the selected data type, can be combined and executed in the expression of the "Calculate" instruction:
|
Data type |
Instruction |
Syntax |
Example |
|---|---|---|---|
|
Bit strings |
AND: AND logic operation |
AND |
IN1 AND IN2 OR IN3 |
|
OR: OR logic operation |
OR |
||
|
XOR: EXCLUSIVE OR logic operation |
XOR |
||
|
INV: Create ones complement |
NOT |
||
|
SWAP: Swap 1) |
SWAP |
||
|
Integers |
ADD: Add |
+ |
(IN1 + IN2) * IN3; (ABS(IN2)) * (ABS(IN1)) |
|
SUB: Subtract |
- |
||
|
MUL: Multiply |
* |
||
|
DIV: Divide |
/ |
||
|
MOD: Return remainder of division |
MOD |
||
|
INV: Create ones complement |
NOT |
||
|
NEG: Create twos complement |
-(in1) |
||
|
ABS: Form absolute value |
ABS( ) |
||
|
Floating-point numbers |
ADD: Add |
+ |
((SIN(IN2) * SIN(IN2) + (SIN(IN3) * SIN(IN3)) / IN3)); (SQR(SIN(IN2)) + (SQR(COS(IN3)) / IN2)) |
|
SUB: Subtract |
- |
||
|
MUL: Multiply |
* |
||
|
DIV: Divide |
/ |
||
|
EXPT: Exponentiate |
** |
||
|
ABS: Form absolute value |
ABS( ) |
||
|
SQR: Form square |
SQR( ) |
||
|
SQRT: Form square root |
SQRT( ) |
||
|
LN: Form natural logarithm |
LN( ) |
||
|
EXP: Form exponential value |
EXP( ) |
||
|
FRAC: Return fraction |
FRAC( ) |
||
|
SIN: Form sine value |
SIN( ) |
||
|
COS: Form cosine value |
COS( ) |
||
|
TAN: Form tangent value |
TAN( ) |
||
|
ASIN: Form arcsine value |
ASIN( ) |
||
|
ACOS: Form arccosine value |
ACOS( ) |
||
|
ATAN: Form arctangent value |
ATAN( ) |
||
|
NEG: Create twos complement |
-(in1) |
||
|
TRUNC: Truncate numerical value |
TRUNC( ) |
||
|
ROUND: Round numerical value |
ROUND( ) |
||
|
CEIL: Generate next higher integer from floating-point number |
CEIL( ) |
||
|
FLOOR: Generate next lower integer from floating-point number |
FLOOR( ) |
||
|
1) Not possible for data type BYTE. |
|||
Parameters
The following table shows the parameters of the instruction "Calculate":
|
Parameters |
Declaration |
Data type |
Memory area |
Description |
|
|---|---|---|---|---|---|
|
S7-1200 |
S7-1500 |
||||
|
EN |
Input |
BOOL |
I, Q, M, D, L or constant |
I, Q, M, D, L, T, C or constant |
Enable input |
|
ENO |
Output |
BOOL |
I, Q, M, D, L |
I, Q, M, D, L |
Enable output |
|
IN1 |
Input |
Bit strings, integers, floating-point numbers |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
First available input |
|
IN2 |
Input |
Bit strings, integers, floating-point numbers |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Second available input |
|
INn |
Input |
Bit strings, integers, floating-point numbers |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Additionally inserted inputs |
|
OUT |
Output |
Bit strings, integers, floating-point numbers |
I, Q, M, D, L, P |
I, Q, M, D, L, P |
Output to which the end result is to be transferred. |
You can find additional information on valid data types under "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
|
Parameters |
Operand |
Value |
|---|---|---|
|
IN1 |
Tag_Value_1 |
4 |
|
IN2 |
Tag_Value_2 |
4 |
|
IN3 |
Tag_Value_3 |
3 |
|
IN4 |
Tag_Value_4 |
2 |
|
OUT |
Tag_Result |
12 |
If the "Tag_Input" has the signal state "1", the instruction is executed. The value of operand "Tag_Value_1" is added to the value of operand "Tag_Value_2". The sum is multiplied with the value of the operand "Tag_Value_3". The product is divided by the value of the operand "Tag_Value_4". The quotient is transferred as end result to the operand "Tag_Result" at the OUT output of the instruction. If no errors occur during the execution of the individual instructions, output ENO and the operand "Tag_Output" are set to "1".