Attention
IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.
CTUD¶
Count up/down counter. Increments CV on rising edges of CU and
decrements CV on rising edges of CD. Provides both an upper-limit
output QU and a lower-limit output QD.
IEC 61131-3 |
Section 2.5.2.3.3 |
Support |
Supported |
Inputs¶
Name |
Type |
Description |
|---|---|---|
|
|
Count-up input (increments on rising edge) |
|
|
Count-down input (decrements on rising edge) |
|
|
Reset input (sets CV to 0) |
|
|
Load input (loads PV into CV) |
|
|
Preset value |
Outputs¶
Name |
Type |
Description |
|---|---|---|
|
|
Upper-limit output (TRUE when CV >= PV) |
|
|
Lower-limit output (TRUE when CV <= 0) |
|
|
Current counter value |
Behavior¶
On each rising edge of CU, the counter value CV is incremented by one.
On each rising edge of CD, CV is decremented by one. When R is
TRUE, CV is reset to zero. When LD is TRUE, the preset value
PV is loaded into CV. The output QU is TRUE when CV is
greater than or equal to PV. The output QD is TRUE when CV is
less than or equal to zero.
Typed variants CTUD_DINT, CTUD_LINT, CTUD_UDINT, and CTUD_ULINT
use the corresponding integer type for PV and CV.
Example¶
This example counts up with CU held TRUE. After the first scan,
CV is 1 which reaches PV, so at_max is TRUE.