Skip to main content

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

InstructionSymbolPurpose
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

MemberTypeMeaning
.PREDINTPreset — target count
.ACCDINTAccumulated count so far
.CUBOOLCount-up enable — 1 while a CTU rung is true
.CDBOOLCount-down enable — 1 while a CTD rung is true
.DNBOOLDone — 1 when .ACC is greater than or equal to .PRE
.OVBOOLOverflow — 1 when .ACC wraps past the positive maximum
.UNBOOLUnderflow — 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.