Arithmetic instructions
67
Part II IEC Instructions
ABS
Absolute Value
To add an enable input and enable output to the instruction, select [With EN/ENO] from the
"Instructions" pane (LD, FBD or IL editor). To reuse an instruction select "Recently used" from the
context menu or press <Ctrl>+<Shift>+<v> in the programming window.
PLC types Availability of ABS (see page 1318)
Data type I/O Function
INT, DINT,
REAL
input input data type
INT, DINT,
REAL
output as input absolute value
This example uses variables. You can also use a constant for the input variable.
Description
ABS calculates the value in the accumulator into an absolute value. The result is saved in the
output variable.
Data types
Example
In this example, the same POU header is used for all programming languages. For an example
using IL (instruction list), please refer to the online help.
POU header
All input and output variables used for programming this function have been declared in the POU
header.
Body
Input_value of the data type INTEGER is converted into an absolute value of the data type
INTEGER. The converted value is written into absolute_value.
LD
ST
When programming with structured text, enter the following:
absolute_value:=ABS(input_value);