Compute (CPT)
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
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 | Format | Description |
---|---|---|---|
Dest | SINT INT DINT LINT USINT UINT UDINT ULINT REAL LREAL | tag | Tag to store the result. |
Expression | 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, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD, SIN, SQR, TAN, TOD, TRN |
3 | ** |
4 | - (negate), NOT |
5 | *, /, MOD |
6 | - (subtract), + |
7 | AND |
8 | XOR |
9 | OR |
Affects Math Status Flags
See Math status flags.
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.
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
Provide Feedback