Description
You can use the "Count up" instruction to increment the value at output CV. When the signal state at the CU input changes from "0" to "1" (positive signal edge), the instruction is executed and the current counter value at the CV output is incremented by one. The counter value is incremented each time a positive signal edge is detected, until it reaches the high limit for the data type specified at the output CV. When the high limit is reached, the signal state at the CU input no longer has an effect on the instruction.
You can query the counter status in the Q output. The signal state at the Q output is determined by the PV parameter. If the current counter value is greater than or equal to the value of the PV parameter, the Q output is set to signal state "1". In all other cases, the Q output has signal state "0". You can also specify a constant for the PV parameter.
The value at the CV output is reset to "0" and saved to an edge memory bit when the signal state at input R changes to "1". As long as the R input has signal state "1", the signal state at the CU input has no effect on the instruction.
|
Note Only use a counter at a single point in the program to avoid the risk of counting errors. |
Each call of the "Count up" instruction must be assigned an IEC counter in which the instruction data is stored. An IEC counter is a structure with one of the following data types:
For S7-1200 CPU
|
Data block of system data type IEC_<Counter> (Shared DB) |
Local tag |
|---|---|
|
|
For S7-1500 CPU
|
Data block of system data type IEC_<Counter> (Shared DB) |
Local tag |
|---|---|
|
|
You can declare an IEC counter as follows:
-
Declaration of a data block of system data type IEC_<Counter> (for example, "MyIEC_COUNTER")
-
Declaration as a local tag of the type CTU_<Data type> or IEC_<Counter> in the "Static" section of a block (for example #MyIEC_COUNTER)
When you set up the IEC counter in a separate data block (single instance), the instance data block is created by default with "optimized block access" and the individual tags are defined as retentive. For additional information on setting retentivity in an instance data block, refer to "See also".
When you set up the IEC counter as local tag (multi-instance) in a function block with "optimized block access", it is defined as retentive in the block interface.
The execution of the "Count up" instruction requires a preceding logic operation. It can be placed within or at the end of the network.
Parameters
The following table shows the parameters of the "Count up" instruction:
|
Parameter |
Declaration |
Data type |
Memory area |
Description |
|
|---|---|---|---|---|---|
|
S7-1200 |
S7-1500 |
||||
|
CU |
Input |
BOOL |
I, Q, M, D, L or constant |
I, Q, M, D, L or constant |
Count input |
|
R |
Input |
BOOL |
I, Q, M, D, L, P or constant |
I, Q, M, T, C, D, L, P or constant |
Reset input |
|
PV |
Input |
Integers |
I, Q, M, D, L, P or constant |
I, Q, M, D, L, P or constant |
Value at which the output Q is set. |
|
Q |
Output |
BOOL |
I, Q, M, D, L |
I, Q, M, D, L |
Counter status |
|
CV |
Output |
Integers, CHAR, WCHAR, DATE |
I, Q, M, D, L, P |
I, Q, M, D, L, P |
Current counter value |
You can select the data type of the instruction from the "???" drop-down list of the instruction box.
Example
The following example shows how the instruction works:
When the signal state of the "TagIn_1" operand changes from "0" to "1", the "Count up" instruction is executed and the current counter value of the "Tag_CV" operand is incremented by one. With each additional positive signal edge, the counter value is incremented until the high limit of the specified data type (INT = 32767) is reached.
The value of the PV parameter is adopted as the limit for determining the "TagOut" output. The "TagOut" output has signal state "1" as long as the current counter value is greater than or equal to the value of the "Tag_PV" operand. In all other cases, the "TagOut" output returns the signal state "0".