CTD

CTD 1:

Decrementer

VAR_INPUT

VAR_INPUT
    CD      : BOOL; (* Count Down on rising edge *)
    LOAD    : BOOL; (* Load Start Value *)
    PV      : WORD; (* Start Value *)
END_VAR

VAR_OUTPUT

VAR_OUTPUT
    Q       : BOOL; (* Counter reached 0 *)
    CV      : WORD; (* Current Counter Value *)
END_VAR

When LOAD is TRUE, the counter variable CV will be initialized with the upper limit PV. If CD has a rising edge from FALSE to TRUE, CV will be lowered by 1 provided CV is greater than 0 (i.e., it doesn't cause the value to fall below 0).Q returns TRUE when CV is less than or equal to 0.

Requirements

Development environment

Target system type

PLC libraries to include

TwinCAT Version >= 2.6.0

PC or CX (x86)

Standard.Lib

TwinCAT Version >= 2.6.0

BC (165)

Standard.Lb6

TwinCAT Version >= 2.9.0

BCxx50 or BX

Standard.lbx

TwinCAT Version >= 2.10.0 Build >= 1301

CX (ARM)

Standard.lib