Description
You can use the "Assign parameters and count down" instruction to decrement the value of a counter. 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. The count is decremented until the low limit of "0" is reached. When the low limit is reached, the counter value is no longer decremented on a positive signal edge.
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 at input CD is "1", the counter will count accordingly in the next scan cycle, even when no change has been detected in the signal edge.
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 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 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 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. |
|
CD |
Input |
BOOL |
I, Q, M, D, L 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:
When the signal state at the "TagIn_1" input changes from "0" to "1" (positive signal edge) and the current counter value is greater than "0", the counter value is decremented by one. When the signal state at the "TagIn_2" 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_3" 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".