Posted in

How to use the comparison operation in Mitsubishi PLCs programming?

How to use the comparison operation in Mitsubishi PLCs programming?

As a supplier of Mitsubishi PLCs, I’ve witnessed firsthand the transformative impact these programmable logic controllers can have on industrial automation. One of the most powerful and frequently used features in Mitsubishi PLC programming is the comparison operation. In this blog, I’ll share my insights and experiences on how to effectively use comparison operations in Mitsubishi PLC programming. Mitsubishi PLCs

Understanding Comparison Operations

Comparison operations are fundamental in programming as they allow the PLC to make decisions based on certain conditions. In Mitsubishi PLCs, comparison operations involve evaluating the relationship between two values or data sets. For example, you might want to check if one value is greater than, less than, equal to, or not equal to another value.

The basic comparison operators in Mitsubishi PLC programming include:

  • Equal to (=): Checks if two values are the same.
  • Not equal to (<>): Ensures that two values are different.
  • Greater than (>): Determines if the first value is larger than the second.
  • Less than (<): Checks if the first value is smaller than the second.
  • Greater than or equal to (>=): Verifies if the first value is either larger than or equal to the second.
  • Less than or equal to (<=): Checks if the first value is either smaller than or equal to the second.

These operators are used in conditional statements within ladder logic, which is the most common programming language for Mitsubishi PLCs. The result of a comparison operation is a boolean value (true or false), which can then be used to control the flow of the program, such as activating an output, starting a timer, or executing a specific sequence of instructions.

Implementing Comparison Operations in Ladder Logic

Step 1: Identify the Comparison Requirement

Before writing any code, you need to clearly define the comparison you want to perform. This involves determining the values or data sources that will be compared and the specific condition you want to check. For example, you might want to compare the current temperature reading from a sensor with a predefined setpoint temperature to decide whether to turn on a heater.

Step 2: Select the Appropriate Comparison Instruction

In Mitsubishi PLC ladder logic, comparison instructions are represented by specific symbols. These symbols typically include the comparison operator and two input boxes where you can specify the values or addresses that will be compared.

For example, to perform an equal-to comparison, you would use the "STL" (Step Ladder) instruction with the "=" operator. The instruction would look something like this:

LD X0
CMP K10 D0
OUT Y0

In this code snippet:

  • LD X0 is the instruction to load the input signal X0 into the PLC’s internal memory.
  • CMP K10 D0 is the comparison instruction. It compares the constant value K10 with the value stored in register D0.
  • OUT Y0 is the output instruction. If the comparison result is true (i.e., the value in D0 is equal to 10), the output Y0 will be energized.

Step 3: Incorporate the Comparison into the Ladder Logic

Once you have selected the appropriate comparison instruction, you need to integrate it into the overall ladder logic program. This may involve combining the comparison with other instructions, such as timers, counters, or other conditional statements.

For example, you might want to add a timer to delay the activation of an output after a comparison condition is met. The modified ladder logic could look like this:

LD X0
CMP K10 D0
ANI M100
TON T0 K100
LD T0
OUT Y0

In this updated code:

  • ANI M100 is an AND instruction that checks if the auxiliary relay M100 is off.
  • TON T0 K100 is a timer instruction that starts a timer T0 with a preset value of 100 (the exact time unit depends on the PLC configuration).
  • LD T0 is used to check if the timer T0 has timed out.
  • OUT Y0 is the output instruction that energizes the output Y0 if the timer has timed out.

Practical Examples of Using Comparison Operations

Example 1: Level Control in a Tank

Imagine you have a water tank with a level sensor that provides a continuous analog signal representing the water level. You want to maintain the water level between a minimum and maximum level.

The ladder logic for this application could be as follows:

LD X0
MOV D100 D0 ; Transfer the analog input value to D0
CMP K10 D0 ; Compare the water level with the minimum level
OUT M0 ; Set M0 if the level is below the minimum
CMP K50 D0 ; Compare the water level with the maximum level
OUT M1 ; Set M1 if the level is above the maximum
LD M0
AND NOT M1
OUT Y0 ; Turn on the pump to fill the tank if the level is low and not high
LD M1
AND NOT M0
OUT Y1 ; Turn on the drain valve if the level is high and not low

In this example:

  • The value from the analog input is transferred to register D0.
  • Two comparison operations are performed: one to check if the level is below the minimum and another to check if it is above the maximum.
  • Based on the comparison results, the appropriate output (pump or drain valve) is energized.

Example 2: Speed Monitoring in a Conveyor Belt

Suppose you have a conveyor belt with a speed sensor that measures the belt’s rotational speed. You want to detect if the speed falls below a certain threshold indicating a potential problem.

The ladder logic for this scenario could be:

LD X0
MOV D200 D0 ; Transfer the speed value to D0
CMP K200 D0 ; Compare the speed with the minimum acceptable speed
OUT M2 ; Set M2 if the speed is below the threshold
LD M2
OUT Y2 ; Activate an alarm if the speed is low

In this case:

  • The speed value from the sensor is transferred to register D0.
  • A comparison operation checks if the speed is below the minimum acceptable value.
  • If the comparison is true, an output Y2 is energized to activate an alarm.

Best Practices for Using Comparison Operations

  • Use Descriptive Addressing: When specifying the values or addresses for comparison, use descriptive names or labels that clearly indicate what each value represents. This makes the code more readable and easier to understand, especially for other programmers or maintenance personnel.
  • Validate Inputs: Before performing a comparison operation, ensure that the input values are valid and within the expected range. Invalid inputs can lead to unexpected results and potentially cause system failures.
  • Test and Debug: Always test your code thoroughly in a controlled environment before deploying it to a production system. Use simulation tools provided by Mitsubishi or other programming software to verify the functionality of your comparison operations and identify any potential issues.
  • Consider Edge Conditions: Pay attention to edge conditions, such as the minimum and maximum values of the data being compared. Make sure your code handles these cases correctly to avoid errors or unexpected behavior.

Conclusion

Comparison operations are a powerful and essential tool in Mitsubishi PLC programming. By understanding how to implement these operations effectively and following best practices, you can create robust and efficient automation systems that can make intelligent decisions based on real-time data.

B&R If you’re looking to incorporate Mitsubishi PLCs into your industrial automation projects or need further assistance with programming and using comparison operations, I’m here to help. As a trusted supplier of Mitsubishi PLCs, I have the expertise and resources to provide you with high-quality products and support. Contact me to discuss your specific requirements and explore how we can work together to achieve your automation goals.

References

  • Mitsubishi Electric Automation, Inc. Mitsubishi FX Series PLC Programming Manual.
  • Practical PLC Programming: A Step-by-Step Guide by Steven Cobb
  • Programmable Logic Controllers: Principles and Applications by David A. Bell

Yuntengbao Automation (Xiamen) Co., Ltd.

Address: Room 013, 4th Floor, No. 606-4, Xinglong Road, Huli District, Xiamen City, Fujian Province, China
E-mail: lrene@plcsupplychain.com
WebSite: https://www.plcsupplychain.com/