Sinumerik 840C X-Axis Offset Shift After Linear Scale to Rotary Encoder Retrofit
The Sinumerik 840C is a high-end CNC platform that has been in service in milling, turning, and special-purpose machines for more than three decades. Because the controller, drives, and measuring systems were designed in an era when machines were often retrofitted in the field, the 840C is flexible about the source of position feedback - it accepts both linear scales and rotary encoders. That flexibility is also the source of one of the most common field problems on a retrofit axis: the X-axis appears to be referenced correctly (the G54 work offset is preserved across power off/on), but the physical axis position drifts by tens or hundreds of millimetres after every power cycle.
This article walks through the exact failure mode reported on a rack-and-pinion X-axis that was originally fitted with a Heidenhain LB326 exposed linear encoder (2 500 PPR) and was later reworked to use a GIVI misure rotary incremental encoder (18 000 PPR) mounted on the rear of the servo motor. The diagnosis, machine-data verification, and recommissioning steps below apply to any 840C axis converted from a direct-measuring linear scale to an indirect-measuring rotary encoder.
1. Problem Description
The reported symptoms are unambiguous and repeatable:
- Originally the X-axis was fitted with a Heidenhain LB326 linear scale rated at 2 500 PPR.
- The scale was removed and replaced with a GIVI misure rotary incremental encoder (18 000 PPR) mounted on the rear of the X-axis servo motor shaft.
- The mechanical drive remains a rack-and-pinion arrangement; the gear ratio and pinion pitch were not formally calculated and were set "by trial and error" until the axis appeared to move correctly.
- After successful referencing, the operator stores a G54 work offset, powers the machine off, and powers it back on.
- The stored G54 value is preserved, but the physical position of the X-axis is shifted by more than 200 mm relative to the workpiece coordinate system.
The discrepancy is consistent (not random) - it always reads the same wrong value on warm restart, which immediately rules out EMC noise, encoder cable faults, or intermittent wiring problems. The data path between the measuring system and the MCS display is intact; the scaling or reference logic is wrong.
2. Distinguishing Axis Reference from Work Offset (G54)
On every Sinumerik controller the MCS display has two distinct numbers, and they must be kept separate during diagnosis:
| Display value | Source | Persisted? | Failure mode if wrong |
|---|---|---|---|
| Machine zero (axis reference) | Measuring system + reference point MDs | Re-established on each reference traverse | Physical axis position wrong after every power-on |
| Work offset (G54-G57, G500-G599) | Operator input / part program | Yes (NV-RAM, MD3650* setup) | Stored offset is correct but applied to wrong machine coordinate |
If G54 is preserved but the physical axis no longer sits on the referenced MCS position, the work-offset memory is healthy and the problem lies entirely in the axis reference branch of the measuring system. This is the single most important diagnostic distinction on the 840C, because it isolates the work to MD240*-MD396* (axis-specific machine data) and the reference-traverse sequence, not to the settable frames.
3. Reference Point Approach Sequence on the 840C
The reported sequence is the standard Sinumerik 840C reference-point approach with reduced clear cam and zero mark search. The PLC must hand-shake the cam signal and the measuring-system zero pulse:
- Operator selects the axis and triggers the reference traverse (e.g. via the Reference Point Approaching mode or the corresponding NC command
G74). - The axis accelerates in rapid traverse in the configured reference direction (MD340* bit, typically the negative direction for X).
- The axis reaches the reference cam limit switch - hardware input wired to the PLC interface (DB32 / axis-specific I/O).
- After hitting the cam, the controller reverses direction at reduced velocity (MD284* reduction factor).
- While moving off the cam, the 840C evaluates the first valid zero pulse (reference mark) of the encoder within the configured window.
- On the valid zero pulse the MCS value is forced to the coordinate defined in MD284* (reference point coordinate) and the axis is considered referenced (DB31/32 bit "Referenced" = 1).
4. Root Cause: Encoder Pitch Mismatch on a Rack-and-Pinion Axis
When the feedback source is a rotary encoder on the motor shaft, the controller has no direct knowledge of pinion rotation vs. linear travel. The 840C must be told, in machine-data form, the following four quantities:
- The number of encoder pulses per motor revolution (
ppr). - The evaluation factor (typically 4x for square-wave TTL, set in MD396*).
- The gear ratio between the motor shaft and the pinion shaft (MD220* / MD224*).
- The pinion pitch - the linear travel per pinion revolution, in mm/rev (entered as part of the leadscrew-pitch field in MD240* / MD244*).
If any one of these is wrong, the controller's internal position and the physical axis position diverge. The 200 mm drift reported in this case is large enough to indicate a unit-conversion error (for example, a factor of 5x or 10x) rather than a small back-lash or sign error. Common errors seen in the field include:
- Entering the pinion pitch in teeth-pitch rather than mm/rev.
- Using the motor-side gear ratio (e.g. 4:1) in MD220* but forgetting the second-stage reduction between the intermediate shaft and the pinion.
- Forgetting the 4x evaluation factor when migrating from a 1x sin/cos interpolator to a TTL encoder.
- Using the linear scale's original grating pitch in mm (e.g. 0.020 mm) in a field intended for mm/rev - a single zero in the wrong place gives a 10x error, which on a 1 m travel of the X-axis is exactly 100 mm of drift. A second zero gives 1 000 mm, which the axis then saturates and reports as 200 mm due to MODULO wrap or a software limit.
5. Machine Data to Verify
The 840C organises axis-specific data into the MD2xx and MD3xx blocks. The fields that must be re-checked after any encoder change are listed below. The exact sub-indices depend on the axis letter (X = 1, Y = 2, Z = 3, etc.); the asterisks below denote the axis sub-index that the user must substitute.
| MD | Block | Function | Field check |
|---|---|---|---|
| MD220* | Spindle / gearbox | Numerator of gearbox ratio (motor : load) | Must reflect motor-to-pinion ratio only |
| MD224* | Spindle / gearbox | Denominator of gearbox ratio | Match the actual installed gear pair |
| MD240* | Leadscrew / feed constant | Leadscrew pitch in mm/rev (or pinion pitch here) | Must equal pinion diameter x pi for a rack-and-pinion |
| MD244* | Encoder pulses per revolution | PPR of the mounted encoder | Set to 18 000 for the GIVI misure unit, accounting for evaluation factor |
| MD260* | Encoder assignment | Direct or indirect measuring system | Set to "indirect" (motor encoder) for this retrofit |
| MD284* | Reference point coordinate | MCS value written at the reference mark | Should be a meaningful machine zero, not 0 if a tool-home is used |
| MD296* | Reference approach direction | + or - direction for cam search | Match the physical cam location |
| MD316* | Position-window monitoring | Tolerance between actual and setpoint at standstill | Loosen temporarily to allow the trial to complete |
| MD320* | Following-error monitoring | Max lag during reference approach | May need to be raised if the reference velocity is increased |
| MD340* | Reference approach velocity | Rapid and creep speeds for the cam search | Creep speed must allow reliable detection of the zero pulse |
| MD364* | Position-controller Kv factor | Closed-loop gain | Re-tune for the new total inertia (motor + pinion + rack) |
| MD396* | Measuring-system evaluation | Multiplication factor (1x / 2x / 4x) | Set to 4x for a TTL square-wave encoder, 1x for sin/cos |
6. Pitch Calculation for Rack and Pinion
The mm/rev value the 840C needs is the linear travel of the load per revolution of the encoder, not the linear travel per motor revolution. With a motor-mounted encoder, a gearbox, and a pinion, the formula is:
mm_per_encoder_rev = (pinion_teeth * module * pi) / gearbox_ratio
where:
-
pinion_teeth= number of teeth on the pinion -
module= gear module in mm (NOT diametral pitch - module is the standard metric unit, e.g. 2.0 mm) -
gearbox_ratio= (motor rev) / (pinion rev); for a 4:1 reducer this value is 4
The number of internal increments per mm, which is what MD240* ultimately resolves into, is:
inc_per_mm = (encoder_ppr * eval_factor * gearbox_ratio) / (pinion_teeth * module * pi)
For the reported hardware (GIVI 18 000 PPR, TTL, 4x evaluation, hypothetical 4:1 gear reducer, 20-tooth pinion, module 2.0 mm):
mm_per_encoder_rev = (20 * 2.0 * pi) / 4 = 31.416 mm/rev
inc_per_mm = (18000 * 4 * 4) / 31.416 = 9167 inc/mm
If the original commissioning entered, for example, 200 mm/rev instead of 31.4 mm/rev, the controller will believe every millimetre of pinion travel corresponds to only (31.4/200) = 0.157 of a real millimetre, and a 200 mm move will be displayed as 31.4 mm - but the zero-pulse distance stored at the reference mark will be wrong by a factor of 6.36x. Across a full traverse that compounds to the kind of 200 mm drift the operator is reporting. The factor of 6.36x is a fingerprint that points directly to a missing gearbox-ratio entry in the MD block.
7. Step-by-Step Corrective Procedure
-
Archive the current MD file via the RS-232 interface or a CF-card image. Note the date, the encoder PPN, and the current values of MD220*, MD224*, MD240*, MD244*, MD260*, MD284*, MD296*, MD340*, and MD396*.
// 840C MD dump menu path (operator panel) Setup -> MD -> Save -> Serial (V24) -> 9600 8N1 -
Measure the gearbox ratio and pinion geometry directly. Open the gearbox, count the teeth on each gear, measure the centre distance, and calculate the module. Do not trust a nameplate.
module = (2 * centre_distance) / (teeth_1 + teeth_2) - Verify the encoder PPR from the GIVI misure nameplate and the data sheet. 18 000 PPR is common for motor-mounted encoders; confirm whether the unit outputs TTL square-wave or 1 Vpp sin/cos. Set MD396* to 4 for TTL, 1 for sin/cos with external interpolator, or the interpolator factor (5, 10, 25, 50, 100) for a sin/cos unit with internal interpolation.
-
Enter the calculated values:
MD220* = gearbox_numerator // e.g. 4 MD224* = gearbox_denominator // e.g. 1 MD240* = pinion_pitch_mm_per_rev // e.g. 31.416 MD244* = 18000 // encoder PPR MD260* = 1 // indirect (motor) measuring system MD396* = 4 // TTL 4x evaluation - Reset the axis reference state to force a fresh reference traverse. On the 840C this is done by writing the DB31/32 "Referenced" bit to 0 from the PLC, or by deleting the reference-point bit in the axis-specific MD (MD284* bit "reference point not yet approached").
- Run the reference traverse in single-axis mode at 25 % rapid override. Watch the actual position value in the SERVICE / DIAGNOSIS screen and verify that the value of MD284* (reference point coordinate) is written at the moment the zero pulse fires.
- Mark-to-mark test: Mark the machine bed and the rack with a scribed line. Move the axis exactly one pinion revolution (1 rev of the gearbox output shaft) by commanding a move of (pinion_pitch_mm_per_rev). The scribed mark must return to within the position-window monitoring value of MD316*.
- Re-verify G54 behaviour: Set G54 to a known value, traverse to a known fixture point, record the MCS, power off, wait 30 s for the DC bus to discharge, power on, re-reference the X-axis, and confirm the MCS reads the same value at the same fixture point. The 200 mm drift must be gone.
8. Reference Mark Distance - the Hidden Gotcha
Both the original Heidenhain LB326 and the new GIVI misure encoder are incremental devices with a single reference mark per unit of travel. The 840C uses the reference-mark distance to set the size of the search window for the zero pulse; if the distance is wildly wrong, the controller either never finds the reference mark (axis stuck "not referenced") or picks up a noise-induced false pulse. With a rotary encoder, the reference-mark distance is the pulses-per-revolution value (18 000). The MD field that carries this is typically MD3640* on the 840C, but the user must confirm against the active SW version. If the SW was carried over from a machine with a linear scale, the original distance was the grating pitch in increments (e.g. 20 000 inc/mm for a 5 um scale, or 40 000 inc/mm for a 2 um scale). Leaving that value in place will corrupt the reference search.
9. PLC Hand-Shake and Reference Cam Check
Because the reference traverse is initiated by the NC and the cam signal is wired to the PLC, the PLC program must be re-checked when the mechanical layout changes:
- Confirm the cam input is wired to the correct PLC input byte for the X-axis (typically I 0.x or the axis-specific I/O area on the FM-NC / 840C interface).
- Confirm the PLC sets the "Reference point switch" enable bit in DB31/DB32 (axis interface) before the NC issues the reference traverse.
- Confirm the PLC does not pre-trigger the cam-evaluation during normal jog motion - this is a common bug after retrofits where the old cam debounce time is wrong for the new creep velocity.
- Confirm the encoder interface module (6SC610 / 6SC611 / 6SN1118 / 611-D depending on the drive family) reports the reference mark to the NC correctly. On the SIMODRIVE 611-D family the SIMODRIVE 611-D documentation describes the measuring-circuit connector X411 / X412 and the SRM / ARM feedback assignment.
10. Diagnostic Matrix
| Symptom | Likely MD | Verification | Remedy |
|---|---|---|---|
| G54 preserved, physical axis drifts after power cycle | MD240*, MD244*, MD396* | Mark-to-mark test | Re-enter pitch, PPR, evaluation factor |
| Axis never reaches "Referenced" state | MD260*, MD284*, MD296* | Check DB31/32 referenced bit after traverse | Verify reference-pulse polarity, cam direction, encoder assignment |
| Axis references but at random position each cycle | Reference-mark distance MD3640* | Scope encoder Z pulse vs. NC expected position | Set reference-mark distance to encoder PPR |
| Axis references but Kv unstable / following error alarms | MD364* | Run servo trace, observe following error | Re-tune Kv for the new inertia |
| G54 itself lost on power cycle | MD3650* (setup memory), battery | Check NV-RAM battery voltage | Replace battery, restore setup data from MD file |
| Reference traverse oscillates around the cam | MD340* creep velocity, PLC debounce | Trace cam input and reference-bit | Reduce creep velocity, increase debounce |
11. Verification
After the corrective procedure, the following checks must all pass before the machine is returned to production:
- Five consecutive power cycles with the same G54 set, same fixture point, and the same MCS reading (within MD316* tolerance).
- A G01 move of 1 000 mm in X returns the axis to the same MCS reading as the start position (within MD316*).
- Mark-to-mark test on a known pinion revolution matches MD316* within the commanded value.
- A standard part program that exercises G54, G55, and G58 completes without 7xxx following-error alarms and without 1xxx measuring-system alarms.
- The PLC error stack (DB2 / DB3 on the 840C) is empty after the test cycle.
12. Common Field-Proven Caveats
- After any encoder change, re-validate the soft limits in MD3610* / MD3612* - if the scaling was wrong by a factor of 5x or 10x, the soft limits are now off by the same factor and can be triggered by a small commanded move.
- The 840C supports a two-encoder mode (semi-closed loop on the motor encoder, closed loop on a load-side linear scale). If the original machine had a linear scale, the MD260* field was set to "direct"; for the retrofit it must be set to "indirect" or "both". The wrong setting makes the controller use the second encoder channel that is no longer connected, producing a fixed-position error.
- The encoder cable shielding must be grounded at the drive end only; a double-grounded shield on a GIVI encoder with TTL outputs will inject common-mode noise and the reference mark can be lost on power-on as the bus voltage ramps up.
- If the drive is on the SIMODRIVE 611-D platform, the firmware version on the closed-loop control module must support the new PPR value. Older firmware (SW 1.x for the 611-D) was limited to 16 384 PPR per channel; 18 000 PPR requires at least SW 2.1 or a measurement-circuit module that supports higher counts. The Siemens support portal lists the compatible firmware per drive family.
- Always re-archive the MD file after the retrofit. The 840C is old enough that NV-RAM batteries fail without warning, and the only reliable backup is the serial dump.
FAQ
Why does my Sinumerik 840C X-axis drift by 200 mm after power off/on but G54 is preserved?
The work offset (G54) is stored in NV-RAM and survives a power cycle, but the axis reference is re-established by a fresh reference traverse. If the scaling (MD240* pinion pitch, MD244* PPR, MD396* evaluation) is wrong, the controller writes the reference point coordinate at the wrong physical position, so the MCS display is offset by a multiple of the scaling error. Verify the three MDs above against the actual pinion geometry and encoder nameplate.
What machine data must be re-entered after changing a linear scale to a rotary encoder on the 840C?
At minimum: MD220*/MD224* (gearbox ratio), MD240* (mm/rev), MD244* (encoder PPR), MD260* (direct/indirect selection), MD284* (reference point coordinate), MD296* (reference direction), MD340* (creep velocity), MD3640* (reference-mark distance), and MD396* (evaluation factor 1x/2x/4x). Also re-validate the soft limits in MD3610*/MD3612* because the scaling change shifts the working envelope.
How do I calculate the mm/rev field for a rack-and-pinion X-axis with a motor-mounted encoder?
Use mm_per_encoder_rev = (pinion_teeth * module * pi) / gearbox_ratio. For a 20-tooth pinion, 2.0 mm module, and 4:1 gear reducer the value is 31.416 mm/rev. The controller's internal increments per millimetre are (PPR * eval_factor * gearbox_ratio) / (pinion_teeth * module * pi). For 18 000 PPR, 4x evaluation, 4:1 ratio, and the same pinion that is 9 167 inc/mm.
Why does the 840C sometimes pick a wrong reference pulse on a rotary encoder?
The reference-mark distance MD3640* must match the rotary encoder's pulses per revolution. A value carried over from a linear scale (e.g. 40 000 inc/mm from a 2 um grating) is dimensionally wrong and the search window will be misinterpreted. Set MD3640* to the encoder PPR (18 000 for the GIVI misure unit) and re-test.
Will the SIMODRIVE 611-D accept an 18 000 PPR encoder on the 840C?
Firmware SW 2.1 and later on the SIMODRIVE 611-D closed-loop module supports encoders above 16 384 PPR per channel. Older firmware may saturate the counter and the reference mark will never be found. Check the firmware stamp on the module and consult the Siemens support portal for the latest compatibility list before commissioning.