Copy the quadrature count into a second register and round the copy into steps of 5 so the operator display stops flickering, while the raw count stays exact for diagnostics and control. Round the magnitude to the nearest 5 and reapply the sign, or hold the display until the count crosses a multiple of 5. Both rules step up and down, and the panel's decimal formatting keeps the fraction visible.
Jitter on a counter display is usually a resolution problem, not a counting problem. The screen shows more digits than the job needs, so the last digit flickers while the machine sits still. The fix is to copy the quadrature count into a second register and round that copy into steps of 5. The raw count keeps running untouched for diagnostics and for anything that positions or protects the machine. This page gives the two rounding rules that work, the sign handling that integer division demands, a worked example at 1012 counts with 0.1 mm per count, and the nine test values to run before the screen goes back to the operator.
Decide whether the count or the display is unstable
Watch the raw count on a maintenance screen while the machine is parked and while it moves. Counter instructions add or subtract one count on a 0-to-1 transition of the input, and quadrature decoding delivers 4 counts per encoder line, so vibration at a signal edge can toggle a few counts with nothing moving. What you see decides the fix:
- The display flickers by 1 or 2 in the last digit and the raw count holds one value: a presentation problem. Quantize and you are done.
- The raw count wanders 1 or 2 counts while parked: edge chatter from vibration, shielding or grounding. Clean up the signal first, then quantize if the display still shows more digits than the job needs.
- The raw count jumps by tens or hundreds or drifts with no motion: lost counts, electrical noise or the wrong count mode. Diagnose the count before touching the display.
- The display freezes while the machine moves: an update or link problem, not jitter.
A stepped display changes only what the operator sees. Every count still exists in the raw register.
Two rounding rules that step by 5
Nearest 5. Round the magnitude to the closest multiple of 5 and reapply the sign:
stepped_count = sign(raw_count) × ((abs(raw_count) + 2) ÷ 5) × 5 with integer division
The +2 is the half-step bias for a 5-count step (half of 5 is 2.5 counts, and integer math adds 2). It produces nearest-step rounding, and because counts are whole numbers no value sits exactly 2.5 counts from two multiples of 5, so the rule never ties. The sign is handled on the magnitude because integer division in IEC 61131-3 languages truncates toward zero: −7 ÷ 5 gives −1, not −2, and a formula that looks sign-neutral below zero lands on the wrong step.
Boundary hold. Move the display only when the count crosses a multiple of 5:
stepped_count = (raw_count ÷ 5) × 5 with integer division
Truncation toward zero makes the band around zero symmetric: raw counts from −4 to 4 display 0, from 5 to 9 display 5, and from −9 to −5 display −5.
Hysteresis. Both rules flicker when the count parks on a rounding edge. Hold the displayed value until the raw count moves more than half a step plus the measured wobble away from it. With 1 count of wobble and a 5-count step, that trigger is 4 counts (2.5 + 1, rounded up).
Sign trouble is not unique to counters. A panel that loses the sign on bipolar RTD temperatures fails the same way, and the same test catches it: run values on both sides of zero.
Worked example: a count parked at 1012
A slide carries an encoder into a quadrature counter, scaled at 0.1 mm per count. Your scaling will differ; the arithmetic is what transfers. The machine is stationary and the count sits at 1012, wobbling between 1011 and 1013. The unstepped display computes 1012 × 0.1 = 101.2 mm and flickers between 101.1 and 101.3 mm.
Nearest 5:
- 1011 → ((1011 + 2) ÷ 5) × 5 = (1013 ÷ 5) × 5 = 202 × 5 = 1010 counts → 101.0 mm
- 1012 → (1014 ÷ 5) × 5 = 202 × 5 = 1010 → 101.0 mm
- 1013 → (1015 ÷ 5) × 5 = 203 × 5 = 1015 → 101.5 mm
The wobble band straddles the rounding edge between 1012 and 1013, so nearest-5 still flickers between 101.0 and 101.5 mm.
Boundary hold:
- 1011 ÷ 5 = 202 remainder 1 → 202 × 5 = 1010 → 101.0 mm
- 1012 ÷ 5 = 202 remainder 2 → 1010 → 101.0 mm
- 1013 ÷ 5 = 202 remainder 3 → 1010 → 101.0 mm
All three counts display 101.0 mm, and the number moves only when the count reaches 1015. Each display step is 5 counts × 0.1 mm = 0.5 mm, which one decimal place shows exactly.
Hysteresis variant: display 1010 and update only when the raw count moves 4 or more counts away from it. Wobble to 1013 is 3 counts away and holds. A real move to 1014 is 4 counts, and the display steps to 101.5 mm.
Write it in the PLC and format it on the panel
- Leave the raw count in its own register. Nothing writes to it.
- Add a second register for the stepped value and compute it once per scan. Illustrative names and types:
raw_count : DINT := 1012; // value from the counter module, read only
stepped_count : DINT := 0; // value the display uses, one write per scan
Apply the nearest-5 or boundary expression to raw_count and store the result in stepped_count. 3. Point the numeric display object at stepped_count. 4. Set the object's decimal-places setting so the fraction shows. One place displays the 0.5 mm steps of the example; two places display a 0.25 mm fraction. If the object only prints whole numbers, keep the value in tenths and label the screen "× 0.1 mm". 5. Scale in one place. Quantize the raw counts and let the object's scaling multiply by 0.1 mm per count, or scale in the PLC first and quantize the engineering value. Doing both doubles the step size. When the PLC does the scaling, multiply before dividing, because an early integer divide truncates: converting 1012 counts (101.2 mm) to whole millimetres with 1012 ÷ 10 gives 101 mm and drops the 0.2 mm the decimal place was showing. The raw-versus-engineering split matters in trends too: setting raw and engineering units on an HMI trend. 6. Keep a maintenance view with raw_count beside stepped_count. During steady running, a moving raw count with a still stepped count means the filter is doing its job. Where the number sits and how big the digits read is its own job: how to display a PLC counter value where operators can see it.
Test values in both directions
Run these raw counts through the expression before the screen goes live:
| Raw count | Nearest 5 | Boundary hold |
|---|---|---|
| 4 | 5 | 0 |
| 5 | 5 | 5 |
| 9 | 10 | 5 |
| 12 | 10 | 10 |
| 13 | 15 | 10 |
| −4 | −5 | 0 |
| −7 | −5 | −5 |
| −9 | −10 | −5 |
| −10 | −10 | −10 |
Then jog the machine up and down across two boundaries. The boundary hold flips exactly on multiples of 5 in both directions. Nearest 5 flips at 1013 going up and at 1012 coming back down from 1015, so check the flip point in each direction. Counting down has its own scan-timing traps: PLC up-down counter scan timing and direction logic.
When the display is not the problem
If the raw count moves while the machine is parked, no display rule will steady the number honestly. Chase the signal first: shield and ground the encoder cable, keep it out of drive output trays, and check the count mode against the encoder's documentation. When the count freezes or disagrees with the motion, work through the layers one at a time: find which layer freezes when a PLC counter stops updating.
One safety rule: the stepped value is for eyes only. Positioning, limits, interlocks and totalizers read the raw count. The nearest-5 value can sit up to 2 counts from the truth and the boundary value up to 4 counts behind it, and no control function should ever see that error.
If you also want a notice or status board beside the machine, our shop-floor screens cover that as a separate display. They are not a replacement for the panel that shows the count.
Recommendation: keep the raw count untouched, compute the stepped value into a second register once per scan, and use nearest-5 on the magnitude with a 5-count step when the wobble is 2 counts or less. Switch to the boundary hold when the count parks on a rounding edge, and add the 4-count hysteresis trigger when the display must hold through the wobble and still track real motion. Let the panel's decimal-places setting show the fraction, and run the nine test values before the screen goes back on the wall.
Questions
How much wobble can a 5-count step absorb?
With nearest-5, any raw count within 2 counts of the displayed multiple maps to it, so a machine parked anywhere inside that 5-count band shows one steady number. A band that sits across the 2-to-3 count edge still flips between two steps; that is the case for the boundary hold or the 4-count hysteresis trigger. The sizing scales up: a 10-count step absorbs up to 4 counts of wobble around the displayed value.
Should I quantize raw counts or the scaled value?
Pick one place to scale. Quantize raw counts and let the panel's decimal formatting insert the point: 5 counts at 0.1 mm per count prints as 0.5 mm steps with one decimal place. Scale first only when the requirement is a step in engineering units; a 5.0 mm step is 50 counts at 0.1 mm per count, so round the millimetre value to multiples of 5.0 or the counts to multiples of 50. Quantizing in both places doubles the step size.
What step size should I choose?
Make the step wider than the peak-to-peak wobble, with margin. Counts wobbling between 1011 and 1013 span 2 counts, so a 5-count step holds them. Wobble of ±4 counts needs a 10-count step. Larger steps steady the display further but hide more real motion, so pick the smallest step that covers the measured wobble and re-measure if the machine changes.
Planning information, not legal or engineering advice. Rules differ by place: check codes and permits with your local authority and your licensed trades.