9 Function modules
50
9.1 Software up/down counter
The counter provides the following functions:
• Counting up
• Counting down
• Reset the counter to 0
• Set an upper counter value
• Query in case the upper counter value is exceeded
• Query of counter status 0
• Query counter value
The counter counts the positive edges at the inputs CU (counting upwards) and CD (counting down-
wards).
Call
CTUD<instance> (CU, CD, R, LD, PV);
Inputs
The parameters R, LD, CU and CD are sorted in descending order in the table according to their priority.
Outputs
Comment
To set the upper counter value with LD, R must not be TRUE.
The values of the inputs/outputs are not retained when the power is turned off.
Examples
CTUD01 (IN, FALSE, FALSE, FALSE, 100);
(* count positive edges of IN upwards *)
CTUD01 (FALSE, IN, FALSE, FALSE, 100);
(* count positive edges of IN downwards *)
CTUD01 (IN, FALSE, TRUE, FALSE, 100);
(* set counter status to 0 *)
CTUD01 (IN, FALSE, FALSE, TRUE, 100);
(* set upper counter value: 100 *)
Parameter Data type Description
<Instance> 01 to xx (specify instance with two digits)
R BOOL TRUE = set counter status to 0
LD BOOL TRUE = set upper counter value
CU BOOL Positive edge = count up
CD BOOL Positive edge = count down
PV UINT Upper counter value
Parameter Data type Query; (* description *)
CV UINT OUT := CTUD<instance>.CV;
(* OUT = counter status *)
QU BOOL OUT := CTUD<instance>.QU;
(* OUT = TRUE, if counter status > upper counter value *)
QD BOOL OUT := CTUD<instance>.QD;
(* OUT = TRUE, if counter status <= 0 *)