Loading AILogicHMI...

PLC Arithmetic instructions (ADD, SUB, MUL, DIV with practical examples)

admin
Aug 26, 2025
8 min read
Ladder Logic Visualization
PLC Arithmetic Instructions (ADD, SUB, MUL, DIV) Input 1 Input 2 PLC Processing ADD, SUB, MUL, DIV = Output AILogicHMI
PLC Arithmetic Instructions (ADD, SUB, MUL, DIV with Practical Examples)

PLC Arithmetic Instructions (ADD, SUB, MUL, DIV with Practical Examples)

Programmable Logic Controllers (PLCs) are the backbone of modern industrial automation, controlling everything from simple conveyor belts to complex robotic systems. A fundamental aspect of PLC programming involves performing mathematical calculations. This article delves into the essential PLC arithmetic instructions – ADD (addition), SUB (subtraction), MUL (multiplication), and DIV (division) – providing practical examples to help you understand how to implement them effectively in your ladder logic programs. Understanding these PLC arithmetic instructions is crucial for creating sophisticated control systems that can perform real-time calculations and adjustments.

Introduction to PLC Arithmetic Operations

PLCs often need to perform calculations based on sensor inputs, timer values, or other process variables. These calculations can range from simple addition and subtraction to more complex multiplication and division operations. The PLC arithmetic instructions provide the tools to perform these calculations directly within the PLC program.

These instructions are essential for tasks such as:

  • Scaling analog signals
  • Calculating flow rates
  • Controlling motor speeds
  • Monitoring temperature and pressure

In this article, we will explore each of these instructions in detail, providing practical examples using ladder logic diagrams. We will also discuss some common considerations and best practices for using arithmetic operations in PLC programming.

The ADD Instruction: Adding Values in PLC Logic

The ADD instruction is used to add two or more numerical values together. The result of the addition is then stored in a designated destination register. Understanding the PLC ADD instruction example is crucial for basic PLC programming.

Syntax: In most PLC programming environments, the ADD instruction typically requires specifying the source values to be added and the destination register where the result will be stored.

Example: Adding Two Registers in Ladder Logic

Let's consider a simple example where we want to add the values stored in two registers, N7:0 and N7:1, and store the result in register N7:2.

--] [--------------------(ADD)--------------------
              N7:0     Source A
              N7:1     Source B
              N7:2     Destination
            --] [---------------------------------------------

In this example, when the rung condition is true, the ADD instruction will add the value in N7:0 to the value in N7:1 and store the sum in N7:2.

Important Note: Ensure that the destination register is large enough to accommodate the result of the addition. If the result exceeds the maximum value that the register can hold, an overflow error may occur.

The SUB Instruction: Subtracting Values in PLC Logic

The SUB instruction is used to subtract one numerical value from another. The result of the subtraction is then stored in a designated destination register. Understanding the PLC SUB instruction example is crucial for control applications.

Syntax: Similar to the ADD instruction, the SUB instruction requires specifying the source values (minuend and subtrahend) and the destination register.

Example: Subtracting Two Registers in Ladder Logic

Let's consider an example where we want to subtract the value in register N7:1 from the value in register N7:0 and store the result in register N7:2.

--] [--------------------(SUB)--------------------
              N7:0     Source A (Minuend)
              N7:1     Source B (Subtrahend)
              N7:2     Destination
            --] [---------------------------------------------

In this example, when the rung condition is true, the SUB instruction will subtract the value in N7:1 from the value in N7:0 and store the difference in N7:2.

Caution: Be mindful of the order of operands in the SUB instruction. Subtracting A from B is different from subtracting B from A. Also, negative results are possible, so ensure the destination register can handle signed values.

The MUL Instruction: Multiplying Values in PLC Logic

The MUL instruction is used to multiply two numerical values together. The product of the multiplication is then stored in a designated destination register. Understanding the PLC MUL instruction example is important for scaling and calculations.

Syntax: The MUL instruction requires specifying the source values (multiplicand and multiplier) and the destination register.

Example: Multiplying Two Registers in Ladder Logic

Let's consider an example where we want to multiply the value in register N7:0 by the value in register N7:1 and store the result in register N7:2.

--] [--------------------(MUL)--------------------
              N7:0     Source A (Multiplicand)
              N7:1     Source B (Multiplier)
              N7:2     Destination
            --] [---------------------------------------------

In this example, when the rung condition is true, the MUL instruction will multiply the value in N7:0 by the value in N7:1 and store the product in N7:2.

Tip: Multiplication can quickly result in large numbers. Ensure that the destination register is large enough to accommodate the product to avoid overflow errors. Consider using double-integer registers (e.g., DINT) for large results.

The DIV Instruction: Dividing Values in PLC Logic

The DIV instruction is used to divide one numerical value by another. The quotient of the division is then stored in a designated destination register. Understanding the PLC DIV instruction example is critical for ratio calculations and scaling.

Syntax: The DIV instruction requires specifying the source values (dividend and divisor) and the destination register.

Example: Dividing Two Registers in Ladder Logic

Let's consider an example where we want to divide the value in register N7:0 by the value in register N7:1 and store the result in register N7:2.

--] [--------------------(DIV)--------------------
              N7:0     Source A (Dividend)
              N7:1     Source B (Divisor)
              N7:2     Destination (Quotient)
            --] [---------------------------------------------

In this example, when the rung condition is true, the DIV instruction will divide the value in N7:0 by the value in N7:1 and store the quotient in N7:2.

Caution: Division by zero is undefined and will cause an error in most PLC systems. Always ensure that the divisor is not zero before executing the DIV instruction. Implement logic to prevent division by zero.

Example: Division by Zero Prevention

--] [--------] [--------------------(DIV)--------------------
              N7:1  <> 0   N7:0     Source A (Dividend)
                           N7:1     Source B (Divisor)
                           N7:2     Destination (Quotient)
            --] [---------------------------------------------

Practical Examples of PLC Arithmetic in Action

Let's look at some real-world examples of how PLC arithmetic instructions can be used in industrial applications.

Example 1: Scaling an Analog Input

Suppose you have an analog input signal from a temperature sensor that ranges from 4-20mA, representing a temperature range of 0-100°C. You need to scale this signal to a usable temperature value within the PLC.

Here's how you can use PLC math functions to achieve this:

  1. Read the raw analog input value (e.g., in register AI:0).
  2. Subtract the minimum analog value (4mA) from the raw value.
  3. Multiply the result by the temperature range (100°C).
  4. Divide the result by the analog signal range (16mA).
  5. Store the scaled temperature value in a designated register.
--] [--------------------(SUB)--------------------
              AI:0     Source A (Raw Analog Input)
              4        Source B (Minimum Analog Value)
              N7:0     Destination (Adjusted Analog Value)
            --] [---------------------------------------------

            --] [--------------------(MUL)--------------------
              N7:0     Source A (Adjusted Analog Value)
              100      Source B (Temperature Range)
              N7:1     Destination (Scaled Value)
            --] [---------------------------------------------

            --] [--------------------(DIV)--------------------
              N7:1     Source A (Scaled Value)
              16       Source B (Analog Signal Range)
              N7:2     Destination (Temperature in °C)
            --] [---------------------------------------------

Example 2: Calculating Flow Rate

Consider a flow meter that outputs a pulse signal proportional to the flow rate. You need to calculate the flow rate in gallons per minute (GPM) based on the pulse frequency.

Here's how you can use arithmetic operations in PLC programming to calculate the flow rate:

  1. Read the pulse count over a specific time interval (e.g., 1 second).
  2. Multiply the pulse count by a calibration factor (pulses per gallon).
  3. Multiply the result by 60 to convert to gallons per minute.
  4. Store the calculated flow rate in a designated register.
--] [--------------------(MUL)--------------------
              C5:0.ACC Source A (Pulse Count)
              0.1      Source B (Calibration Factor - Pulses/Gallon)
              N7:0     Destination (Gallons per Second)
            --] [---------------------------------------------

            --] [--------------------(MUL)--------------------
              N7:0     Source A (Gallons per Second)
              60       Source B
              N7:1     Destination (Gallons per Minute)
            --] [---------------------------------------------

Conclusion

Mastering PLC arithmetic instructions is fundamental to building robust and efficient industrial automation systems. By understanding how to use the ADD, SUB, MUL, and DIV instructions, you can create PLC programs that perform real-time calculations, adapt to changing conditions, and optimize process performance. Remember to consider potential issues such as overflow errors and division by zero, and implement appropriate safeguards to ensure reliable operation.

Ready to take your PLC programming skills to the next level? Explore advanced PLC programming techniques and best practices to build even more sophisticated control systems. Contact us today to learn more about our PLC training programs!

Discussion (0)

Start the conversation!
Share your thoughts on this article.