Siemens PLC Counters and Comparators Programming


Siemens PLC Counters and Comparators Logic

Understand and use of Siemens PLC counters and comparators Programming on PLC to control a work system and solve problems to make a control algorithm to control a system as we want.


  1. Siemens S7 300 PLC



Three types of counters commonly used:
• Up Counter
• Down Counter
• Up Down Counter
Counter is a simple function to calculate, for Up Counter counting forward 1,2,3 …

For Down Counter counts down 9,8,7, … and there is also called Up Down Counter whose function is counting forward and backward, for example 1,2,3,4,5,4,3,2, …

While the Comparator functions as an input comparison in the form of WORD, the types are as follows:

  • Equal
  • Not Equal
  • Greater Than
  • Less Than

For Equal, then if the input value is compared then the output will be active or worth 1. While Not Equal is the opposite of Equal, if the input value is compared then the output will be active or worth
1.For Greater than it must be given a standard value, if the input value exceeds the standard value then it is fulfilled and the output will be active.

For Less than the opposite of Greater than, a standard value is also given, if the input value exceeds the standard value then the output will be fulfilled


The steps to make an Up Counter are as follows:

  1. Just like a timer, the function counter can be taken from the left side layoutScreenshot_1

  2. For example, we use the S_CU Up Counter
    Double click it will appearScreenshot_2

  3. Fill it with C0Screenshot_3

  4. Add Input and OutputScreenshot_4

  5. Simulated I0.0 is ONScreenshot_5

  6. The CV_BCD looks worth 1, and Q4.0 will be active if the count is> 0
    I0.0 is off and then on again, the counter will be 2Screenshot_6

  7. To move counts to PLC variables, use MW (memory word)
    For this example, use MW10Screenshot_7

  8. The count value in MW10 can be used for other processes, for example as a count of the number of products that pass, interlocking, etc.
    For a counter use case example, what will be exemplified is: if after 5 counts the output Q4.1 will be activeScreenshot_8

  9. Select the function to compare, in this case using GE_I (Greater Equal Integer) or in another sense>> for values ​​of type integerScreenshot_9

  10. Output Q4.1 will be on if the number of calculations (MW10) is more than or equal to the setpoint, namely 5Screenshot_10

  11. To reset the counter, add input to the counter functionScreenshot_11Screenshot_12

  12. When the counter is reset, MW10 returns to 0 and output Q4.1 is off

Down Counter is also the same way with Up Counter, so just change to the Down Counter icon.


After analysis, it can be concluded as follows:

Counter (counter) has 3 basic functions that are often used, namely Counter Up (counting up), Counter Down (counting down), Counter Up Down (counting up and down). These basic functions are often used in industrial plants, for example to calculate the movement of each machine, calculate production for 1 shift etc.

Comparator has 4 functions, namely Comparator Equal (comparator of the same value), Comparator Not Equal, Comparator Greater Than (Comparator Greater Than (greater value comparison), Comparator Less Than (comparison of smaller values). These basic functions are also often used in industrial plants, for example to limit the amount of production, limit the number of actuator movements etc.

Counter and Comparator are often combined in a program’s algorithm, for example in limiting movement, first the input enters the counter to calculate its motion then the output goes into the comparator and compared to the standard set, if the standard exceeds the engine will die.