How-to
Dividing encoder counts into a sample clock with a counter
Short answer
Divide A/B quadrature counts by N by configuring the counter as a linear-encoder position channel and preloading it to 2^32 minus 1 minus N, so the terminal count event fires one rising edge every N net counts. A pulse-train tick divider has no direction logic and keeps emitting edges when the encoder dithers, so it is the wrong tool.

On this page
- Step 1: Confirm which counter mode you built
- Step 2: Preload the counter for the divide factor
- Step 3: Route the terminal count pulse to the sample clock
- Worked example: preloading a 32-bit counter for one pulse every 4 counts
- Step 4: Handle encoder jitter at the pulse boundary
- Step 5: Verify before connecting the acquisition card
- Questions asked
Dividing a quadrature encoder by N to clock an acquisition card fails when the counter is built as a pulse-train tick divider: that mode has no direction logic, so encoder dither at a standstill keeps generating edges. The working configuration is a counter input position channel for a linear encoder, preloaded to terminal count minus N, so the terminal count event fires one rising edge after every N net counts of forward travel. The steps below build that divider, verify it, and hand the output to the sample clock input.
Step 1: Confirm which counter mode you built #
Open the task on the counter card and read the channel type. A counter output pulse generation channel using ticks is a frequency divider on one line; it needs one counter per line, A and B separately, and every edge that reaches the tick input counts, forward or back. Delete it. A counter input position channel with the linear encoder type is the correct mode: the quadrature decoder counts up in one direction and down in the other, so dither cancels. Set the decoding type (X1, X2 or X4) to match the resolution you want N counted in. The same decoder behavior is what lets a PLC count pulses without losing position when the wiring and decoding are matched, as covered in counting encoder pulses on a PLC without losing position.
Step 2: Preload the counter for the divide factor #
The counters are 32-bit, so terminal count is 2^32 minus 1. Starting the count N below terminal count makes the counter reach it after N net forward counts; the output then pulses on the terminal count event terminal, the count reloads to the initial value, and that position becomes the new zero. Set the initial count to the preload, set the Z index value to the same preload, and leave the Z index phase at the A and B levels of the encoder's rest state. For the underlying arithmetic of scaling encoder counts into commanded motion, see how to calculate step and direction servo pulse scaling.
Step 3: Route the terminal count pulse to the sample clock #
Pick the counter's terminal count output terminal and run it to the acquisition card's external sample clock input, either by wire to the PFI line named in that card's pinout or over the RTSI bus if both boards share a cable. Read the exact terminal names in the system's device explorer and the device documentation. On the acquisition task, set the sample clock source to that terminal and the active edge to rising; the card samples on the low-to-high transition, so the level held between pulses is irrelevant. Start the acquisition task first so it is armed, then start the counter task, or the first sample is lost.
Worked example: preloading a 32-bit counter for one pulse every 4 counts #
Inputs: the divide factor N is 4 counts, from the design requirement of one sample every 4 increments of net travel. The counter depth is 32 bits, from the counter card's specifications, so terminal count is 4294967295.
The rule in words: preload equals terminal count minus the divide factor.
Arithmetic: 4294967295 − 4 = 4294967291.
Set the initial count and the Z index value to 4294967291 and start the task. Move the encoder forward 4 net counts and one rising edge appears on the terminal count output; the counter reloads, so every further 4 net counts produces the next edge, at 8, 12, 16 and so on. Retreat to 3 and return to 4: no second edge, because the reload already made that point the new zero.
The decision: the expected sample count is net forward travel in counts divided by N, rounded down, so 30 net counts at N = 4 give 7 samples with 2 counts in hand. If the scope shows more edges than that, the fault is jitter at a pulse boundary, not the preload.
Step 4: Handle encoder jitter at the pulse boundary #
Jitter well inside the window nets out and produces nothing. Jitter at the boundary does not: an encoder sitting at N minus 1 that vibrates one count forward reaches terminal count, fires the pulse and reloads, so you sample with no real travel. Fix the source, in this order:
- Electrical noise on A or B: enable the counter input's digital debounce filter, which sets a minimum pulse width an edge must exceed to be counted. Choose a width shorter than the narrowest legitimate A or B edge at your top travel speed, or real pulses are rejected too.
- Mechanical vibration: remount the read head so it is decoupled from the vibration source.
- Wrong Z index phase: dither the encoder by hand around a pulse point with a scope on the output; if the repeats are not quiet, set the Z index phase to the A and B levels of the encoder's rest state and retest.
Debounce and minimum pulse width behave the same way on any counter input; the same reasoning applies when matching an incremental encoder to a PLC high speed counter.
Step 5: Verify before connecting the acquisition card #
Disconnect the sample clock input and put a scope or a spare counter on the divider output.
- Move forward exactly N counts from a known start: expect one rising edge.
- Move forward N more: expect a second edge and none between.
- Dither at the boundary with the debounce filter off, then on, and record the edge count to confirm the filter setting.
- Check the terminal-count pulse width against the minimum pulse width the acquisition card specifies for an external sample clock, taken from that device's specifications document; shape it with a counter output stage if it falls short.
Reconnect and acquire. One safety note: this verification is done with the axis under hand control or at low speed; do not commission the divided clock during a production cycle, because a wrong divide factor silently samples at the wrong spacing.
Questions asked
Can I change the divide factor without rebuilding the task?
Yes. Recompute the preload as 4294967295 minus the new N and set it as the initial count and Z index value, then restart the task. N is any whole number of decoded counts, not only small values.
Why not use two pulse-train tick dividers, one on A and one on B?
A tick divider counts every edge regardless of direction, so it needs one counter per line and emits edges while the encoder dithers in place. A quadrature position counter counts up in one direction and down in the other, so back-and-forth motion cancels and only net travel produces pulses.
What pulse width does the divided clock need?
The sample clock input of the acquisition card triggers on the rising edge, so the level between edges does not matter, but the terminal-count pulse must still meet the minimum pulse width the card specifies for an external sample clock; take that number from the device's own specifications document.


