1. Classification System of Arithmetic Operation Instructions
1. Basic Four Arithmetic Operations
ADD 16-bit Addition Production Accumulation
SUB 16-bit Subtraction Remaining Material Calculation
MUL 16-bit Multiplication Area Calculation (Length × Width)
DIV 16-bit Division Speed Conversion (Meters/Minute → Meters/Second)
DADD 32-bit Addition Large Number Calculation (e.g., Annual Cumulative Production)
2. Increment/Decrement Instructions
INC 16-bit Increment Product Counter
DEC 16-bit Decrement Inventory Decrease Count
DINC 32-bit Increment High-Speed Counter Expansion
3. Floating Point Operation Instructions
FLT Integer to Floating Point Conversion High Precision Calculation (e.g., Temperature Control)
ADD.F Floating Point Addition Flow Accumulation
SUB.F Floating Point Subtraction Difference Calculation
2. Core Instruction Practical Cases
Case 1: Production Line Output Statistics System
Control Requirements: For each product produced, increment counter D100 by 1, and automatically transfer the value of D100 to D200 (hourly accumulation) every hour.
// Product Counting
LD X0 // Counting Signal
INC D100 // D100=Current Output
// Hourly Accumulation
LD M8014 // Minute Pulse (1 minute = 60 seconds)
CMP M8014 K60 // When the 60th minute occurs
LD = M0 // Comparison Result Equals
ADD D100 D200 D200 // Hourly Accumulation = Previous Value + Current Output
MOV K0 D100 // Reset Current Output
Optimization Points:
1. Use INC instruction instead of ADD K1 to reduce code size
2. Use CMP for timed transfer
Case 2: Recipe Ratio Calculation System
Control Requirements: Raw Material A accounts for 60%, Raw Material B accounts for 40%; Automatically calculate A/B usage based on total weight D100.
// Calculate Raw Material A Usage
MOV D100 D200 // Total Weight
MUL D200 K60 D300 // A Usage = Total Weight × 60%
// Calculate Raw Material B Usage
SUB D100 D300 D400 // B Usage = Total Weight – A Usage
Notes:
Multiplication results may exceed 16 bits (D300 must use a 32-bit register)
In practical applications, decimal point processing needs to be added (using FLT instruction)
Case 3: Temperature PID Control System
Control Requirements: Real-time calculation of temperature deviation (Set Value – Measured Value); Integral term accumulates deviation value
// Calculate Temperature Deviation
SUB D100 D200 D300 // D100=Set Value, D200=Measured Value
// Integral Term Accumulation
ADD D400 D300 D400 // Integral Term = Previous Value + Deviation
Key Parameters:
D300 stores real-time deviation value
D400 stores integral term accumulated value
Case 4: Motor Speed Conversion System
Control Requirements: Read encoder pulse count D100 (100ms sampling); Convert to speed (revolutions/minute)
// Calculate Speed
FLT D100 D200 // Convert pulse count to floating point
MUL D200 K6 D300 // 100ms×6=1 minute
DIV D300 K1000 D400 // Speed = Total Pulses/1000
Step Analysis:
1. Convert pulse count to floating point (to avoid integer division loss of precision)
2. Calculate total pulse count in 1 minute
3. Divide by encoder pulses per revolution (assumed 1000P/R)
3. Advanced Application Techniques
1. Large Number Calculations
// Calculate 32-bit large number addition
DADD D100 D200 D300 // D100+D201=D300+D301
2. Dynamic Coefficient Adjustment
// Adjust coefficients based on production mode
MOV K[D0] D10 // D0 stores coefficient number (0-2)
MUL D10 D20 D30 // Dynamically calculate result
3. Error Compensation
// Perform linear compensation on sensor data
FLT D100 D200 // Convert raw value to floating point
ADD.F D200 K2.5 D300 // Compensation +2.5℃
4. Common Problems and Solutions
Problem 1: Multiplication Result Overflow
Cause: The maximum value of a 16-bit register is 32767, exceeding this will cause overflow
Solution: Use 32-bit instructions (DMUL) or floating point operations
Problem 2: Division Result Error
Cause: Divisor is 0 or integer division loses decimal places
Solution: Add divisor zero protection, use floating point division
Problem 3: Floating Point Operation Invalid
Cause: Floating point conversion (FLT) not enabled
Solution: Execute FLT instruction before performing floating point operations
5. Pitfall Guide
⚠️ Prohibited Actions:
1. Cannot perform arithmetic operations directly on BCD codes (must convert to BIN first)
2. Floating point operation instructions cannot be mixed with ordinary arithmetic instructions
3. Pay attention to register pairing when performing 32-bit operations (e.g., D100 and D101 form DD100)
💡 Optimization Tips:
Use DBCD instruction to perform operations directly on BCD codes
Display intermediate calculation results (e.g., D300) on the touchscreen
Add error detection for critical calculations (e.g., overflow flag M8022)
Next Issue Preview:
“Mitsubishi PLC Logic Operation Instructions in Practice” – From simple unit operations to complex state combinations, teaching you step by step how to make PLC learn “logical judgment”! Follow me to unlock new skills in digital circuits~