Subtract (SUB)

0 comments
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

Read More »

Add (ADD)

0 comments
The ADD instruction adds Source A to Source B 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 other structured text programming to achieve the same result.

Operands
-    Ladder Diagram

Operand
Type
Format
Description
Source A
SINT
INT
DINT
REAL
Immediate
tag
value to add to Source B
Source B
SINT
INT
DINT
REAL
immediate
tag
value to add to Source A
Destination
SINT
INT
DINT
REAL
tag
tag to store the result
A SINT or INT tag converts to a DINT value by sign-extension.

-    Function Block

Operand
Type
Format
Description
ADD tag
FBD_MATH
structure
ADD structure

-    Structured Text
Use the plus sign "+" as an operator within an expression. This expression adds sourceA to 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 to test against SourceB
Valid = any float
SourceB
REAL
Value to test against SourceA
Valid = any float


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

Example
Add float_value_1 to float_value_2 and place the result in add_result.

-    Ladder Diagram

-    Function Block


File name: PLC-17_IS_CMI-ADD.pdf
File size: 419.87 KB

Read More »

Compute (CPT)

0 comments
The CPT instruction performs the arithmetic operations you define in the expression.

Available Languages
-    Ladder Diagram

-    Function Block
This instruction is not available in function block.

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

* There is no equivalent structured text instruction. Use other structured text programming to achieve the same result.

Operands
-    Ladder Diagram

Operand
Type
Format
Description
Destination
SINT
INT
DINT
REAL
tag
tag to store the result
Expression
SINT
INT
DINT
REAL
immediate
tag
an expression consisting of tags and/or immediate values separated by operators.





-    Structured Text
Structured text does not have a CPT instruction, but you can achieve the same results using an assignment and expression.

destination := numeric_expression;

Example 1
When enabled, the CPT instruction evaluates value_1 multiplied by 5 and divides that result by the result of value_2 divided by 7 and places the final result in result_1.


Example 2
When enabled, the CPT instruction truncates float_value_1 and float_value_2 to the power of two and divides the truncated float_value_1 by that result, and then stores the remainder after the division in float_value_result_cpt.



File name: PLC-16_IS_CMI-CPT.pdf
File size: 397.84 KB

Read More »

Compute and Math Instructions

0 comments

The compute/math instructions evaluate arithmetic operations using an expression.

Available Instructions





If you want to:
Use this instruction:
evaluate an expression
add two values
subtract two values
multiply two values
divide two values
determine the remainder after one value is divided by another
calculate the square root of a value
take the opposite sign of a value
take the abosolute value of a value
ABS



You can mix data types, but loss of accuracy and rounding error might occur and the instruction takes more time to execute. Check the S:V bit to see whether the result was truncated.
The bold data types indicate optimal data types. An instruction executes faster and requires less memory if all the operands of the instruction use the same optimal data type, typically DINT or REAL.
A compute/math instruction executes once each time the instruction is scanned as long as the rung-condition-in is true. If you want the expression evaluated only once, use any one-shot instruction to trigger the instruction.


File name: PLC-15_IS-CMI.pdf
File size: 388.26 KB

Read More »

Not Equal To (NEQ)

0 comments
The NEQ instruction tests whether Source A is not equal to Source B.

Available Languages
-    Ladder Diagram


-    Function Block


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

* There is no equivalent structured text instruction. Use other structured text programming to achieve the same result.

Operands
-    Ladder Diagram

Operand
Type
Format
Description
Notes
Source A
SINT
INT
DINT
REAL
String type

Immediate
tag
value to test against Source B
If you enter a SINT or INT tag, the value converts to a DINT value by sign-extension.

String types are:
-          Default STRING data type
-          Any new string type you create

To test the characters of a string, enter a string type tag for both Source A and Source B.
Source B
SINT
INT
DINT
REAL
String type
Immediate
tag
value to test against Source A

-    Function Block

Operand
Type
Format
Description
NEQ tag
FBD_COMPARE
structure
NEQ structure

-    Structured Text
Use the less than and greater than signs "<>" together as an operator within an expression. This expression evaluates whether sourceA is not equal to sourceB.

IF sourceA <> sourceB THEN
 <statements>;

FBD_COMPARE 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 to test against SourceB
Valid = any float
SourceB
REAL
Value to test against SourceA
Valid = any float


Output Parameter
Data Type
Description
EnableOut
BOOL
Enable output.
Dest
BOOL
Result of the instruction. This is equivalent to rung-condition-out of the ladder diagram NEQ instruction.

Example
If value_1 is not equal to value_2, set light_4. If value_1 is equal to value_2, clear light_4.

-    Ladder Diagram


-    Function Block


-    Structured Text
light_4 := (value_1 <> value_2);


- Download to PDF


Read More »