Using the CPT compute function
The CPT function is used to compute mathematical equations easily in Ladder Diagram.
-
If the EN input is TRUE, the EXP string input will be processed and output the result in the OUT element.
-
Functions can also be used in the expression (EXP) string.
-
The result of the expression must match the data type of the variable being used to store the result.
Element Name | Element Type | Description |
---|---|---|
EN | Input | Executes the CPT function when TRUE. |
EXP | Input | Expression to solve in string format. Max size of the EXP input is 100 bytes (100 characters). |
ENO | Output | Outputs the value of EN. |
OUT | Output | Result of the expression.Data type of variable mapped to OUT must match the result of the expression. |
Comparison Functions
EQ, GE, GT, LE, LT and NE.
-
Example: "(Var1 > Var2) AND (Var1 > Var3)" -> Var1, Var2, and Var3 are variables.
Numerical Operations
ABS, ACOS, ADD, ASIN, ATAN, COS, DIV, EXP, EXPT, LN, LOG, MOVE, MUL, SIN, SQRT, SUB, TAN, TRUNC
-
Example: "(Var1*Var2)/Var3"-> Var1, Var2, and Var3 are variables.
-
Example: "5*3+4-9" -> works with just constants also.
Angle Conversion
DEG, RAD
-
Example: "5.0*RAD (tempDegree)" -> tempDegree is a variable.
Type Conversion
All type conversions that do not contain special symbols “(***)”.
-
Example: "10 * REAL_TO_DINT(tempReal)"
These examples show a few of the supported capabilities of the CPT function.
CPT Example Variables
CPT Angle Conversion Example
CPT Numerical Operation Example
CPT Comparison Operation Example
CPT Type Conversion Example
LP313