Skip to main content

SF_CTUD (FB)

Description of the function block

Tip

The version of the function block as described here corresponds to the latest version of the function block in Version list of function blocks.

Tip

SF_CTUD is a counter FB from the SafetyStandard library. It is an extension of CTUD, a standard IEC 61131-3 function block. The SF_CTUD function block contains both standard data types and safety-related data types (prefix: SAFE).

SF_CTUD fulfills the function of an up and down counter.

Figure 112. Function block: SF_CTUD
Function block: SF_CTUD


Table 89. VAR_INPUT

Name

Data Type

Initial Value

Description, parameter values

CU

BOOL

FALSE

Rising edge at CU increments CV by 1.

CD

BOOL

FALSE

Rising edge at CD decrements CV by 1.

RESET

BOOL

FALSE

TRUE: Resets the CV counter to 0.

FALSE: Counting up is enabled.

LOAD

BOOL

FALSE

TRUE: Sets CV to the initial value PV

FALSE: Counting down is enabled.

PV

SAFEINT

0

Start value (count down) /or upper limit for incrementing CV



Table 90. VAR_OUTPUT

Name

Data Type

Initial Value

Description, parameter values

QU

SAFEBOOL

FALSE

TRUE: Counter CV has reached the upper limit.

QD

SAFEBOOL

FALSE

TRUE : Counter CV has reached 0.

CV

SAFEINT

0

Current counter value of the counter CV.



FB code

IF R THEN CV := 0 ;
ESLIF LOAD THEN CV := PV ;
ELSE
            IF NOT (CU AND CD) THEN
                            IF CU AND (CV < PVmax)
                            THEN CV := CV+1;
                            ELSIF CD AND (CV > PVmin)
                            THEN CV := CV-1;
                            END_IF;
            ENDIF;
ENDIF;
QU := (CV >= PV) ;
QD := (CV <= 0);

The numerical value of PVmin is 0. The numerical value of PVmax is 32767.