Skip to main content
CNC.wiki

G28 Automatic Return to Reference Position: CNC Programming Guide

Learn to program G28 automatic return to reference position on Fanuc, Siemens, and Mitsubishi CNCs. Avoid crashes and verify parameters and zero return alarms.

Hakan Gündoğdu
Hakan Gündoğdu

CNC CARE Co-founder

Introduction

A high-speed rapid traverse plunge directly into a table-mounted vise jaw, a rotating chuck, or a workholding clamp represents one of the most destructive collision risks during automated machining cycles. When a programmer commands a G28 automatic reference position return in absolute mode (G90) and specifies target coordinates of zero (e.g., G90 G28 X0 Y0 Z0), the CNC controller interprets the workpiece coordinate origin as the intermediate waypoint. Instead of retracting directly to safety, the spindle assembly or tool turret plunges at maximum rapid feedrate into the raw stock, shattering the cutting tool, bending the turret, triggering an immediate overload alarm code, and producing a ruined scrap part. Eliminating this risk requires a precise understanding of how the control parses absolute versus incremental commands during the home return sequence. Implementing a safe direct return to machine zero protects expensive spindle bearings and prevents unscheduled downtime on the shop floor.

Technical Summary

Technical AttributeSpecification
Command CodeG28
Modal GroupGroup 00 / Non-modal (One-shot)
Applicable BrandsFanuc, Siemens, Mitsubishi
Critical ParametersFanuc: Parameter No. 3401 Bit 6 (GSB) & Bit 7 (GSC), Parameter No. 3402 Bit 0 (G01); Siemens: MD 34100 $_MA_REFP_SET_POS[n]; Mitsubishi: Parameter #2037 G53ofs, Parameter #1091 Ignore middle point
Main ConstraintAt least one axis coordinate must be programmed in the G28 block. All active tool length offsets and cutter/nose radius compensations (G40, G49, Txx00) must be canceled prior to execution.

Quick Read

  • Incremental Safe Mode: Switch modally to G91 (milling/lathe B/C) or use incremental coordinate addresses U0 W0 (lathe A) to bypass waypoint movement and return directly to machine home.
  • Cancel Offset Compensation: Always program G40 and tool length/offset cancels (Txx00 or G49) prior to executing G28 to prevent false non-arrival alarms.
  • Syntax Address Minimum: Program at least one axis coordinate (such as X, Y, Z, U, W) in the G28 block; empty command blocks will cause syntax errors.
  • Deactivate Coordinates: Disable all active scaling, coordinate system rotation, and mirroring functions to avoid coordinate shifting and failed checks.
  • Avoid Waypoint Mode Shifts: Do not switch CNC modes (to MDI or manual) or trigger PLC interrupts while the machine is paused at a single-block intermediate waypoint.
  • Rotary Axis Limits: Program returns on multiple rotary axes individually rather than simultaneously to avoid coordination errors or Mitsubishi Program Error (P10).

Basic Concepts

Integrating the G28 automatic reference position return into a parts program establishes a programmatic safety routine that establishes a repeatable physical machine zero before tool indexing, pallet swapping, or program completion. Tool turrets and spindle assemblies must retract to a known, collision-free home position. G28 handles this via a two-phase motion: the axes first traverse to a designated intermediate waypoint, and from there, they travel directly to the machine zero coordinate. This ensures that tool changes occur far away from the workpiece and workholding fixtures, preventing tool interference.

To verify that the axes have arrived safely at the machine zero reference point, programmers can implement the G27 reference position return check. While G28 performs the physical return to the reference point, G27 provides a diagnostic verification step to ensure no positioning errors or coordinate shifts occurred during the cycle. By combining these commands, shops can confirm coordinate integrity, which is especially important when axes are moving at maximum velocities during G00 rapid traverse positioning to avoid mechanical overtravel.

Safety check envelopes like the G22 stored stroke limit check on command can be combined with reference return cycles to establish software-based travel boundaries. These software limits prevent the machine slides from crashing into the physical margins of the enclosure. During G28 execution, the control briefly cancels compensations, meaning the physical tool tip path will shift based on active offsets. Understanding how coordinates translate during the waypoint transition is critical to keeping the tool path within the safe boundaries of the work envelope.

Command Structure

The G28 command is a Group 00 non-modal (one-shot) instruction that executes rapid axis positioning to the programmed coordinates before performing the referencing return. Programmed axes traverse at rapid traverse speed to the coordinates specified in the block. Once the axes reach the target position, the control's position loop comparator evaluates the machine's physical feedback against the reference coordinates stored in system variables. The return verifies only the axes programmed in the block; any omitted axes remain unchecked.

To accommodate different machine configurations, G28 utilizes different syntax structures. Lathe systems running under G-code System A use absolute (X, Z) or incremental (U, W) coordinates directly in the return block. Milling systems and machining centers specify absolute coordinate addresses (X, Y, Z). On Mitsubishi systems, the P parameter can be appended to designate which of the reference positions to return to. On Siemens controls, the system must switch to ISO Dialect mode using G291 before G28 can be parsed.

Syntax for Lathe/Turning Systems:

G28 X... Z... ;  (Absolute Coordinates)
G28 U... W... ;  (Incremental Coordinates)

Syntax for Milling/Machining Systems:

G90 G28 X... Y... Z... ;  (Absolute Coordinates)
G91 G28 X... Y... Z... ;  (Incremental Coordinates)

Parameter Specifications:

Address / ParameterDescriptionApplicable Brands
X, Y, ZCoordinates of the intermediate waypoint in absolute positioning mode.Fanuc, Siemens, Mitsubishi
U, WIncremental coordinate values for target axes checks (System A).Fanuc, Mitsubishi

Brand Applications

Fanuc

Fanuc controls execute G28 as a native Group 00 preparatory command that compares coordinates directly at the kernel level. Setup parameters like Parameter 3401 Bits 7 and 6 dictate whether the coordinates are processed using G-code System A, B, or C. If coordinates match, the control panel status LEDs light up.

Programmers must cancel compensations using G40 and Txx00 in the same block. For example, G28 G40 U0 W0 T0300 M05 ; checks the absolute reference point of X and Z axes while canceling tool nose radius compensation and tool offsets.

System CategoryIdentifier / CommandApplication Detail
ParametersParameter No. 3401 Bit 7 (GSC) & Bit 6 (GSB)Selects the active G-code system (A, B, or C) for coordinate interpretation.
ParametersParameter No. 3402 Bit 6 (CLR)Determines if Group 00 modal G-codes return to clear states on reset.
ParametersParameter No. 3402 Bit 0 (G01)Sets default motion state (rapid G00 vs linear G01) on reset.
ParametersParameter No. 5040 Bit 3 (TCT)Enables tool length compensation (+/-) G43/G44 on active axes.
AlarmsAlarm PS0092Axes complete G28 but fail to align precisely with true machine zero (LED fails to light).
AlarmsAlarm PS0187Illegal command triggered if G28 is executed during scaling (G51), mirror image (G51.1), or rotation (G68).
AlarmsAlarm PS0325Triggered if G28 is specified inside finishing shape program blocks of cycles like G71 or G72.
VersionsLathe G-code systemsLathe systems select G-code Systems A, B, or C; System A uses address letters (X/Z vs U/W) for absolute/incremental.
VersionsLegacy Series 15Handles compensation data and canned cycles differently, disabling standard multi-block repeat parameters.

Warning: Programmers must deactivate coordinate rotation with G69 before commanding a home return, as executing G28 while coordinate rotation (G68) is active will trigger Alarm PS0187.

Siemens

Siemens controls process G28 using an ISO Dialect wrapper. Under the hood, SINUMERIK does not run a kernel-level command; instead, it executes a background macro program named cycle328.spf. This macro uses MD 34100 to define the physical coordinate positions of the reference points.

To execute the check, the control must be placed in ISO Dialect mode using G291. For example, programming G91 G28 X0 Y0 Z0 ; will check the reference coordinates of the X, Y, and Z axes using the cycle328.spf macro.

System CategoryIdentifier / CommandApplication Detail
ParametersMD 34100 $_MA_REFP_SET_POSDefines reference coordinate values for points 1 to 4 (index 0 to 3).
ParametersMD 18800 $MN_MM_EXTERN_LANGUAGEEnables external ISO Dialect language interpreter.
ParametersMD 20154 $MC_EXTERN_GCODE_RESET_VALUES[n]Determines default G-codes (absolute/incremental) in external language on reset.
AlarmsAlarm 61800External CNC system missing; triggered if MD 18800 is not activated.
AlarmsAlarm 61004Configuration of geometry axis not correct inside underlying cycle328.spf macro.
AlarmsAlarm 14800Programmed path velocity or default feed is zero or unconfigured.
VersionsSINUMERIK 802D sl vs. 840D sl802D sl has write-protected channel G-code reset variables, while 840D sl allows full modification.

Warning: Ensure that active coordinate transformations are fully deactivated using TRAFOOF before G28 execution, as unresolved transformations will cause cycle328.spf to fail and trigger Alarm 61004.

Mitsubishi

Mitsubishi CNC systems process G28 as a Group 00 unmodal instruction linked directly to the PLC. The controller uses axis-specific parameter #2037 to store the reference coordinate offsets from the machine zero. Once coordinates are matched, the system outputs a zero point arrival signal.

Programmers can specify which of the four reference positions to check using the P address. For example, G28 U0 W0 T0300 ; checks the primary reference position, while canceling offsets.

System CategoryIdentifier / CommandApplication Detail
ParametersParameter #2037 G53ofsAxis-specific reference coordinate offsets for reference points 1 to 4.
ParametersParameter #1443 G28olEnables G28 rapid traverse block overlap function when set to 1.
ParametersParameter #2633 G28olinpsSets in-position check width for rapid traverse block overlap.
ParametersParameter #1091 Ignore middle pointBypasses intermediate point when set to 1, returning directly to home.
AlarmsProgram Error (P430)G29 executed after power-on without first executing G28 or G30 to record waypoint.
AlarmsProgram Error (P931)G28 commanded while tool axis length compensation (G43.1) is active.
AlarmsOperation Error (M01 0013)Mode switched to MDI or reference position return during waypoint stop.
AlarmsOperation Error (M01 0129)PLC interrupt operation initiated while paused at waypoint stop.
AlarmsProgram Error (P10)G28 commanded to two or more rotary axes simultaneously on M80/M830 systems.
VersionsM80 / M830 SeriesLinear axes forced to shift to accommodate active offsets, triggering P10 if multiple rotary axes homed.
VersionsC80 SeriesG28 integrates with ZR variables (#50000 to #52749). G26 is tapped retract instead of spindle monitor.

Warning: Command conflicts exist with the G26 code on Mitsubishi C80 Series, where it triggers an automatic machining interruption retraction cycle rather than Spindle Speed Fluctuation Detection.

Brand Comparison

Feature / AttributeFanucSiemensMitsubishi
G-Code ExecutionExecuted natively within NCK motion kernel as a Group 00 unmodal command.Bypassed natively; executed in ISO Dialect mode via cycle328.spf background macro.Executed natively as a Group 00 unmodal command.
Coordinate TransformationRequires manual cancellation of active compensation frames.Macro automatically deactivates transformations via TRAFOOF before referencing.Processes directly and can send physical zero-arrival signals to PLC for loader handshaking.
Reference Positions & CyclesRigid Group 00 unmodal return using Parameter No. 3402.Maps reference positions to axis machine data MD 34100 $_MA_REFP_SET_POS.Supports up to 6 tool change positions (G30.1-G30.6) and overlap parameters #1443 G28ol.
G26 Command ClashActivates Spindle Speed Fluctuation Detection.— (no source)Triggers Machining Interruption tool retraction recovery cycle.

Technical Analysis

The underlying architectural differences between Fanuc, Siemens, and Mitsubishi controls determine how the G28 home return cycle interacts with coordinate system registers and physical axis motion loops. On Fanuc and Mitsubishi controls, G28 is executed as a native kernel-level command. This means the motion loop and axis positioning interpolator process the intermediate and reference coordinates directly, generating physical signal outputs such as operator panel LEDs (Fanuc) or PLC zero-arrival registers (Mitsubishi) upon completion. Conversely, Siemens SINUMERIK controls do not execute G28 natively within the NCK kernel. Instead, they require the programmer to activate ISO Dialect mode via G291, which routes the G28 command through a background macro program named cycle328.spf. This macro-based execution deactivates active kinematic frames using the native TRAFOOF command and evaluates coordinates via software offsets before executing the reference point approach.

Another distinct contrast exists in how these brands manage multiple reference points and rapid traverse dynamics. Mitsubishi systems provide highly flexible reference structures, allowing programmers to utilize up to six dedicated tool change coordinates (G30.1 to G30.6) and configure block overlap parameters (#1443 G28ol and #2633 G28olinps) to optimize cycle times. Fanuc relies on a more rigid Group 00 structure, where Parameter No. 3402 dictates coordinate clear states and tool compensations must be manually managed. Cross-platform command conflicts also introduce severe collision risks on the shop floor. A prime example is the G26 command, which represents Spindle Speed Fluctuation Detection on Fanuc, but represents Machining Interruption (tapping retract retraction macro) on Mitsubishi controls. Running a Fanuc G-code program containing a G26 block on a Mitsubishi control will trigger an unexpected axis retraction, driving the tool body directly through raw material and leading to a catastrophic hard collision.

Program Examples

Fanuc Example

G91 G28 X0 Y0 Z0 ; Incremental reference return with zero intermediate distance
G28 Z0.1 M09 ; Absolute mode Z-axis return via waypoint Z0.1, turning off coolant
G28 U0 W0 T0300 M05 ; Lathe incremental return for X/Z axes, canceling offsets and stopping spindle
M30 ; Program end

Dry Run Verification

Perform a first-article dry run with the spindle stopped and the workpiece removed from the workholding. Prior to execution, manually reference all axes to establish the machine coordinate system. Activate dry run mode on the operator panel and run the program. The axis slides will execute the G28 block by transitioning directly from their current position to the machine zero home position without performing any intermediate travel. Once home is reached, verify that the reference position LEDs on the control panel illuminate. If the axes stop before reaching home or the LEDs fail to light, check for active offsets and verify Alarm PS0092 status.

Siemens Example

G291 ; Switch SINUMERIK control to ISO Dialect mode
G28 Z150.0 M09 ; Retract Z-axis to intermediate coordinate Z150.0 and turn off coolant
G91 G28 X0 Y0 Z0 ; Command incremental home return with zero waypoint distance
G290 ; Switch back to native Siemens mode
M30 ; Program end

Dry Run Verification

Ensure that MD 18800 is active to allow ISO Dialect parsing. Perform a dry run with feedrate override dialed down. Run the program. The control will call the cycle328.spf background macro to process G28. The tool should traverse to the intermediate point before moving to the machine zero reference point defined in MD 34100. If the coordinates do not match the machine data setting, the cycle macro will halt execution, display Alarm 61800 or Alarm 61004, and suppress the cycle start light.

Mitsubishi Example

G91 G28 X0 Y0 Z0 ; Execute incremental home return with zero distance waypoint
G28 Z150.0 M09 ; Absolute reference return driving Z-axis to intermediate Z150.0 and turn off coolant
G28 U0 W0 T0300 ; Lathe system incremental zero return, canceling tool offsets
M30 ; Program end

Dry Run Verification

Ensure Parameter #2037 G53ofs is set with the correct machine offsets. Run the program with a dry run feedrate. The axes will move to the programmed coordinates before returning to the machine home. Monitor the screen to confirm that the axes verify their arrival. Once complete, confirm that the control sends the zero-arrival signal to the PLC.

Error Analysis

BrandAlarm CodeTrigger ConditionOperator SymptomRoot Cause / Fix
FanucAlarm PS0092Axes complete G28 travel but fail to align precisely with physical machine zero.Reference return LED fails to light; automatic cycle start is deactivated.Cancel all active compensations (G40, G49, Txx00) prior to commanding G28.
FanucAlarm PS0187G28 is executed while coordinate rotation (G68), scaling (G51), or mirror imaging (G51.1) is active.Execution halts; Alarm PS0187 appears on screen.Deactivate coordinate rotation (G69) or scaling (G50) before executing G28.
FanucAlarm PS0325G28 specified within sequence numbers P and Q of canned cycles like G71 or G72.Program stops with Alarm PS0325.Remove travel commands from canned cycle finishing shape definitions.
SiemensAlarm 61800G28 executed without activating external ISO Dialect interpreter machine data.Cycle stops immediately with Alarm 61800.Activate MD 18800 (or options bit 19800).
SiemensAlarm 61004Incorrect geometry axis configuration within the underlying cycle328.spf background macro.Execution halts inside background macro; Alarm 61004 displays.Verify channel geometry axis assignments and ensure they align with cycle328.spf.
SiemensAlarm 14800G28 commanded but programmed path velocity or default feed is zero or unconfigured.Cycle halts with Alarm 14800.Specify a valid path feedrate or velocity.
MitsubishiProgram Error (P430)G29 executed after power-on without first executing G28 or G30 to record waypoint.NC execution stops with Program Error (P430) displayed.Program and execute G28 or G30 first to store the intermediate waypoint.
MitsubishiProgram Error (P931)G28 commanded while tool axis length compensation (G43.1) is active.NC execution stops with Program Error (P931).Deactivate G43.1 tool compensation beforehand.
MitsubishiOperation Error (M01 0013)Mode switched to MDI or reference position return during single-block waypoint stop.Execution stops with Operation Error (M01 0013).Avoid switching modes at waypoint.
MitsubishiOperation Error (M01 0129)PLC interrupt operation initiated while paused at single-block waypoint stop.Execution stops with Operation Error (M01 0129).Do not trigger PLC interrupts at waypoint.
MitsubishiProgram Error (P10)G28 commanded to two or more rotary axes simultaneously on M80/M830 systems.NC stops with Program Error (P10).Program G28 returns for rotary axes individually.

Application Note

A catastrophic turret collision and shattered cutting tools occur when a programmer commands G90 G28 X0 Y0 Z0 with an active workpiece coordinate system. Because absolute mode is active, the CNC control interprets the target coordinates as the intermediate waypoint, forcing the tool turret to rapid-traverse directly to the G54 workpiece origin. On a machine table equipped with a table-mounted vise jaw, workpiece clamps, or a chuck, the spindle assembly will plunge directly into the workholding, causing high-speed impact damage, bending the turret, and producing a scrap part. To eliminate this risk, programmers must enforce the use of incremental mode (G91 or incremental coordinates like U0 W0) to force the intermediate travel distance to equal zero, ensuring a direct, unobstructed path home.

Related Command Network

  • G27 (Reference Position Check): Verifies whether the axes have arrived precisely at the machine reference coordinate without performing a permanent return.
  • G22 (Stored Stroke Limit Check On): Activates the stored stroke limit check function to establish a software safety boundary.
  • G00 (Rapid Traverse Positioning): Commands the axes to traverse at maximum rapid rate to programmed coordinates.
  • G29 (Return from Reference Position): Commands the axes to return to a programmed position by moving back through the intermediate waypoint stored during the preceding G28 cycle.
  • G30 (Return to 2nd, 3rd, or 4th Reference Position): Traverses the axes to secondary reference positions (such as tool change points) defined in the control parameters.

Conclusion

Establishing a reliable reference routine is essential for maintaining machine alignment and avoiding high-speed turret collisions during automatic tool changes. Programmers must enforce incremental commands (G91 or incremental addresses) and cancel all offsets before executing home return blocks. This programming discipline guarantees that axes retract directly to their physical reference coordinates, protecting expensive spindles and ensuring consistent part quality in automated production runs.

FAQ

How does G28 handle active tool compensations when returning to machine home?

During G28 execution, the control cancels tool length and radius compensations at the intermediate point. If offsets are left active (without G40 or G49/Txx00), the retraction trajectory will shift by the offset amount, risking collision with fixtures. Programmers must place G40 and G49 or tool cancel codes (like T0100 to cancel offset 01 on Fanuc) in the block immediately preceding or containing G28.

Why does a Siemens SINUMERIK control require G291 to execute a G28 command?

Siemens controls process G28 through an ISO Dialect interpreter macro (cycle328.spf) rather than running it natively. If G28 is commanded in native Siemens mode (G290), the machine data will reject the syntax or fail to execute the motion. Programmers must switch the channel to ISO mode by writing G291 before G28, and restore native mode with G290 after the return cycle is complete.

What is the difference between G28 and G30 reference returns?

G28 returns the machine axes to the primary reference point (machine zero), whereas G30 returns them to secondary, tertiary, or quaternary reference coordinates (such as tool change or loading positions). In terms of setup, G30 positions are defined by distinct parameter registers (such as index 1 of MD 34100 on Siemens or Parameter 2037 on Mitsubishi). Operators should use G30 when the tool needs to retract to a specific intermediate clearance plane rather than the absolute machine zero limit.

Still not resolved?

Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

Ask AI Assistant
Hakan Gündoğdu
Hakan Gündoğdu
  • CNC CARE Co-Founder (May 2025 - Present)
  • Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
  • Reis CNC Service Engineer (2003 - 2008)
  • Ören Kalıp CNC Mold Line Team Leader (1999 - 2002)

With over 25 years of experience working in all areas of the CNC machine industry, I continue my activities as a co-founder of CNC CARE, where we offer brand-independent consulting, engineering, and original spare parts services.

Related Articles

Other articles on this topic