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.
-
MELSEC Tutorial 01 – PLC System Configuration
MELSEC Tutorial 01 – System Configuration, Installation, and Wiring Setting up a MELSEC PLC system is the first step in…
-
MELSEC Tutorial 02 – PLC Module Configuration Diagram
MELSEC Tutorial 02 – Module Configuration Diagram Creating a module configuration diagram is a critical step in setting up a…
-
MELSEC Tutorial 03 – Ladder Program
MELSEC Tutorial 03 – Ladder Program In industrial automation, programming controls the behavior of devices and systems. MELSEC Ladder Programming…
-
MELSEC Tutorial 04 – Create a Ladder Program
MELSEC Tutorial 04 – Create a Ladder Program Industrial automation relies heavily on programming to implement control logic for machines…
-
MELSEC Tutorial 05 – Ladder Sequence Instructions
MELSEC Tutorial 05 – Ladder Logic Programming Sequence Instructions Ladder Logic Programming is a vital skill for developing control systems…
-
MELSEC Tutorial 06 – Ladders Timers and Counters
MELSEC Tutorial 06 – Ladder Logic Programming: Timer and Counter MELSEC Timers and counters are fundamental tools in ladder logic…
-
MELSEC Tutorial 07 – Ladder Logic Programming Data Transfer
MELSEC Tutorial 07 – Ladder Logic Programming: Data Transfer In ladder logic programming, data transfer instructions are crucial for moving…
-
MELSEC Tutorial 08 – Ladder Comparison Operations
MELSEC Tutorial 08 – Ladder Logic Programming: Comparison Operation In industrial automation, MELSEC comparison operations play a vital role in…
-
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…
-
MELSEC Tutorial 10 – Ladder Input Instructions
MELSEC Tutorial 10 – Ladder Logic Programming: Input Instructions MELSEC Ladder logic programming depends on input instructions to define how…
-
MELSEC Tutorial 11 – Creating ladder logic comments
MELSEC ladder logic Creating Comments, Statements, and Notes When programming with ladder logic, clarity is essential to ensure the program…
-
MELSEC Tutorial 12 – Writing to PLC
MELSEC Tutorial 12 – Writing to PLC In this tutorial, we’ll explore how to write programs to a PLC using…
-
MELSEC Tutorial 13 – Debugging and Maintenance
MELSEC Tutorial 13 – Debugging and Maintenance Efficient debugging and maintenance are critical aspects of working with MELSEC PLC systems,…
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
.
- Insert an ADD instruction in the ladder logic.
- Specify the source operands (
D0
andD1
) 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
.
- Insert a SUB instruction.
- Specify
D0
andD1
as operands andD2
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
.
- Insert a MUL instruction in your program.
- 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
.
- Add a DIV instruction.
- Define
D0
as the dividend,D1
as the divisor, andD2
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
.
- Perform the addition (
D0 + D1
) using an ADD instruction, storing the intermediate result inD4
. - Use a MUL instruction to multiply
D4
andD2
, storing the final result inD3
.
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
.
- Use a MOV instruction to load the scaling factor (1.5) into a temporary register (
D5
). - 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:
- View real-time register values during program execution.
- Modify register values to simulate different inputs and observe the results.
Conclusion
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.