AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

Why a scaled modulo shifts when an absolute encoder wraps

Sensors, encoders and machine vision on the machine Published 6 min read By AutomateDirectUSA engineering team

Short answer

A modulo range that does not divide the encoder's power-of-two physical range creates a fixed position step at every raw rollover. Configure the encoder for its full physical range, accumulate wrap-safe deltas in the PLC, and take the modulo there. Power-cycle position validity is a separate property of the absolute measuring principle.

On this page
  1. Where the step comes from
  2. The step, worked out
  3. Check the gear ratio first
  4. What a power cycle does and does not erase
  5. Accumulation that survives both
  6. Verify with these readings
  7. Questions asked

A modulo range that does not divide the encoder's physical measuring range puts a fixed step into the scaled position at every raw rollover. With 65,536 counts per revolution and 16,384 revolutions, the physical range is 2^30 = 1,073,741,824 counts, and a 3,600,000-count modulus leaves 941,824 counts behind at each wrap. The decision: parameterize the encoder for its full physical range, accumulate wrap-safe signed deltas in the controller, and apply the modulo there. Do not scale the encoder down to the modulo range.

Where the step comes from #

The physical range of a 16-bit, 14-bit-multiturn absolute encoder is the product of its two power-of-two stages:

  • Counts per revolution: 2^16 = 65,536
  • Revolutions: 2^14 = 16,384
  • Physical range: 65,536 × 16,384 = 2^30 = 1,073,741,824 counts

A modulus built from round decimal numbers carries factors of 3 and 5. Factor 3,600,000 and you get 2^7 × 3^2 × 5^5. Because of the 3^2 and 5^5 factors it cannot divide any power of two, so a scaled value defined as raw mod 3,600,000 jumps whenever the raw counter wraps.

That power-of-two structure is not an accident of one model. Multiturn absolute encoders are built from binary counting stages, which is why datasheet measuring ranges are 8,192 steps, 65,536 steps and similar: the same reason a 13-bit SSI multiturn stage gives 8,192 steps and 8,192 turns, as that measuring-range article explains. Any modulus that is not a power-of-two divisor will step at the boundary.

The step, worked out #

Take the example modulus of 3,600,000 counts (12 stops at 300,000 counts):

  • 1,073,741,824 / 3,600,000 = 298.26, so a raw rollover occurs after 298 full modulo lengths and a fraction
  • 298 × 3,600,000 = 1,072,800,000
  • 1,073,741,824 − 1,072,800,000 = 941,824 counts lost at each wrap

Concretely: the raw value goes from 1,073,741,823 to 0, but continuous motion would have produced a scaled reading of 941,824 next. The scaled position instead snaps to 0, a step of −941,824 counts (equivalently +2,658,176 modulo the range). In stop pitches that is 941,824 / 300,000 = 3.14 pitches, so after the wrap every commanded stop carries a permanent offset of 941,824 − 3 × 300,000 = 41,824 counts. The error does not average out; it repeats on every rollover and every power-on resume that crosses a wrap.

This is a calculated example for these inputs. If your stops are spaced differently, or the encoder counts per table revolution differ from 1:1, recompute the residual from your own modulus before trusting any offset figure here.

Check the gear ratio first #

Before touching scaling, compute raw counts per table revolution: encoder revolutions per table revolution × 65,536. Take the ratio from the mechanical drawing, not from the modulo number.

  • If the result is an integer, use it as the modulo range M in the controller and treat the 300,000-count spacing as a display convenience; 300,000 must equal M / 12 or your stop table is wrong regardless of wrapping.
  • If it is not an integer, no integer modulus can be exact: accumulate with an explicit numerator/denominator ratio and carry the remainder, or you will drift once per table revolution even with no rollover in sight.

Only then decide where the modulo lives. If the encoder feeds a drive or motion controller that supports a modulo (endless) axis, configure continuous rotation there and let it handle overflow; that is the cleaner path when the axis already runs on the drive. If the encoder talks straight to the PLC over the fieldbus, do the modulo in the PLC as below.

What a power cycle does and does not erase #

An absolute multiturn encoder reports a position that is valid at power-up from its measuring principle, so the raw value does not restart at zero. The rotating table related article on absolute encoders and travel range covers the same boundary question from the range side. Three items decide the rest:

  • Scaling parameters: the IO controller sends the configuration, including scaling, preset and code sequence settings, on every connection establishment, so they are never lost on power-down. This is also why encoder-side scaling with a non-power-of-two range cannot dodge the rollover step: the configuration always comes back, wrong modulus and all.
  • A commissioning preset (zero offset): whether it is held in non-volatile memory is model-specific. Read the manual for your exact encoder before relying on it.
  • PLC-side offsets and accumulated position: these survive only if you place them in retentive memory. Non-retentive variables lose them on every restart.

The verification is one reading: record the raw value with the table stationary, power-cycle the encoder, record it again. Identical values mean the power cycle itself costs nothing, and your remaining exposures are the PLC-side data and a rollover crossed while unpowered.

Accumulation that survives both #

Run the encoder at its full physical range: 65,536 measuring units per revolution and 16,384 revolutions, with any smaller scaling disabled in the hardware configuration. Then in the PLC:

  1. Read the raw position as a 32-bit signed integer from the cyclic telegram.
  2. Compute the signed delta against the previous cycle, masked to 30 bits (16#3FFFFFFF), so a wrap from 1,073,741,823 to 0 reads as +1.
  3. Convert a masked delta of 2^29 or more into a negative value by subtracting 2^30, so backward motion accumulates correctly too.
  4. Accumulate into the modulo position and take it modulo M each cycle.
  5. Keep the position and the previous raw value in retentive memory and update them every scan.
  6. Reference the position once at a known stop and lock that write behind a commissioning-only permission.

The delta arithmetic is correct across the 2^30 boundary, so the 941,824-count step never appears. At startup the first delta is computed against the retentive previous raw value, which captures any movement while the cabinet was off, provided the table moved less than 2^29 counts (8,192 encoder revolutions). A larger unpowered move aliases to a smaller one and needs a re-reference. If the previous raw value sits in non-retentive memory, the offset is lost on every restart and the whole scheme collapses.

One safety note: any function that writes the position, including the commissioning reference, must be blocked while the axis is under power or in motion; a live axis that receives an unexpected preset will move or drive against its stop.

Verify with these readings #

  • Stationary power cycle: raw value and accumulated position before and after must match exactly.
  • Forced rollover: inject a previous raw value of 1,073,741,820 and a current raw value of 4 in a test branch. The delta must come out as +8 and the position must advance by 8, not by a negative 941-thousand figure.
  • Power-off move: de-energize, turn the table by a known amount below 8,192 encoder revolutions, restore power. The position must equal the old value plus the moved distance, modulo M.
  • Stop spacing: command all 12 stops. Each settled position must read as k × 300,000 for k = 0 to 11, within positioning tolerance, with no 41,824-count offset on any stop.
  • Soak: return to the reference stop after many table revolutions, including at least one raw rollover (298 modulo lengths of travel at this modulus). The position must return with zero net drift.

The decision in one line: full physical range in the encoder, modulo and retentive delta accumulation in the PLC or in a drive-side modulo axis, and the rollover step and the power-cycle drift both disappear.

Questions asked

Why does the scaled position jump at the physical maximum?

The physical range is 2^30 = 1,073,741,824 counts and the modulo range 3,600,000 does not divide it: 298 modulo lengths reach only 1,072,800,000, so each raw rollover shifts the scaled value by the remaining 941,824 counts. The shift repeats on every rollover and grows into a permanent stop offset unless the modulo is done on the full raw range.

Does an absolute encoder need a new zero point after a power loss?

No, not for the raw value. An absolute multiturn encoder reports a valid position at power-up from its measuring principle, so no re-referencing is caused by the power cycle itself. Verify the specific model's behavior with a stationary power-cycle test: record the raw value, cycle power, and record it again. Scaling parameters sent by the controller survive the cycle; a commissioning preset and PLC-side offsets depend on how they are stored.

Why mask the raw delta with 16#3FFFFFFF?

The mask reduces the raw difference to the range of a 30-bit wrap, so a jump from 1,073,741,823 to 0 reads as a delta of +1 instead of a huge negative number. A masked delta of 2^29 counts or more is then interpreted as backward motion by subtracting 2^30, so rotation in either direction across the boundary accumulates correctly.

How much travel is allowed while the power is off?

The first delta after restoration is computed against the retentive previous raw value, so movement is captured as long as it stays under half the raw range: 2^29 counts, or 8,192 encoder revolutions. Measure the actual unpowered motion on the machine and compare it with that limit.

Keep reading

  • Explainer

    Absolute Position Control With an Incremental Encoder

    An incremental encoder cannot name the current position at power-up; it only counts motion from a starting reference. Give the axis one machine coordinate by homing to a repeatable switch event, by absolute feedback, or by restoring a still-valid position, and after that one reference it executes absolute moves as readily as relative ones.

    Servo and stepper motion

  • How-to

    Calculate RPM from an absolute encoder position difference

    Speed from a single-turn absolute encoder is the rollover-corrected position difference over a fixed sample interval. Sampled every 100 ms in OB35 with 8192 counts per revolution, RPM = corrected difference x 600 / 8192, one count is about 0.073 RPM, and the reading is unambiguous below 300 RPM.

    Sensors, encoders and machine vision on the machine

  • Explainer

    Servo Motor as a Linear Axis: Scaling and Feedback Choices

    A rotary servo motor becomes a linear axis through one scaling number — travel per motor revolution, wheel circumference or screw lead divided by gear ratio — and one decision on where the position loop closes. A 0.1 m wheel at 10:1 gearing gives 0.01 m of travel per motor revolution, or 628.3 rad/m. An analog distance sensor on an input card is monitoring data, not axis feedback, until a documented feedback input binds it to the axis.

    Servo and stepper motion