Subtract (SUB)

The SUB instruction subtracts Source B from Source A and places the result in the Destination.

Available Languages

-    Ladder Diagram

-    Function Block

-    Structured Text
 This instruction is not available in structured text. *

* There is no equivalent structured text instruction. Use the operator in an expression.

Operands
-    Ladder Diagram
Operand
Type
Format
Description
Source A
SINT
INT
DINT
REAL
Immediate
tag
value to subtract to Source B
Source B
SINT
INT
DINT
REAL
immediate
tag
value to subtract to Source A
Destination
SINT
INT
DINT
REAL
tag
tag to store the result

-    Function Block
Operand
Type
Format
Description
SUB tag
FBD_MATH
structure
SUB structure

-    Structured Text
Use the minus sign "-" as an operator within an expression. This expression subtracts sourceA from sourceB and stores the result in dest.

dest := sourceA - sourceB;

FBD_MATH Structure

Input Parameter
Data Type
Description
EnableIn
BOOL
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
SourceA
REAL
Value from which to subtract SourceB.
Valid = any float
SourceB
REAL
Value to subtract from SourceA.
Valid = any float


Output Parameter
Data Type
Description
EnableOut
BOOL
Enable output.
Dest
REAL
Result of the math instruction. Arithmetic status flags are set for this output.

Example
Subtract float_value_2 from float_value_1 and place the result in subtract_result.

-    Ladder Diagram
-    Function Block
-    Structured Text

subtract_result := float_value_1 - float_value_2;

File name: PLC-18_IS_CMI-SUB.pdf
File size: 418.93 KB

0 comments :