Configuring CNT Counters with K and D Preset Values

Stefan Weidner5 min read
Other ManufacturerPLC HardwareTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

The CNT counter instruction follows a short data path: the rung supplies count events, the preset operand supplies the target, and the counter state changes when its current value reaches that target. K and D select different sources for the preset; they are not two pulse inputs.

What data path does the counter use?

Follow the count event from the physical input before examining the preset. An input module converts the field signal into a PLC input state. The logic carrying that state reaches CNT, which updates the current count and compares it with the preset. The preset comes either directly from the instruction or from a data register.

Stage Object Function Commissioning check
Physical layer Sensor, switch, or pulse source Produces the count signal Observe the electrical input and input-module indication
Input image and logic Counter rung condition Presents count events to CNT Monitor the rung and confirm one intended transition per event
Preset source K100 or D100 Supplies the target value Monitor the resolved preset online
Counter state C0 Stores the current value and completion state Watch the current value advance toward the target

No network hop is required when logic inside the PLC supplies D100. If an HMI or another controller writes the register, the path extends through that device's driver and PLC communication interface. Obtain the protocol address and port from the actual project because neither is defined by the counter instruction. Proceed only after the online current value changes once for each intended event.

How do I prove that the pulse reaches the counter?

Layer one first. A preset change cannot repair a missing, noisy, or continuously true input. Monitor the physical input, the PLC input point, the rung condition, and the current count in that order. The transition must reach the instruction while the program section containing CNT is executing.

  1. Operate the field device once and confirm that the input point changes state.
  2. Monitor the logic between that input and CNT. Check interlocks, mode conditions, and program branches that can block the event.
  3. Confirm that one field event produces one count. If the current value does not change, trace backward to the first stage that failed to change.
  4. If one event produces several counts, correct contact bounce, signal noise, or repeated logic transitions before testing the preset.

The proof for this stage is a predictable change in the current value of C0; the completion state is not yet the diagnostic target.

How does a K preset configure a fixed target?

K identifies a literal constant. The instruction below gives C0 a fixed preset of 100:

CNT C0 K100

The value 100 is stored as part of the instruction. Normal runtime logic does not change it. Altering the preset requires editing the instruction and transferring the revised program by the procedure used for the controller.

Operand Value source Runtime change Typical use
K100 Literal 100 in the instruction Not through a data register A target that remains fixed
D100 Current contents of register D100 By writing a new register value A recipe, operator setting, or calculated target

Test K100 by resetting the counter through the project's existing reset logic, applying count events, and observing the completion state when the current value reaches 100.

How do I configure D100 as a variable preset?

D identifies the data-register area. In the following instruction, 100 is part of the address D100; it is not a request to count 100 pulses:

CNT C0 D100

Before executing the counter, place the required target value in D100. Write it with program initialization, recipe logic, an HMI entry, or the programming software's monitored-register function. For example, storing the numeric value 100 in D100 makes the resolved preset 100. Storing another valid value changes the target without changing the CNT instruction.

Monitor both the register and the counter. Seeing D100 as an operand only proves that the address is configured; it does not prove that the register contains a usable target. Check the controller documentation for the counter's accepted numeric range, word width, and signed-value rules before allowing unrestricted operator or communication writes.

The proof for this stage is that the online value of D100 equals the intended preset and that C0 resolves the same target.

Why does CNT C0 D100 appear to do nothing?

The first check is the live value stored in D100. A newly selected or uninitialized register may contain zero. Zero does not represent the intended positive pulse target, so the observed behavior will differ from a counter configured with K100. Write a valid value greater than 1, then reset and retest the counter.

Observed condition Likely stop point Action Proof
D100 reads zero Preset source Write the required positive target into D100 The online preset changes to that value
D100 changes back unexpectedly Register writer Find initialization, recipe, HMI, or communication logic writing the register The value remains stable during the test
Input changes but count does not Rung or program execution Trace enables, interlocks, and task execution The current count advances
Count advances more than once per event Physical signal or edge logic Correct bounce, noise, or repeated transitions One event produces one count
Current count is already beyond a new preset Runtime preset change Apply the project's reset sequence and repeat from a known state The count starts from the intended reset value
Entered value is rejected or interpreted incorrectly Data type or range Read the counter and register format in the controller documentation The monitored decimal value matches the entry

Program order also matters when logic writes D100 during execution. Monitor the register at the point where CNT reads it, not only after later logic has overwritten it. Continue when the preset stays correct throughout the count test.

How do I verify the complete counter operation?

  1. Choose a valid positive test target and place it in D100.
  2. Confirm online that D100 contains the intended numeric value.
  3. Reset C0 with the reset logic already defined for the application.
  4. Apply one count event and confirm that the current value changes exactly once.
  5. Repeat the event while watching the physical input, rung condition, current count, resolved preset, and completion state.
  6. Confirm that completion occurs when the current value reaches the value stored in D100.
  7. Change D100 to another valid test value, reset C0, and repeat the test. This proves that the operand is being read as a register rather than as a literal constant.

FAQ

How do I make CNT C0 count to 100 with a D register?

Use CNT C0 D100 and store the numeric value 100 in D100. Monitor the register online before applying pulses.

How do I choose between K100 and D100?

Use K100 when the target must remain a literal 100. Use D100 when logic, an HMI, a recipe, or a communication device must change the target at runtime.

Why does my D-register counter not activate?

Check the live preset first; D100 may contain zero or may be overwritten by other logic. Load a valid value greater than 1, reset C0, then verify that one input event produces one count and that completion occurs at the stored preset.

Back to blog