7.2.6 CTUD_INT
Function
CTDU_INT 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 | INT | Preset value |
| QU | Var_Output | BOOL | Add counter status |
| QD | Var_Output | BOOL | Status of the down counter |
| CV | Var_Output | INT | The value of the current count |
Corresponding syntax
- Counting range: -32768~32767
- Whenever CU changes from FALSE to TRUE, CV increases by 1, and whenever CD changes from FALSE to TRUE, CV decreases by 1;
- When CV is greater than or equal to PV, QU outputs TRUE; when CV is less than PV, QU outputs FALSE;
- When CV is less than or equal to 0, QD outputs TRUE; when CV is greater than 0, QD outputs FALSE;
- The upper and lower limits of CV depend on the maximum and minimum values of the positive type specified by the counter (-32768~32767)
- At any time, as long as R is TRUE, the QU output is FALSE, and CV immediately stops counting and returns to 0;
- At any time, as long as LD is TRUE, QD outputs FALSE, and CV immediately stops counting and returns to the PV value
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_INT_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;