The Compute instruction is a ladder logic rung output instruction that performs valid arithmetic expressions. The instruction is enabled when the preceding logic is true and disabled otherwise. The result of the expression is placed in the Destination tag. The Compute instruction is slower and uses more memory than other math instructions; however it allows complex expressions in one instruction.
The expression is defined using tags, math operators, and constants. Parentheses ( ) are used to give priority to sections of an expression. Here is a list of logical operands.
Expressions are executed in a predetermined order of operation, not the order they are written in. The operation order may be changed by placing sections of the expression in parentheses as an expression enclosed in parentheses will execute first.
Order Operation
- 1 () Parentheses
- 2 ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR, TAN, TOD, TRN
- 3 **
- 4 –(negate), NOT
- 5 *, /, MOD
- 6 –(subtract), +(add)
- 7 AND
- 8 XOR
- 9 OR
Expression examples: The result of the expression is placed in the tag referenced in the Destination part of the instruction.
- (3*2)/2
- (TAG_A / TAG_B) AND TAG_C
- (1+1+5+TAG_D/(TAG_A)) MOD (TAG_Z * TAG_Y)
The DESTINATION and EXPRESSION can be of the following data types.
- SINT PRE DEFINED STRUCTURE
- INT PRE DEFINED STRUCTURE
- DINT PRE DEFINED STRUCTURE
- REAL PRE DEFINED DATA TYPE
Note: Not all advanced operands are available in safety routines. Expression can be of infinite length (that’s long). Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.