S7 Counter Instructions
S7 Counter Instructions
8. COUNTER INSTRUCTIONS
The counter instructions are the only functions that have access to the counter memory area.
Count Value
Bits 0 through 9 of the counter word contain the count value in binary code.
The count value is moved to the counter word when a counter is set. The range of the count value
is 0 to 999.
You can vary the count value within this range by using the following counter instructions:
• S_CU Up Counter
You provide a counter with a preset value by entering a number from 0 to 999, for example 127,
in the following format: C#127. The C# stands for binary coded decimal format (BCD format:
each set of four bits contains the binary code for one decimal value).
Bits 0 through 11 of the counter contain the count value in binary coded decimal format.
The following figure shows the contents of the counter after you have loaded the count value 127
and the contents of the counter cell after the counter has been set.
S_CU (Up Counter) is preset with the value at input PV if there is a positive edge at input S.
The counter is reset if there is a "1" at input R and the count value is then set to zero.
The counter is incremented by one if the signal state at input CU changes from "0" to "1" and the
value of the counter is less than "999".
If the counter is set and if RLO = 1 at the inputs CU, the counter will count accordingly in the
next scan cycle, even if there was no change from a positive to a negative edge or vice versa.
The signal state at output Q is "1" if the count is greater than zero and "0" if the
count is equal to zero.
If I0.2 changes from "0" to "1", the counter is preset with the value of MW10. If the signal state
of I0.0 changes from "0" to "1", the value of counter C10 will be incremented by one - unless the
value of C10 is equal to "999". Q4.0 is "1" if C10 is not equal to zero.
The counter is reset if there is a 1 at input R and the count value is then set to zero.
The counter is decremented by one if the signal state at input CD changes from "0" to "1" and the
value of the counter is greater than zero.
If the counter is set and if RLO = 1 at the inputs CD, the counter will count accordingly in the
next scan cycle, even if there was no change from a positive to a negative edge or vice versa.
The signal state at output Q is "1" if the count is greater than zero and "0" if the count is equal to
zero.
If I0.2 changes from "0" to "1", the counter is preset with the value of MW10. If the signal state
of I0.0 changes from "0" to "1", the value of counter C10 will be decremented by one - unless the
value of C10 is equal to "0". Q4.0 is "1" if C10 is not equal to zero.
S_CUD (Up-Down Counter) is preset with the value at input PV if there is a positive edge at
input S. If there is a 1 at input R, the counter is reset and the count is set to zero. The counter is
incremented by one if the signal state at input CU changes from "0" to "1" and the value of the
counter is less than "999". The counter is decremented by one if there is a positive edge at input
CD and the value of the counter is greater than "0".
If there is a positive edge at both count inputs, both instructions are executed and the count value
remains unchanged.
If the counter is set and if RLO = 1 at the inputs CU/CD, the counter will count accordingly in
the next scan cycle, even if there was no change from a positive to a negative edge or vice versa.
The signal state at output Q is "1" if the count is greater than zero and "0" if the count is equal to
zero.
Example:
If I0.3 changes from "0" to "1", the counter is preset with the value of 20.
If the signal state of I0.4 changes from "0" to "1", the value of counter C10 will be incremented
by one - except when the value of C10 is equal than "999".
If I0.5 changes from "0" to "1", C10 is decremented by one - except when the value of C10 is
equal to "0". Q8.3 is "1" if C10 is not equal to zero.
Description
--- (SC) (Set Counter Value) executes only if there is a positive edge in RLO. At that time, the
preset value transferred into the specified counter.
The counter C5 is preset with the value of 100 if there is a positive edge at input I0.0 (change
from "0" to "1"). If there is no positive edge, the value of counter C5 remains unchanged.
--- (CU) (Up Counter Coil) increments the value of the specified counter by one if there is a
positive edge in the RLO and the value of the counter is less than "999". If there is no positive
edge in the RLO or the counter already has the value "999", the value of the counter will be
unchanged.
If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the preset value
of 100 is loaded to counter C10.
If the signal state of input I0.1 changes from "0" to "1" (positive edge in RLO), counter C10
count value will be incremented by one unless the value of C10 is equal to "999". If there is no
positive edge in RLO, the value of C10 will be unchanged. If the signal state of I0.2 is "1", the
counter C10 is reset to "0".
Description
--- (CD) (Down Counter Coil) decrements the value of the specified counter by one, if there is a
positive edge in the RLO state and the value of the counter is more than "0". If there is no
positive edge in the RLO or the counter has already the value "0", the value of the counter will be
unchanged.
If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the preset value
of 100 is loaded to counter C10.
If the signal state of input I0.1 changes from "0" to "1" (positive edge in RLO), counter C10
count value will be decremented by one unless the value of C10 is equal to "0". If there is no
positive edge in RLO, the value of C10 will be unchanged.
If the count value = 0, then Q4.0 is turned on.
If the signal state of input I0.2 is "1", the counter C10 is reset to "0".
Comments:
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-------------------------------- -------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
--------------------- ------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
---------- -----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
--------------------------------