CTUD_FUN

Up/down counter

This is a user-defined function from a system function block. CTUD_FUN (count up/down) allows you to program counting procedures (up and down).

Parameters

Input

CU (BOOL)

count up

the value 1 is added to the current CV for each rising edge detected at CU, except when Reset and/or Load is/are set.

CD (BOOL)

count down

the value 1 is subtracted from the current CV for each rising edge detected at CD, except when Reset and/or Load is/are set

if CU and CD are simultaneously set to TRUE no counting operation takes place.

Reset (BOOL)

Reset

CV is reset to zero for each rising edge at Reset and counting stops. The output QU/QD is set to FALSE.

The next falling edge at Reset restarts counting.

Load (BOOL)

if Load is set, PV is loaded to CV and QU is set to TRUE. This, however, does not apply if Reset is set simultaneously. In this case, Load will be ignored.

PV (INT)

Preset value

defines the preset value which is to be attained with the addition or subtraction

If no preset value is set or the preset value is zero, the output QU is set to TRUE immediately after counting starts.

Input/output

dutInstance(CTUD_FUN_INSTANCE_DUT)

Internal memory containing the internal values and states, which corresponds to the instance memory of the associated FB.

Output

QU (BOOL)

signal output - count up

is set to TRUE if CV is greater than/equal to PV

is set to FALSE if a rising edge is detected at Reset

QD (BOOL)

signal output - count down

is set to TRUE if CV = zero

is set to FALSE if a rising edge is detected at Reset

CV (INT)

Current value

  • is the addition/subtraction result

  • counting up:

    If CV reaches the preset value PV, the output QU is set to TRUE, but counting continues until the maximum limit 32767 is reached.

  • counting down:

    If CV reaches zero, the output QD is set to TRUE, but counting continues until the minimum limit -32768 is reached.

  • The value can be changed during counting operation by writing to the variable from the programming editor.

Time chart

Related topics:

Modified on: 2021-03-30Feedback on this pagePanasonic hotline