Skip to content
Home » Blog » MELSEC Tutorial 09 – Ladder Arithmetic Operations

MELSEC Tutorial 09 – Ladder Arithmetic Operations

MELSEC Tutorial 09 – Ladder Logic Programming: Arithmetic Operations

MELSEC arithmetic operations form the backbone of ladder logic programming, enabling programmable logic controllers (PLCs) to perform calculations critical for industrial automation. In this tutorial, we will explore how to implement arithmetic operations like addition, subtraction, multiplication, and division in a MELSEC PLC using GX Works3.

YouTube player



What Are Arithmetic Operations in Ladder Logic?

Arithmetic operations allow a PLC to manipulate numerical data in real-time. These operations are vital for applications such as calculating production rates, scaling sensor values, or managing inventory systems. Common arithmetic instructions include:

  • ADD: Addition
  • SUB: Subtraction
  • MUL: Multiplication
  • DIV: Division


Step 1: Preparing for Arithmetic Operations

Defining Data Registers

Before programming, define the required data registers:

  • D0: First operand
  • D1: Second operand
  • D2: Result of the operation

Ensure these registers are assigned correctly in the Device/Label Editor.

Initializing Test Values

To test your program, assign initial values to the registers through the Test Write feature in GX Works3.


Step 2: Implementing Basic Arithmetic Operations

Example 1: Addition

Scenario: Add values in D0 and D1, and store the result in D2.

  1. Insert an ADD instruction in the ladder logic.
  2. Specify the source operands (D0 and D1) and the destination register (D2).

Ladder Logic Code:

ADD D0 D1 D2 --] [--

When executed, D2 = D0 + D1.


Example 2: Subtraction

Scenario: Subtract D1 from D0, and store the result in D2.

  1. Insert a SUB instruction.
  2. Specify D0 and D1 as operands and D2 as the destination.

Ladder Logic Code:

SUB D0 D1 D2 --] [--

D2 will hold the value of D0 - D1.


Example 3: Multiplication

Scenario: Multiply D0 by D1, and store the result in D2.

  1. Insert a MUL instruction in your program.
  2. Specify the operand registers (D0, D1) and the destination (D2).

Ladder Logic Code:

MUL D0 D1 D2 --] [--

The value in D2 becomes D0 × D1.


Example 4: Division

Scenario: Divide D0 by D1, and store the quotient in D2.

  1. Add a DIV instruction.
  2. Define D0 as the dividend, D1 as the divisor, and D2 as the destination.

Ladder Logic Code:

DIV D0 D1 D2 --] [--

If D1 ≠ 0, D2 = D0 ÷ D1.


Step 3: Advanced Operations

Example: Combining Operations

Scenario: Calculate the formula (D0 + D1) × D2, and store the result in D3.

  1. Perform the addition (D0 + D1) using an ADD instruction, storing the intermediate result in D4.
  2. Use a MUL instruction to multiply D4 and D2, storing the final result in D3.

Ladder Logic Code:

ADD D0 D1 D4 --] [--
MUL D4 D2 D3 --] [--

Example: Real-Time Scaling

Scenario: Scale a sensor value in D0 by multiplying it with a factor (e.g., 1.5), and store the scaled value in D2.

  1. Use a MOV instruction to load the scaling factor (1.5) into a temporary register (D5).
  2. Perform the multiplication (D0 × D5) using a MUL instruction.

Ladder Logic Code:

MOV K15 D5 --] [--
MUL D0 D5 D2 --] [--


Step 4: Debugging and Monitoring MELSEC Arithmetic Operations

Use GX Works3’s Online Monitor to:

  1. View real-time register values during program execution.
  2. Modify register values to simulate different inputs and observe the results.

Conclusion

Ladder logic diagram illustrating arithmetic operations like addition, subtraction, multiplication, and division in MELSEC PLC programming.

MELSEC Arithmetic operations enhance the functionality of ladder logic programs, enabling PLCs to process and analyze data dynamically. By mastering these operations, you can create efficient and scalable programs tailored to your automation needs.

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO