How to create and use different Comparator blocks in PLC ladder logic?

In this article, we will see different comparator blocks used in the Siemens TIA Portal. The comparator blocks

The Siemens TIA Portal Comparator blocks are:

  1. CMP (==)     –       Compare Equal
  2. CMP (<>)     –       Compare Not Equal
  3. CMP (>=)     –       Compare Greater than or Equal
  4. CMP (<=)     –       Compare Lesser than or Equal
  5. CMP (>)       –       Compare Greater than
  6. CMP (<)       –       Compare Lesser than
  7. IN RANGE   –        Value within Range
  8. OUT RANGE –      Value outside Range

Different Comparator Block of PLC Ladder Logic using in Siemens TIA Portal V16

1.CMP (==) – Compare Equal

How to create and use different Comparator blocks in PLC ladder logic? 1

2.CMP (<>) – Compare Not Equal

How to create and use different Comparator blocks in PLC ladder logic? 2

3.CMP (<>) – Compare Not Equal

How to create and use different Comparator blocks in PLC ladder logic? 3

4.CMP (<=) – Compare Lesser than or Equal

How to create and use different Comparator blocks in PLC ladder logic? 4

5.CMP (>) –  Compare Greater than

How to create and use different Comparator blocks in PLC ladder logic? 5

6.CMP (<) – Compare Lesser than

How to create and use different Comparator blocks in PLC ladder logic? 6

7.IN RANGE  – Value within Range

How to create and use different Comparator blocks in PLC ladder logic? 7

8.OUT RANGE  – Value outside Range

How to create and use different Comparator blocks in PLC ladder logic? 8

Declaration of Input and Output of different Comparator PLC block

COMPARE EQUAL
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_01Input%M0.0
2Count UP BlockUP Counter%DB1
3Output Load for Input SwitchOutput%Q0.0
4Comparator Equal BlockCompare%MW0
COMPARE NOT QUAL
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_02Input%M0.1
2Count UP BlockUP Counter%DB2
3Output Load for Input SwitchOutput%Q0.1
4Comparator Not Equal BlockCompare%MW1
COMPARE GREATER THAN OR EQUAL
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_03Input%M0.2
2Count UP BlockUP Counter%DB3
3Output Load for Input SwitchOutput%Q0.2
4Comparator Equal BlockCompare%MW2
COMPARE LESSER THAN OR EQUAL
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_04Input%M0.3
2Count UP BlockUP Counter%DB4
3Output Load for Input SwitchOutput%Q0.3
4Comparator Equal BlockCompare%MW3
COMPARE GREATER THAN
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_05Input%M0.4
2Count UP BlockUP Counter%DB5
3Output Load for Input SwitchOutput%Q0.4
4Comparator Equal BlockCompare%MW4
COMPARE LESSER THAN
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_06Input%M0.5
2Count UP BlockUP Counter%DB6
3Output Load for Input SwitchOutput%Q0.5
4Comparator Equal BlockCompare%MW5
COMPARE IN RANGE
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_07Input%M0.6
2Count UP BlockUP Counter%DB1
3Output Load for Input SwitchOutput%Q0.7
4Comparator Equal BlockCompare%MW6
COMPARE OUT RANGE
S. NoOperationInput/Output/OthersAddress of Each Block
1Input Switch_08Input%M0.7
2Count UP BlockUP Counter%DB1
3Output Load for Input SwitchOutput%Q1.0
4Comparator Equal BlockCompare%MW8

Different PLC Ladder Logic of Comparator Block Operations

Siemens TIA Portal V16 software is used to develop the PLC program. As stated above, the following Sections explain the various PLC comparator blocks.

COMPARATOR EQUAL

  1. The output %Q0.0 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator Equal; will be “Turned ON” only if the Register(Memory register) Value %MW0 is equal to the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.0.
  4. Once the Counter value reaches the preset Value. The counter will be “Turned ON”.  The comparator will be “Turned ON” once it reaches the specified value. This will“Turn ON” the output.

COMPARATOR NOT EQUAL

  1. The output %Q0.1 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. Until Comparator Not Equal; the output will be “Turned ON” only if the Register (Memory register) Value %MW1 is Not equal to the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.1.
  4. Once the Counter value reaches the preset Value. The counter will be “Turned ON”.  The comparator will be “Turned ON” once it reaches the specified value. This will“Turn OFF” the output.

COMPARATOR GREATER THAN OR EQUAL

  1. The output %Q0.2 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator Greater than or Equal; will be “Turned ON” only if the Register (Memory register) Value %MW2 is equal or greater than the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.2.
  4. Once the Counter value reaches the preset Value. The counter will be “Turned ON”.  The comparator will be “Turned ON” once it reaches the specified value. This will“Turn ON” the output.

COMPARATOR LESSER THAN OR EQUAL

  1. The output %Q0.3 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator Lesser than or Equal; will be “Turned ON” only if the Register (Memory register) Value %MW3 is equal or lesser than the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.3.
  4. Once the Counter value reaches the preset Value. The counter will be “Turned ON”.  The comparator will be “Turned ON” once it reaches the specified value i.e., greater than. This will“Turn OFF” the output.

COMPARATOR GREATER THAN

  1. The output %Q0.4 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator Greater than; will be “Turned ON” only if the Register (Memory register) Value %MW4 is greater than the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.4.
  4. Once the Counter value reaches the preset Value. The counter will be “Turned ON”.  The comparator will be “Turned ON” once it reaches the specified value. This will“Turn ON” the output.

COMPARATOR LESSER THAN

  1. The output %Q0.5 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator Lesser than or Equal; will be “Turned ON” only if the Register (Memory register) Value %MW5 is lesser than the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.5.
  4. Once the Counter value reaches the preset Value. The counter will be “Turned ON”.  The comparator will be “Turned ON” once it reaches the specified value i.e., greater than. This will“Turn OFF” the output.

COMPARATOR IN RANGE

  1. The output %Q0.7 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator In Range; will be “Turned ON” only if the Register (Memory register) Value %MW6 within the range of i.e. Min to Max value specified by the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.6.
  4. Once the Counter value reaches the preset range, the counter will be “Turned ON”.  The comparator will be “Turned OFF” once the counter value i.e., greater than the specified range.

COMPARATOR OUT RANGE

  1. The output %Q1.0 will be “Turned ON” if the comparator block connected to the output will be “Turned ON”.
  2. The Comparator Out Range; will be “Turned ON” only if the Register (Memory register) Value is %MW8 Out of the range of i.e., Min to Max value specified by the Counter value.
  3. The Counter will start counting the value with the application of input switch %M0.7.
  4. Once the Counter value reaches above the preset range, the counter will be “Turned ON”.  The comparator will be “Turned ON” once the counter value reaches the range that is out of specified range.

The steps for programming ladder logic on the SIEMENS TIA website are listed below. (Simulation).

How to use Siemens TIA Portal to create PLC Ladder Logic for three phase motor Forward and Reverse

Note: For a detailed explanation of how to use the Siemens TIA Portal to program ladder logic, please refer to the page mentioned above.

Simulation screenshots of different comparator blocks

 Below screenshots has been captured for various comparators block when we ran the program in simulation mode in our test laptop

COMPARATOR EQUAL

  1. The Simulation results show the working of the Comparator Equal Block.
  2. To understand the Comparator Equal operation Counter block is used.
  3. The Comparator has two preset values. One is variable another one is registry here %MW0. Once the register value is equal to the variable it “Turns ON” the output.
  4. The below diagram consists of Input switch_01 %M0.0, which is connected to Up Counter. The Up counter is set with some preset value (Based on our requirement). Current Value(CV) is enabled with register %MW0. The current value continuously increases from every pulse input of the Up counter.
How to create and use different Comparator blocks in PLC ladder logic? 9
  1. Once the registry value equals the preset value in the comparator equal block, the Output “Turns ON”.
How to create and use different Comparator blocks in PLC ladder logic? 10

COMPARATOR NOT EQUAL

  1. The Simulation results show the working of the Comparator is Not Equal Block.
  2. To understand the Comparator Not Equal Operation Counter block is used.
  3. The Comparator has two preset values. One is variable another one is registry here %MW1. Once the register value is equal to the variable it “Turns OFF” the output. Until the output is “Turned ON”.
  4. The below diagram consists of Input switch_02 %M0.1, which is connected to Up Counter. The Up counter is set with some preset value (Based on our requirement). Current Value (CV) is enabled with register %MW1. The current value continuously increases from every pulse input of the Up counter.
How to create and use different Comparator blocks in PLC ladder logic? 11
  1. Once the registry value equals the preset value in the comparator not equal block, the Output “Turns OFF”.
How to create and use different Comparator blocks in PLC ladder logic? 12

COMPARATOR GREATER THAN OR EQUAL

  1. The Simulation results show the working of the Comparator Greater than or Equal Block.
  2. To understand the Comparator Greater than or Equal Operation Counter block is used.
  3. The Comparator has two preset values. One is variable another one is registry here %MW2. Once the register value is equal or greater to the variable it “Turns ON” the output. Until the output is “Turned OFF”.
  4. The below diagram consists of Input switch_03 %M0.3, which is connected to Up Counter. The Up counter is set with some preset value (Based on our requirement). Current Value (CV) is enabled with register %MW2. The current value continuously increases from every pulse input of the Up counter.
How to create and use different Comparator blocks in PLC ladder logic? 13
  1. Once the registry value is equal to the preset value in the comparator equal block, the Output “Turns ON”.
How to create and use different Comparator blocks in PLC ladder logic? 14

COMPARATOR LESSER THAN OR EQUAL

  1. The Simulation results show the working of the Comparator Lesser than or Equal Block.
  2. To understand the Comparator Lesser than or Equal Operation Counter block is used.
  3. The Comparator has two preset values. One is variable another one is registry here %MW3. Once the register value is equal or lesser to the variable it “Turns OFF” the output. The “Turned ON” output.
  4. The below diagram consists of Input switch_04 %M0.4, which is connected to Up Counter. The Up counter is set with some preset value (Based on our requirement). Current Value (CV) is enabled with register %MW3. The current value continuously increases from every pulse input of the upcounter.
How to create and use different Comparator blocks in PLC ladder logic? 15
  1. Once the registry value equals or is greater than the preset value the comparator less than equal block, “Turns OFF” the Output
How to create and use different Comparator blocks in PLC ladder logic? 16

COMPARATOR GREATER THAN

  1. The Simulation results show the working of the Comparator Greater than block.
  2. To understand the Comparator Greater than Operation Counter block is used.
  3. The Comparator has two preset values. One is variable another one is registry here %MW4. Once the register value is greater than the variable it “Turns ON” the output. The “Turned OFF” output.
  4. The below diagram consists of Input switch_05 %M0.4, which is connected to Up Counter. The Up counter is set with some preset value (Based on our requirement). Current Value (CV) is enabled with register %MW4. The current value continuously increases from every pulse input of the Up counter
How to create and use different Comparator blocks in PLC ladder logic? 17
  1. Once the registry value is greater than the preset value the comparator greater block, “Turns ON” the Output.
How to create and use different Comparator blocks in PLC ladder logic? 18

COMPARATOR LESSER THAN

  1. The Simulation results show the working of the Comparator Lesser than Block.
  2. To understand the Comparator Lesser than the Operation Counter block is used.
  3. The Comparator has two preset values. One is variable another one is registry here %MW5. Once the register value is greater than the variable it “Turns OFF” the output. The “Turned ON” output.
  4. The below diagram consists of Input switch_05 %M0.5, which is connected to Up Counter. The Up counter is set with some preset value (Based on our requirement). Current Value (CV) is enabled with register %MW5. The current value continuously increases from every pulse input of the upcounter.
  5. Once the registry value is greater than the preset value the comparator lesser block, “Turns OFF” the Output.
How to create and use different Comparator blocks in PLC ladder logic? 19

COMPARATOR IN-RANGE

  1. The Simulation results show the working of the Comparator IN RANGE Block.
  2. To understand the Comparator IN-RANGE Operation Counter block is used.
  3. The IN-RANGE Block has three Variable Min, Max, and Val. When the block receives the value between the minimum to maximum set by the current value of Counter. The output is connected to the IN-RANGE block “TURNS ON” the output.
  4. The below diagram shows the output is “TURNS ON” when the IN-RANGE block receives the current value %MW6 between set by the Counter.
How to create and use different Comparator blocks in PLC ladder logic? 20
How to create and use different Comparator blocks in PLC ladder logic? 21
  1. The Upcounter is enabled by the “Tag_2” of the counter. Once the Upcounter reaches the Current Value (CV) %MW6. The IN-RANGE block “TURNED ON”.
  1. If the Current Value (CV) %MW6 goes above or out of range. The IN-RANGE block “TURNED OFF”.
How to create and use different Comparator blocks in PLC ladder logic? 22
How to create and use different Comparator blocks in PLC ladder logic? 23

COMPARATOR OUT-RANGE

  1. The Simulation results show the working of the Comparator OUT RANGE Block.
  2. To understand the Comparator OUT-RANGE Operation Counter block is used.
  3. The OUT-RANGE Block has three Variable Min, Max, and Val. When the block receives the value between the minimum to maximum set by the current value of Counter. The output is connected to the OUT-RANGE block “TURNS OFF” the output
  4. The below diagram shows the output is “TURNS OFF” when the OUT-RANGE block receives the current value %MW7 between set by the Counter.
How to create and use different Comparator blocks in PLC ladder logic? 24
  1. The Upcounter is enabled by the “Tag_1” of the counter. Once the Upcounter reaches the Current Value (CV) %MW7. The OUT-RANGE block “TURNED ON”.
How to create and use different Comparator blocks in PLC ladder logic? 25
  1. If the Current Value (CV) %MW7 goes above or below range. The OUT-RANGE block “TURNED ON”
How to create and use different Comparator blocks in PLC ladder logic? 26

It is possible for the reader to understand the Comparator-logic employed in a PLC by completing the tasks described above.

By following this detailed procedure and explanation, you can gain a comprehensive understanding of how to implement various comparator blocks in PLC ladder logic using Siemens TIA Portal V16. Our engineers tested and verified these logic operations through simulation in the TIA Portal software, ensuring the accuracy and functionality of each comparator block. This step-by-step guide provides valuable insights into the programming and simulation of PLC ladder logic for comparator operations, making it easier for you to apply these concepts in real-world industrial automation scenarios.

About The Author

Scroll to Top