1. Up and down counter CTUD

1. Up and down counter CTUD

1.1. Instruction Description

Each time the input energy flow transitions from closed to open, the counter (CTUD) instruction determines the size of the current value compared to the set value. When the current value (CVxxx) is greater than (less than) the preset value (SV), the counter counts downwards (upwards). When the current value (CVxxx) is equal to the preset value (SV), the counter (Cxxx) is set to 1 and the current value (CVxxx) does not act. Performing a reset operation can reset the counter, that is, setting the counter bit (Cxxx) to 0 and resetting the preset value (SV).

Counter range: CVxxx=CV0 to CV255; Cxxx=C0 to C255.

Counter Type Counter Bit Number Maximum Value Counter Number
CTUD 16 bits 32767 C0-C199
CTUD 32-bit 2147483647 C200 – C234
CTUD 32-bit (high-speed) 2147483647 C235-C255

Note: Since each counter has a current value, do not set the same counter number to more than one counter (up and down counters with the same number access the same current value)

1.2. The valid operands of the instruction

Input/Output Data Type operand Description
CV 16 bit integer CV Counter
SV 16 bit integer D/CV/TV/AI/AO/K/H/V/Z/FD, bit composite word (X/Y/M/C/T/S), local variable (LW) preset value

1.3. Example

Command table:

NETWORK 000

LD X000

CTUD CV0 D0 // The counter determines the size relationship between CV0 and D0, and counts up and down from the current value CV0, with a set value (SV) of D0

NETWORK 001

LD C0

OUT Y000

CTUD

图1 CTUD