AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

How-to

Changing a servo axis gear ratio at runtime with MC_GearIn

Servo and stepper motion Published 5 min read By AutomateDirectUSA engineering team

Short answer

The load-gear values of an S7-1500 positioning axis are start values, so a write from the user program is rejected. To change the ratio during operation, command a virtual master axis and couple the real axis with MC_GearIn, whose ratio is a runtime parameter; the fallback is WRIT_DBL plus a technology object restart, which costs memory-card life.

On this page
  1. Why the write to the mechanics is rejected
  2. Method 1: virtual master plus MC_GearIn
  3. Method 2: rewrite the start values and restart
  4. Which method for your machine
  5. Questions asked

You cannot change the ratio where you first tried. Numerator, Denominator and LeadScrewPitch under the mechanics of an S7-1500 positioning axis are start values, and a write from the user program is rejected. Two routes work. The one to build on: keep the real axis configured for one baseline gear stage, command every move on a virtual master axis, and couple the two with MC_GearIn, whose ratio is a runtime parameter. The fallback: rewrite the start values in load memory with WRIT_DBL and restart the technology object. For a machine that shifts gears during production, only the first route is acceptable, because every WRIT_DBL call rewrites the memory card.

Why the write to the mechanics is rejected #

The PositioningAxis technology object stores the load gear in its configuration: Numerator is the number of motor revolutions, Denominator the number of load revolutions, and LeadScrewPitch the load travel per load revolution. All three are start values in the technology DB. The S7-1500/S7-1500T Axis Functions manual lists them in appendix A.2.10 (LoadGear tags) and A.2.13 (Mechanics tags), and states the rule: changes to a start value in load memory are made with the extended instruction WRIT_DBL, and they take effect only after a restart of the technology object. A write from the cyclic program lands on the runtime copy in work memory, and the motion core rejects it to keep the configuration image consistent — that is the write-access error you get.

This is fine for a ratio set once, the way you configure a gear ratio for degree moves on a rotary servo axis and leave it. It is not fine for a shifting gearbox, so the variable part of the ratio has to move out of the technology object and into a runtime instruction.

Method 1: virtual master plus MC_GearIn #

This is the recommended pattern for a multi-stage caliper feed. The gear ratio of MC_GearIn is a runtime parameter, so it changes without restarting anything and without touching load memory.

  1. Add a virtual axis technology object with no drive behind it. Set its load gear to 1:1 and its LeadScrewPitch to the rack pitch per output-shaft revolution, so the virtual axis works directly in true rack millimetres.
  2. Configure the real PositioningAxis for the baseline gear stage: Numerator = motor revolutions per load revolution of that stage, Denominator = 1, LeadScrewPitch = the same rack pitch. With the encoder on the motor, the technology object converts motor counts with this fixed baseline forever after.
  3. Couple the axes with MC_GearIn, master = virtual axis, slave = real axis. The ratio pair for each stage is the true stage ratio divided by the baseline ratio, expressed as integers.
  4. Send every positioning command — MC_MoveAbsolute, MC_MoveVelocity, MC_Halt — to the virtual axis. The real axis only follows; it never receives a move of its own.
  5. At a gear change: halt the virtual axis and wait for standstill, shift the gearbox mechanically, execute MC_GearIn with the new pair, then resume moves. Make the shift request part of the machine sequence so the mechanical shift cannot happen with axis motion — a ratio change under motion ends in a velocity jump and a following-error stop at best, and the interlock belongs in the machine's risk assessment.

Worked example, with the arithmetic #

Example inputs, not measured values: rack pitch p = 10 mm per output-shaft revolution, baseline stage i = 4 motor revolutions per load revolution, second stage i = 2.

The real axis is configured once with Numerator = 4, Denominator = 1, pitch as above. Its internal scale is then fixed at p / i = 10 mm / 4 = 2.5 mm of travel per motor revolution.

The MC_GearIn pair per stage is i(stage) / i(baseline):

Stage i (motor rev / load rev) RatioNumerator RatioDenominator True travel per motor rev
1 (baseline) 4 1 1 2.5 mm
2 2 1 2 5 mm

The slave follows at 1/2 in stage 2, which exactly cancels the factor by which the fixed baseline now overstates travel.

An SCL sketch — the variable and instance names are illustrative, mine, not vendor identifiers:

// Illustrative variables
#nGearStage : INT  := 1;      // 1 = baseline stage, 2 = second stage
#bReGear    : BOOL := FALSE; // TRUE after the shift completed at standstill
#nNum       : DINT := 1;     // RatioNumerator for the active stage
#nDen       : DINT := 1;     // RatioDenominator for the active stage

CASE #nGearStage OF
    1: #nNum := 1; #nDen := 1;
    2: #nNum := 1; #nDen := 2;
END_CASE;

"GearInCaliper"(Master := "VirtualFeedAxis",
                Slave  := "CaliperAxis",
                Execute := #bReGear,
                RatioNumerator := #nNum,
                RatioDenominator := #nDen,
                Acceleration := 200.0,   // example dynamics, mm/s^2
                Deceleration := 200.0,
                Jerk := 1000.0);

The check that proves the scaling, still a calculated example: command 1000 mm/min on the virtual axis in stage 2. True travel per motor revolution in stage 2 is p / i = 10 mm / 2 = 5 mm/rev, so the motor must turn 1000 / 5 = 200 rpm. Through the coupling, the real axis runs at half the master, 500 mm/min in its own units, and its fixed scale gives 500 / 2.5 = 200 rpm. Same number from both directions — the scaling is consistent. One rising edge of Execute latches one ratio; the re-gear after a shift is a new execution of the instruction.

Method 2: rewrite the start values and restart #

When the application must keep a single positioning axis, the documented path is load memory plus restart:

  1. Write the new Numerator, Denominator and LeadScrewPitch start values into the technology DB in load memory with WRIT_DBL; the instruction's addressing is covered in an article on indirect DB addressing with WRIT_DBL.
  2. Restart the technology object with MC_Reset and Restart = TRUE (a CPU restart does the same job); the new start values load at that restart.
  3. Reference the axis again before the next move, because the restart rebuilds the technology object's position context.

The cost: each WRIT_DBL rewrites the load-memory area on the SIMATIC memory card, and repeated writes shorten the card's life. A caliper that shifts gears many times per shift will burn through that budget; this route is for a ratio that changes at commissioning or after a mechanical conversion, not per workpiece.

Which method for your machine #

  • Several gear stages, ratio changes during production: Method 1. No restart, no memory-card wear, and the virtual master keeps the position in true rack units across every shift.
  • One ratio, changed only at setup or a mechanical conversion: Method 2 is fine and adds nothing to the cyclic program.
  • An existing machine whose moves already target the real axis: the retrofit is one virtual technology object plus re-targeting the move instructions to it, and it is still Method 1 — cheaper than any amount of WRIT_DBL traffic on a shifting gearbox.

Either way, the mechanics configuration of the real axis stays untouched in operation; the only question is whether the variable ratio lives in MC_GearIn at runtime or in a start value you rewrite and restart.

Questions asked

Can MC_GearIn apply a new ratio while the slave axis is still moving?

The ratio is latched at the rising edge of Execute, so a new ratio needs a new execution: end the current gearing with MC_GearOut and call MC_GearIn again with the new numerator and denominator. A shifting caliper gearbox changes its mechanics at standstill anyway, so sequence the re-gear after standstill. A ratio swap under motion shows up as a velocity jump and at best a following-error stop.

Does the axis need re-referencing after a gear change?

With the virtual-master method, no. The virtual axis carries the position in true rack units and the new MC_GearIn ratio re-slaves the real axis at standstill, so the next MC_MoveAbsolute goes to the right place. After the WRIT_DBL route the technology object restarts and its position context is rebuilt, so reference the axis again before the next move.

What if the physical ratio is not an integer, for example 3.62 motor revolutions per load revolution?

Express it as an integer pair in MC_GearIn: a ratio of 362 over 100 gives the same value with both inputs integer. Keep every stage as an integer pair in the same load units, so the ratio change between stages stays exact and no stage drifts by a rounding error over a long feed.

Does a virtual master axis need its own drive or I/O?

No. A virtual axis technology object has no drive, no telegram and no encoder; it runs as a software axis in the CPU and costs cycle time only. That is why it works as the positioning reference: all move instructions target it, and the real axis behind MC_GearIn never needs a positioning command of its own.

Keep reading

  • Explainer

    Servo Positioning Resolution Versus Stepper Step Angle Explained

    A 0.018° move needs 360 ÷ 0.018 = 20,000 usable feedback counts per revolution, which come from the encoder and the drive's decoding and scaling, not from the servo label. Matching 3,000 command pulses per revolution on a stepper and a servo only matches command scaling; short-time overload capacity and high-speed performance still differ.

    Servo and stepper motion

  • How-to

    Setting Gear Ratio for Degree Moves on a Rotary Servo Axis

    Divide 360 by every reduction stage between motor and table: a 10:1 belt ahead of a 50:1 gearbox gives 500:1, so one motor revolution turns the load 0.72 degrees. At 0.001 degree per command pulse that is 720 pulses per motor revolution, and the electronic gear must express the encoder ratio exactly, 8192/720 reduced to 512/45, for degree commands to land.

    Servo and stepper motion

  • How-to

    Setting Up Servo Electronic Gearing With Registration Correction

    Gear the folder servo to the web encoder with one fixed electronic gear ratio and apply registration error as a bounded phase trim ramped across the 100 to 200 ms between corrections. At 150 m/min a 0.1 mm tolerance is 40 microseconds of web travel — about eight 0.0127 mm increments — so doubling or halving a pulse train for six pulses trips following error, while a ramped trim changes speed by 0.04 percent.

    Servo and stepper motion