7.2.5 CTUD_DINT
Function
CTDU_DINT is called an up-down counter, used to accumulate the number of input pulses (0->1 or 1->0) at the input end.
LD graphics
Parameter description
| Interface variables | Declaration | Data type | Description |
|---|---|---|---|
| CU | Var_Input | BOOL | Up-count signal input terminal |
| CD | Var_Input | BOOL | Countdown signal input terminal |
| R | Var_Input | BOOL | Reset input, CV clear |
| LD | Var_Input | BOOL | Load preset value, set CV to PV |
| PV | Var_Input | DINT | Preset value |
| QU | Var_Output | BOOL | Add counter status |
| QD | Var_Output | BOOL | Status of the down counter |
| CV | Var_Output | DINT | The value of the current count |
Corresponding syntax
- Counting range: -2147483648~2147483647
- The rest of the syntax refers to CTUD_INT
- Function block example:
warning
Function block usage requires global declaration of an instance
Example
-
LD example is shown in the following animation:

-
ST example is shown in the following code:
CTUD_DINT_1(
CU:=UP,
CD:=DOWN,
R:=RESET,
LD:=LOAD,
PV:=1,
QU=>OUT,
QD=>OUT2,
CV=>cVar
);
IF OUT THEN
IVar:=iVar+1;
ELSE
iVar:=0;
END_IF;
IF OUT2 THEN
iVar2:=iVar2+1;
else
iVar2:=0;
END_IF;