Counters
Counters track discrete events. A counter instruction references a COUNTER tag, which is a structure with a preset, an accumulator, and status bits.
Available Counter Instructions
| Instruction | Symbol | Purpose |
|---|---|---|
| CTU | CTU Counter counter (CU) Preset ? (DN) Accum ? | Increments .ACC by 1 on each rising edge of the rung. Sets .DN when .ACC reaches .PRE; keeps counting past the preset. |
| CTD | CTD Counter counter (CD) Preset ? (DN) Accum ? | Decrements .ACC by 1 on each rising edge of the rung. Typically paired with CTU on the same COUNTER tag. |
COUNTER Tag Members
| Member | Type | Meaning |
|---|---|---|
.PRE | DINT | Preset — target count |
.ACC | DINT | Accumulated count so far |
.CU | BOOL | Count-up enable — 1 while a CTU rung is true |
.CD | BOOL | Count-down enable — 1 while a CTD rung is true |
.DN | BOOL | Done — 1 when .ACC is greater than or equal to .PRE |
.OV | BOOL | Overflow — 1 when .ACC wraps past the positive maximum |
.UN | BOOL | Underflow — 1 when .ACC wraps past the negative minimum |
Reference members as contacts:
XIC(PartsCount.DN)OTE(FullBin)
Rising-Edge Only
Counters increment (or decrement) once per rising edge of the rung. They do not count every scan while the rung is true. No ONS needed — the counter already detects the edge internally.
Resetting a Counter
A counter is retentive — .ACC survives rung transitions. Use a RES instruction to clear it:
XIC(ResetBtn)RES(PartsCount)
Setting the Preset
The preset is stored on the counter tag, not inside the instruction. There are two ways to set it:
- From the rung: click the
Presetrow on theCTUorCTDblock and type the target count. This edits the.PREdefault of the underlyingCOUNTERtag in place — no need to leave the ladder editor. - From the Tag editor: expand the counter tag's row and edit the
Default Valueof.PRE.
The Accum row on the block is editable the same way and sets the .ACC default, which is mainly useful for tests that start mid-count.