Explainer
Retaining stepper axis position after power loss
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
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 #
- 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.
- 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.
- 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.
- 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.
- 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:
- Home against a reference on every start. When no switch is fitted, homing an incremental encoder axis without a proximity switch shows the startup routine that re-establishes the reference from machine features.
- Add incremental feedback and keep the homing pass. What survives a power cycle in absolute versus quadrature feedback explains why an incremental encoder, however useful, still leaves that reference move on the schedule.
- Fit absolute feedback when the position must be correct with no homing at all. A multi-turn absolute encoder reports position with power off, and in the S7-1500 and S7-1500T motion-control documentation the manufacturer also documents the MC_SaveAbsoluteEncoderData instruction, which saves absolute encoder adjustment data to the SIMATIC Memory Card. Absolute adjustment has failure modes of its own across power cycles; why MC_Home absolute encoder adjustment is lost after a power cycle walks through one.
- Close the loop instead of storing. Converting an open-loop stepper to closed-loop control gives the drive measured position, and this comparison of closed-loop versus open-loop control tuning lays out when each method fits.
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.


