You are here: Core Reference > Coding > Logic > CTD

CTD

Function Block Name

CTD

Description

CTD is a down counter function block and it is typically used to indicate when a count has decreased to a minimum value.

Arguments

CD {BOOL}

Determines when the counter decreases. The counter will go down by 1 when the CD input changes from False to True. The counter does not change again until the CD input changes from True to False and then back to True. The counter is only affected by the CD input changing from False to True.

If the counter reaches the number specified by the PV input, the counter will no longer decrease, even if the CD input continues to change from False to True.

LD {BOOL}

Indicates whether there is a Load. If the LD value is True, the CV output is set to the preset value (PV) irrespective of the count; if the LD value is False, the CV output has a value that corresponds to the number of times the CD value has changed.

PV {INT}

This is an integer input that defines the starting number for the counter.

Returns

Q {BOOL}

The Q output defines whether the count is active or inactive. If the CV output is greater than 0, the Q output is False and the counting is active; if the CV output reaches 0, the Q output is True and the counting stops.

CV {INT}

The CV output is the value of the counter. It decreases by 1 each time the CD input changes from False to True.

The CV output begins as the same number as the PV input. It can decrease until it reaches 0, at which point the Q output becomes True and the counting stops.

Example - CTD Function Block Diagram:

In this Function Block Diagram, the LD output begins as True, and so the CV output is set to be the same as the PV input of 10. The LD output then becomes False and so the counting begins (as the CV output can now be affected by the CD input). The CD input changes from True to False and then back to True again. This causes the CV output to decrease by 1 as the CD input has changed from False to True once. The Q output remains as False as the CV output is above 0. The Q output will only change to True when the CD input has changed from False to True a further 9 times (reducing the CV output to 0). When the Q output changes to True, the counting stops.

Example - CTD ST Program:

The syntax for entering a CTD function block in an ST program is:

  • VAR
    • CD_IN AT %M(.Digital Point1): BOOL;
    • LD_IN AT %M(.Digital Point2): BOOL;
  • END_VAR
  • VAR
    • PV_IN: INT;
    • Q_OUT: BOOL;
    • CV_OUT: INT;
    • FB : CTD;
  • END_VAR
  • FB( CD := CD_IN, LD := LD_IN, PV := PV_IN, Q => Q_OUT, CV => CV_OUT );

The direct variables are declared in a separate VAR block to the internal variables. The input and output variables for the CTD function block are also allocated names that are different to the names of the inputs and outputs in the function block as this makes it easier to understand the ST program (for example, the CD input variable is named CD_IN). In this example, the direct variables for the CD and LD inputs (CD_IN and LD_IN) reference digital points (the Boolean values for these inputs are taken from digital points in the database).

In the second VAR block, the internal variables are declared, including an FB variable that defines the type of function block.

The ST Program can then reference the variables as inputs and outputs for the function block:

  • FB( CD := CD_IN, LD := LD_IN, PV := PV_IN, Q => Q_OUT, CV => CV_OUT );

So, the ST Program uses the CD_IN input as the CD input for the FB function block (which has already been declared as a CTD type). For the LD input, it uses the LD_IN variable, and for the PV input it uses the PV_IN variable. For its outputs, it uses the Q_OUT variable for the Q output and the CV_OUT variable for the CV output.


ClearSCADA 2015 R2