Compute (CPT)

This information applies to the CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, GuardLogix 5570, Compact GuardLogix 5380, CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, and GuardLogix 5580 controllers. Controller differences are noted where applicable.
When enabled, the CPT instruction evaluates the expression and places the result in the Dest.
The CPT instruction enables complex expressions in one instruction.
When evaluating the expression, all non-LREAL operands convert to LREAL before performing calculations if either of these conditions are true:
  • Any operand in the expression is LREAL.
  • The Dest is LREAL.
When evaluating the expression, all non-REAL operands will be converted to REAL before performing calculations if any operand or Dest in the expression is NOT LREAL, and any of these conditions are true:
  • Any operand in the expression is REAL.
  • The expression contains SIN, COS, TAN, ASN, ACS, ATN, LN, LOG, DEG or RAD.
  • The Dest is REAL.
There are rules for allowable operators in safety applications. See
Valid Operators
.
Available Languages
Ladder Diagram
L5K_CPT_LD_avail_v31
Function Block
This instruction is not available in function block.
Structured Text
This instruction is not available in structured text.
Operands
IMPORTANT:
Unexpected operation may occur if:
  • Output tag operands are overwritten.
  • Members of a structure operand are overwritten.
  • Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data Conversions.
Ladder Diagram
Operand
Data Type
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Format
Description
Dest
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
tag
Tag to store the result.
Expression
SINT
INT
DINT
REAL
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
immediate
tag
An expression consisting of tags and/or immediate values separated by operators.
Formatting expressions
For each operator used in an expression, one or two operands (tags or immediate values) must be provided. Use the following table to format operators and operands within an expression.
For operators that operate on:
Use this format:
Example
One operand
operator(operand)
ABS(tag)
Two operands
operand_a operator operand_b
tag_b + 5
tag_c AND tag_d
(tag_e**2) MOD (tag_f / tag_g)
Determine the order of operation
The instruction performs the operations in the expressions in a prescribed order. Specify the order of operation by grouping terms within parentheses. This forces the instruction to perform an operation within the parentheses ahead of the other operations.
Operations of equal order are performed from left to right.
Order
Operation
1
( )
2
ABS, ACOS, ASIN, ATAN, COS, DEG, BCD_TO, LN, LOG, RAD, SIN, SQRT, TAN, TO_BCD, TRUNC
3
**
4
- (negate), NOT
5
*, /, MOD
6
- (subtract), +
7
AND
8
XOR
9
OR
Affects Math Status Flags
Controllers
Affects Math Status Flags
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Conditional
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Yes
Major/Minor Faults
None specific to this instruction. See Index Through Arrays for array-indexing faults.
Execution
Ladder Diagram
Condition/State
Action Taken
Prescan
N/A
Rung-condition-in is false
Set Rung-condition-out to Rung-condition-in.
Rung-condition-in is true
Set Rung-condition-out to Rung-condition-in.
The instruction evaluates the expression and places the result in the Dest.
Postscan
N/A
Examples
Ladder Diagram
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.
CPT Result
CPT_LD_ex1_v31
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.
Ladder Diagram
L5K_CPT_LD_ex2_v31
CPT Result Example 2
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.