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

The preset is stored on the counter tag, not inside the instruction. There are two ways to set it:

  • From the rung: click the Preset row on the CTU or CTD block and type the target count. This edits the .PRE default of the underlying COUNTER tag in place — no need to leave the ladder editor.
  • From the Tag editor: expand the counter tag's row and edit the Default Value of .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.