RSLogix 5000 provides powerful math instructions to perform arithmetic and advanced calculations within ladder logic programming. These instructions include basic operations such as ADD, SUB, MUL, and DIV, as well as functions like MOD (modulus), SQRT (square root), NEG (negate), and ABS (absolute value).
The CPT (Compute) instruction allows for complex mathematical expressions to be written in a single block, making it ideal for combining multiple operations efficiently. This guide explains each instruction, its syntax, parameters, and usage with examples for Allen Bradley ControlLogix and CompactLogix PLCs.
Math instructions in RSLogix 5000 are used to perform arithmetic and numerical operations within ladder logic programs. These instructions operate on tag values and support common data types such as INT (Integer), DINT (Double Integer), and REAL (Floating Point). Math instructions are essential for tasks like analog scaling, counter calculations, totalization, and data comparison in control systems.
You can use individual math instructions for simple operations or combine them inside the CPT (Compute) instruction for advanced expressions. All math instructions require valid source and destination tags. The source tags provide input values, and the destination tag stores the result.
The ADD instruction performs addition by summing two values: Source A and Source B. The result is stored in the Destination tag.
Each of these fields – Source A, Source B, and Destination – can be tags or constants. The data types commonly used are INT, DINT, or REAL.
Operands:
For example, if:
The result of tag_Input1 + 25.5 will be saved in tag_OutputSum.
This instruction is commonly used for analog signal adjustments, scaled calculations, and process totalization.
The SUB instruction performs subtraction by subtracting Source B from Source A. The result is stored in the Destination tag.
All three fields – Source A, Source B, and Destination – can be tags or constants. The most commonly used data types are INT, DINT, or REAL.
Operands:
For example, if:
The result of Tank_Level - 5.0 will be stored in Adjusted_Level.
This instruction is useful in applications like setpoint deviation, level correction, or adjusting sensor offsets.
The MUL instruction multiplies two values: Source A and Source B, and stores the result in the Destination.
Both sources can be tag values or constants, and the destination must support the result's data type. Common data types used are INT, DINT, or REAL.
Operands:
Example:
This instruction is widely used for scaling, power calculation (e.g., V × I), and time conversion.
The DIV instruction divides Source A by Source B and stores the result in the Destination tag.
Ensure the data types support the division result. Use REAL data type for fractional or floating-point results to avoid truncation.
Operands:
Example:
This instruction is commonly used for average calculation, ratio control, and time-based rate measurements.
The MOD instruction in RSLogix 5000 is used to find the remainder after division. It is helpful in applications where a value must wrap around after reaching a certain limit, such as indexing, blinking operations, or alternating between states.
Parameters:
Example:
If Source A = 17 and Source B = 5, then the result stored in Destination = 2 (because 17 ÷ 5 = 3 remainder 2).
The SQRT instruction calculates the square root of a given non-negative number. It takes one SOURCE value and stores the result in the DEST tag.
Usage Format:
Example:
Result: Root_Result = 12.0
Application: Calculating the magnitude of voltage or current in vector-based systems, or in RMS formula like √(A² + B²).
The NEG instruction changes the sign of a number. It multiplies the input by -1. This is useful when dealing with direction reversal, signed values, or correcting values in control logic.
Parameters:
Example:
If Source = 25, then Destination = -25. Similarly, if Source = -10, then Destination = 10.
The CPT (Compute) instruction in RSLogix 5000 evaluates a complete mathematical expression and stores the result in a specified Dest tag.
This instruction is used when complex arithmetic operations involving multiple operands and mathematical functions are required. The CPT instruction enables expressions like (A + B) * C / D in a single rung.
Imagine a vertical cylindrical tank. The volume of a cylinder is calculated using the formula:
Volume = π × r² × h
In the PLC:
CPT instruction expression:
CPT Dest: FilledVolume Expression: 3.1416 * Radius * Radius * Level
This computes the volume of water based on the current level in the tank.Advantages of CPT Instruction
The ABS instruction in RSLogix 5000 calculates the absolute value of a number. It removes the negative sign, if any, and returns only the positive magnitude of the input.
This instruction is useful when you want to ensure a value is always positive, such as when dealing with direction-independent measurements like speed, temperature deviations, or error values.
If Source = -45.7
, then after ABS instruction executes, Dest = 45.7
.
Use this to avoid errors in calculations that require non-negative values.