AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

Retaining stepper axis position after power loss

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

Short answer

Yes: a retained variable in a global data block keeps the last stored axis position through a shutdown, and startup logic can load it back into the technology object. The retained number cannot detect movement or lost steps while the machine is off, so trust it only on slow, low-accuracy axes that nothing can move unpowered, and home or fit an absolute encoder whenever a collision is possible.

On this page
  1. What a retained variable keeps and what it cannot know
  2. Setting up the retained position and the restart logic
  3. How far the restored coordinate can be off
  4. When the restored coordinate is safe to use
  5. When to home or add absolute feedback
  6. The decision, case by case
  7. Questions asked

An S7-1214 can keep the last position of an open-loop stepper axis through a shutdown: declare the value in a global data block, set the variable's Retain property, and copy each technology object's actual position into that variable every cycle. Startup logic then loads the retained number back into the axis before any motion is enabled. That is all retention does — it preserves a number. The CPU cannot see whether the machine sat still while power was off, and a stepper without an encoder has no feedback to report the steps lost as the drive died. A restored coordinate is therefore a legitimate restart reference only on slow, low-accuracy axes that nothing can move unpowered; everywhere else it is a guess that can steer the first automatic move into a collision.

What a retained variable keeps and what it cannot know #

In STEP 7 (TIA Portal), each variable in a global data block can carry the Retain property. The CPU writes retained variables to non-volatile memory and reloads them at power-up, so the values survive an orderly shutdown and a sudden outage alike. The technology object's actual position is not retained by itself: it lives in the motion-control runtime, not in your data block, so nothing is kept unless the program copies it out every cycle.

Take the example machine used through this article: four positioning axes, three of them steppers without encoders, each homed against a reference after every start today. The temptation is to keep feeding the HMI from a memory double word in OB1 — a value parked at an address such as %MD142 — and call that storage. Writing to a memory double word keeps nothing across power-off, because retention is a property of a declared variable, not of an address. The position has to land in a variable declared in a global data block, with Retain ticked on that variable.

Setting up the retained position and the restart logic #

  1. Create a global data block for axis data and declare one position variable per axis, in the user units the HMI already shows — millimetres on this machine.
  2. Tick the Retain checkbox on each of those variables. Marking the whole block works too, but per-variable marking keeps unrelated data out of non-volatile memory.
  3. Every cycle, copy each technology object's actual position into its retained variable — one more destination on the MOVE in OB1 that already feeds the HMI.
  4. On power-up, before any axis is enabled, run startup logic that homes each technology object against its retained value: the homing instruction has a mode that takes the reference position as a value instead of searching for a switch or a mark, and that is the mode to use.
  5. Leave the drives disabled until every technology object reports initialized, and command the first move at reduced velocity.

Notice what that chain does not contain: a measurement. Every step preserves, restores or trusts a number; nothing in it asks the machine where it is. The error budget below decides whether the scheme is acceptable.

How far the restored coordinate can be off #

Two independent errors separate the restored number from the mechanism. Both calculations are worked examples for the inputs stated — substitute your own speeds, scan times and outages.

Update lag. The retained variable is only as fresh as the last scan that wrote it, so at the moment power fails, the lag equals axis speed times scan time. For an axis moving at 20 mm/s on a 10 ms scan: 20 mm/s x 0.010 s = 0.2 mm. The stored coordinate trails the true position by up to 0.2 mm — negligible on this slow machine, and it scales in direct proportion to speed. An open-loop axis can also overshoot its last commanded position as the rotor coasts under load after the pulses stop, and with no encoder, that coast goes unmeasured.

Unpowered movement. The larger term has no upper bound. Suppose the X carriage sits at +312.500 mm at shutdown, so the retained variable holds 312.500 mm exactly — retention itself loses nothing. During the outage a technician slides the carriage 40 mm toward the motor while clearing a jam. True position at restart: 312.500 - 40.000 = 272.500 mm. The CPU restores 312.500 mm and believes it. The first automatic move, commanded to 250.000 mm, then executes with the entire coordinate system shifted by 40.000 mm, and any fixture mapped from the old coordinates stands in the path.

The same error class arrives without human help wherever gravity or an unbalanced load can back-drive the axis: a vertical axis on an unbraked screw sags between shutdown and restart, and steps lost as the supply collapses go unreported. Retention is exact; the mechanism is not.

When the restored coordinate is safe to use #

Commit to it when three conditions hold at once. First, nothing can move the axis while the control is dead: no gravity load, no back-drivable screw, no counterweight, no manual access, no vibration that can creep the carriage. Second, the application's tolerance comfortably exceeds the scan lag plus the unmeasured coast — a margin well beyond 0.2 mm at the speeds this machine runs. Third, a wrong restart position costs a soft stop against a limit, not a crash into product or tooling.

Where those hold, retained restart is the right answer, with discipline at restart: restored coordinates drive nothing automatic until an operator confirms them against machine marks, the first move runs at reduced velocity, and hard limit switches — wired independent of any stored coordinate — stay armed the whole time. Treat every restored coordinate as unverified until a reference is confirmed, and keep people and obstacles clear of the axis path across that first move.

When to home or add absolute feedback #

The scheme fails as soon as any condition breaks: a Z axis under gravity, a carriage a technician can reach, an accuracy requirement tighter than the error budget, or an outage whose collision would cost real damage. Then the retained value may still appear on the HMI as a hint, but it must never drive motion, and position has to come from the machine. In ascending cost:

The decision, case by case #

  • Slow axis, loose tolerance, mechanically immobile while powered down: retain. One retained variable per axis, a cyclic copy out of each technology object, startup logic that homes the technology object from the retained value, reduced first-move velocity, operator confirmation before automatic mode.
  • Axis that gravity, an unbalanced load or a hand can move while power is off: home every start. Keep the retained value on the HMI as a reference if it helps; let no motion command use it.
  • Position that must be correct after every outage with no homing pass: absolute feedback on the axis, with the adjustment data saved the way the documentation for your CPU prescribes.

Retention answers where the controller believed the axis stopped. It never answers where the axis is. Only the machine — through a switch, a mark or feedback hardware — answers that.

Questions asked

Does marking the whole data block Retain keep the axis positions automatically?

No. Retention applies only to the variables you mark in a global data block. The technology object's actual position lives in the motion-control runtime, so it survives a shutdown only if the program copies it into a retained variable every cycle and startup logic loads it back before motion. Without that copy and that restore, nothing is kept.

Can the memory double word that holds the position be made retentive directly?

Retention is a property of a declared variable inside a data block, not of a raw memory address. A value parked at a memory double word such as %MD142 disappears at power-off no matter how often it is written. Declare a variable in a global data block, tick Retain on it, and make that variable the destination of the position copy.

Can the controller detect that an axis moved while power was off?

Not without feedback hardware. An open-loop stepper gives the CPU no signal path from the motor, so unpowered movement, back-driving and steps lost at shutdown are invisible to the program. External checks such as hard reference stops, position marks or an operator's confirmation can catch them, and a multi-turn absolute encoder removes the question by measuring position with no power applied.

Do retained positions survive a program download or a CPU memory reset?

Plan on them being replaced by the block's start values after a changed download of that data block, and on a memory reset initializing retentive memory as well. The exact download behavior is documented per CPU family and firmware, so confirm it for yours before trusting retention across a program update. After any program change, re-establish position by homing before automatic motion runs.

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

  • Troubleshooting

    Why a servo axis returns 4 degrees off home after years

    Trace commanded position, actual position and torque through one forward-and-reverse cycle before touching the home offset. If command and actual both repeat exactly while the tool keeps stepping further off, the fault is mechanical lost motion behind the sensor — a slipping coupling, a worn key or backlash — and re-referencing only hides it while the slip keeps growing. Repair the joint, then re-establish home.

    Servo and stepper motion

  • Troubleshooting

    Why a Stepper Axis Stays Blocked on a Low Limit After E-Stop

    The axis blocks on three stacked conditions: motion permission removed by the E-stop, a latched low-limit error, and a Homed status that disabling the axis erases. Recover in that order — safety reset, enable the axis, MC_Reset to acknowledge the error, then MC_Home so the axis moves away from the active limit. On a reported S7-1214C DC/DC/DC at firmware V4.2, that sequence cleared the alarm with no manual move.

    Servo and stepper motion