1. Classification System of Comparison Instructions
1. Single Value Comparison Instructions
CMP 16-bit single value comparison Temperature Over Limit Alarm
DCMP 32-bit single value comparison Production Target Value Comparison
ZCP Range Comparison Pressure Normal Range Detection
2. Data Processing Instructions
MEAN Average Value Calculation Remove Sensor Noise
MAX Maximum Value Detection Device Performance Monitoring
MIN Minimum Value Detection Material Lower Limit Alarm
3. Floating Point Comparison Instructions
CMP.F Floating Point Single Value Comparison High Precision Level Control
ZCP.F Floating Point Range Comparison Chemical Reaction Temperature Control
2. Core Instruction Practical Cases
Case 1: Constant Temperature Control System
Task Requirements: 1.When the temperature exceeds 50℃, start the cooling fan (Y0); 2.When the temperature is below 45℃, turn off the cooling fan
// Temperature Comparison
CMP D100 K50 M0 // D100=current temperature, compared with 50℃
LD M1 // When D100>50℃
OUT Y0 // Start cooling fan
LD M2 // When D100<45℃
OUT Y0 // Turn off cooling fan
Logic Analysis:
1.M0-M2 store comparison results (M0=D100<K50, M1=D100=K50, M2=D100>K50)
2.Control output state through M1/M2
Case 2: Equipment Operating Range Monitoring
Task Requirements: 1.When the pressure value is between 20-30bar, the equipment operates normally (Y1); 2.Trigger alarm (Y2) when out of range
// Pressure Range Comparison
ZCP K20 K30 D200 M10 // D200=current pressure
LD M12 // When D200>30bar
OUT Y2 // High Pressure Alarm
LD M10 // When D200<20bar
OUT Y2 // Low Pressure Alarm
LD M11 // When 20≤D200≤30
OUT Y1 // Normal Operation
Key Parameters:
K20=Lower Limit, K30=Upper Limit
M10-M12 store comparison results (M10=D200<K20, M11=K20≤D200≤K30, M12=D200>K30)
Case 3: Sensor Data Filtering System
Task Requirements: 1.Continuously collect 10 temperature values (D100-D109); 2.Calculate average value and display (D200)
// Data Collection
LD X0 // Sampling Trigger
BMOV D100 D110 K10 // Save historical data
// Calculate Average Value
MEAN D110 K10 D200 // Calculate the average of D110-D119
Optimization Points:
Use BMOV to save historical data
MEAN instruction automatically calculates average value, reducing programming workload
Case 4: Production Recipe Range Management
Task Requirements: 1.Select different parameter ranges based on product model; 2.Real-time monitoring of whether parameters are within allowed range
// Recipe Selection
LD X1 // Recipe 1 Selection
ZCP K10 K20 D300 M20 // Parameter Range 10-20
LD X2 // Recipe 2 Selection
ZCP K30 K40 D300 M30 // Parameter Range 30-40
// Alarm Output
LD M22 // Recipe 1 Parameter Exceeds Limit
OR M32 // Recipe 2 Parameter Exceeds Limit
OUT Y3 // Trigger Alarm
Extended Applications:
Dynamically modify ZCP’s upper and lower limit values using MOV instruction
Use CMP to achieve single value comparison (e.g., special handling when D300>K25)
3. Advanced Application Techniques
1. Dynamic Threshold Comparison
// Adjust temperature threshold based on production speed
MOV K[D0] D10 // D0 stores current speed, dynamically calculates threshold
CMP D20 D10 M0 // Current temperature compared with dynamic threshold
2. Multi-Condition Combined Comparison
// Trigger alarm when temperature>50℃ and pressure<30bar simultaneously
LD M1 // Temperature>50℃
AND NOT M12 // Pressure<30bar
OUT Y4 // Trigger Alarm
3. High Precision Floating Point Comparison
// High Precision Level Control (0.1mm accuracy)
FLT D400 D500 // Convert to floating point
CMP.F D500 K100.0 M50 // Compare with 100.0mm
4. Common Problems and Solutions
Problem 1: Abnormal Comparison Results
Cause: Register type mismatch (e.g., using 16-bit CMP to compare 32-bit data)
Solution: Use 32-bit instruction (DCMP) or double word register
Problem 2: ZCP Range Not Effective
Cause: Incorrect upper and lower limit settings (e.g., K30<K20)
Solution: Ensure upper limit value>lower limit value
Problem 3: MEAN Calculation Error
Cause: Number of data points exceeds register range (e.g., K15)
Solution: Reduce sampling count or use double word instruction
5. Pitfall Guide
⚠️ Prohibited Actions:
1. Cannot directly use comparison instructions on BCD codes (must convert to BIN first)
2. Floating point comparison must execute FLT conversion first
3. ZCP instruction cannot cross program end marker (END)
💡 Optimization Tips:
1. Use MOV K1 D0 to initialize comparison flags
2. Add comments to key comparisons (e.g., // High Temperature Alarm Threshold)
3. Display comparison results in real-time on the touchscreen (e.g., M0-M2)
Previous Recommendations: “Comprehensive Analysis of Mitsubishi PLC Logic Operation Instructions! From Simple Unit Operations to Complex State Combinations”
Previous Recommendations: “Comprehensive Analysis of Mitsubishi PLC Arithmetic Operation Instructions! From Basic Addition and Subtraction to Complex Algorithm Practice”
Previous Recommendations: “Comprehensive Analysis of Mitsubishi PLC Data Transmission Instructions! From Basics to Practical Core Instructions”
Previous Recommendations: “Comprehensive Analysis of Mitsubishi PLC Program Flow Control Instructions! 5 Core Instructions + Factory Practical Cases”
Previous Recommendations: “Ultimate Guide to Mitsubishi PLC Function Instructions! Comprehensive Analysis from Basics to Advanced”
Next Preview:
“Mitsubishi PLC Data Conversion Instructions in Practice”—— From BCD Code to ASCII, a step-by-step guide to overcoming communication “language barriers” between devices! Follow↓↓
Get more materials
What comparison instructions have you used in your projects? What comparison logic errors have you encountered? Feel free to share in the comments section.