Skip to main content

7.2.4 CTD_INT

Function

CTD_INT is called a down counter, used to accumulate the number of input pulses (0->1 or 1->0) at the input end.

LD graphics

Alt ​​text

Parameter description

Interface variablesDeclarationData typeDescription
CDVar_InputBOOLDown counter input
PVVar_InputINTPreset value
LDVar_InputBOOLLoad preset value, set CV to PV
QVar_OutputBOOLCounter status, output bit
CVVar_OutputINTThe value of the current count

Corresponding syntax

  • Counting range: -32768~32767
  • CD changes from FALSE to TRUE, CV decreases by 1;
  • When CV is equal to 0, Q outputs TRUE. After that, whenever CD changes from FALSE to TRUE, Q keeps outputting TRUE, and CD continues to decrease by 1 until it reaches the minimum value of the integer type specified by the counter.
  • At any time, as long as LD is TRUE, Q 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: alt text

  • ST example is shown in the following code:

CTD_INT_1(
CD:=DOWN,
LD:=LOAD,
PV:=1,
Q=>OUT,
CV=>cVar
);
IF OUT THEN
iVar:=1;
ELSE
iVar:=0;
END_IF;