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
Edit .PRE in the tag editor for the counter's tag.