Up/down counter
This is a user-defined function from a system function block. CTUD_FUN (count up/down) allows you to program counting procedures (up and down).
Count up (CU set to TRUE)
Counting up starts at zero until the maximum value 32767 is reached. Each rising edge at count up CU increases the value at current value CV by 1.
Count down (CD set to TRUE)
Counting down starts at zero until the minimum value -32768 is reached. Each rising edge at count down CD decreases the value at current value CV by 1.
Input
count up
the value 1 is added to the current CV for each rising edge detected at CU, except when Reset and/or Load is/are set.
count down
the value 1 is subtracted from the current CV for each rising edge detected at CD, except when Reset and/or Load is/are set
if CU and CD are simultaneously set to TRUE no counting operation takes place.
Reset
CV is reset to zero for each rising edge at Reset and counting stops. The output QU/QD is set to FALSE.
The next falling edge at Reset restarts counting.
if Load is set, PV is loaded to CV and QU is set to TRUE. This, however, does not apply if Reset is set simultaneously. In this case, Load will be ignored.
Preset value
defines the preset value which is to be attained with the addition or subtraction
If no preset value is set or the preset value is zero, the output QU is set to TRUE immediately after counting starts.
Input/output
Internal memory containing the internal values and states, which corresponds to the instance memory of the associated FB.
Output
signal output - count up
is set to TRUE if CV is greater than/equal to PV
is set to FALSE if a rising edge is detected at Reset
signal output - count down
is set to TRUE if CV = zero
is set to FALSE if a rising edge is detected at Reset
Current value
is the addition/subtraction result
counting up:
If CV reaches the preset value PV, the output QU is set to TRUE, but counting continues until the maximum limit 32767 is reached.
counting down:
If CV reaches zero, the output QD is set to TRUE, but counting continues until the minimum limit -32768 is reached.
The value can be changed during counting operation by writing to the variable from the programming editor.