9 Function modules
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.
Parameter
<Instance>
R
LD
CU
CD
PV
Outputs
Parameter
CV
QU
QD
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 *)
50
Data type
Description
01 to xx (specify instance with two digits)
BOOL
TRUE = set counter status to 0
BOOL
TRUE = set upper counter value
BOOL
Positive edge = count up
BOOL
Positive edge = count down
UINT
Upper counter value
Data type
Query; (* description *)
UINT
OUT := CTUD<instance>.CV;
(* OUT = counter status *)
BOOL
OUT := CTUD<instance>.QU;
(* OUT = TRUE, if counter status > upper counter value *)
BOOL
OUT := CTUD<instance>.QD;
(* OUT = TRUE, if counter status <= 0 *)