Description
You can use the "Assign parameters and count up / down" instruction to increment or decrement the value of a counter. If the signal state at the CU input changes from "0" to "1" (positive signal edge), the current counter value is incremented by one. If the signal state at the CD input changes from "0" to "1" (positive signal edge), the counter value is decremented by one. The current counter value is output as a hexadecimal value at output CV and BCD-coded at output CV_BCD. If there is a positive signal edge at the CU and CD inputs in one program cycle, the counter value remains unchanged.
The counter value is incremented until the high limit of "999" is reached. When the high limit value is reached, the counter value is no longer incremented on a positive signal edge. When the low limit of "0" is reached, the counter value is no longer decremented.
When the signal state at input S changes from "0" to "1", the counter value is set to the value of the PV parameter. If the counter is set and if RLO is "1" at the inputs CU and CD, the counter counts accordingly in the next scan cycle, even if no change in the signal edge is detected.
The counter value is set to zero when the signal state at the R input changes to "1". As long as the R input has the signal state "1", processing of the signal state of the CU, CD and S inputs has no effect on the counter value.
The signal state at output Q is "1" if the counter value is greater than zero. If the counter value is equal to zero, output Q has the signal state "0".
|
Note Only use a counter at a single point in the program to avoid the risk of counting errors. |
The "Assign parameters and count up / down" instruction needs a preceding logic operation for the edge evaluation and can be placed within or at the end of the network.
Parameters
The following table shows the parameters of the "Assign parameters and count up / down" instruction:
|
Parameters |
Declaration |
Data type |
Memory area |
Description |
|---|---|---|---|---|
|
<counter> |
InOut/Input |
COUNTER |
C |
Counter of the instruction The number of counters depends on the CPU. |
|
CU |
Input |
BOOL |
I, Q, M, D, L, T, C or constant |
Count up input |
|
CD |
Input |
BOOL |
I, Q, M, D, L, T, C or constant |
Count down input |
|
S |
Input |
BOOL |
I, Q, M, D, L, T, C or constant |
Input for presetting counter |
|
PV |
Input |
WORD |
I, Q, M, D, L or constant |
Preset counter value (C#0 to C#999) |
|
R |
Input |
BOOL |
I, Q, M, D, L, T, C or constant |
Reset input |
|
CV |
Output |
WORD, S5TIME, DATE |
I, Q, M, D, L |
Current counter value (hexadecimal) |
|
CV_BCD |
Output |
WORD, S5TIME, DATE |
I, Q, M, D, L |
Current counter value (BCD format) |
|
Q |
Output |
BOOL |
I, Q, M, D, L |
Status of the counter |
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
If the signal state at the input "TagIn_1" or at the input "TagIn_2" changes from "0" to "1" (positive edge), the instruction "Assign parameters and count up / down is executed. When there is a positive signal edge at the "TagIn_1" input and the current counter value is less than "999", the counter value is incremented by one. When there is a positive signal edge at the "TagIn_2" input and the current counter value is greater than "0", the counter value is decremented by one.
When the signal state at the "TagIn_3" input changes from "0" to "1", the counter value is set to the value of the "TagPresetValue" operand. The counter value is reset to "0" when the "TagIn_4" operand has signal state "1".
The current counter value is hexadecimal in the "TagValue_1" operand and BCD-coded in the "TagValue_2" operand.
The "TagOut" output has the signal state "1" as long as the current counter value is not equal to "0".