G28 CNC Code | Reference Point Return

Mastering G28: The CNC Reference Point Return Command

In CNC machining, the machine reference point (home position) is a fixed, known location within the machine’s travel limits. It serves as the absolute origin of the machine coordinate system. The G28 G-code is used to command a return to this reference point. However, the way G28 behaves depends critically on whether the machine is in absolute (G90) or incremental (G91) mode. Understanding this difference is essential for safe and predictable machine operation.

This article provides a comprehensive guide to using G28 on both CNC lathes and machining centers (mills), covering:

  • The concept of the machine reference point.
  • The two distinct behaviors of G28 (with G90 and G91).
  • Syntax and examples for Fanuc (and similar) controls.
  • Applications on lathes and mills.
  • G30
  • Interaction with other G-codes.
  • Control-specific considerations (Fanuc, Siemens, Haas, Mazak, Mitsubishi).
  • Troubleshooting tips.
  • The role of CAM software.

Crucial Note: Always consult the programming manuals for your specific CNC control system and machine tool. While G28 is generally standardized, there might be subtle variations or machine-specific behaviors.

1. The Machine Reference Point (Home Position)

Every CNC machine has a machine reference point, also known as machine zero or home position.

  • Fixed Location: This is a fixed, physical location within the machine’s travel limits, determined by the machine tool builder (MTB).
  • Machine Coordinate System Origin: It serves as the absolute origin (0, 0, 0) of the machine coordinate system. All other coordinate systems (work offsets, etc.) are ultimately referenced to this point.
  • Homing: When you power on a CNC machine, it usually needs to be “homed” (referenced). This involves moving each axis to its reference point, often by triggering limit switches or using encoder feedback. This process establishes the machine’s current position relative to machine zero.

2. G28: Return to Reference Point - Two Different Behaviors

The G28 command instructs the machine to return to its reference point. However, the way it does this depends critically on the active coordinate system mode:

  • G90 (Absolute Mode) + G28: In absolute mode, any axis words (X, Y, Z, etc.) specified with G28 are interpreted as an intermediate point in the current work coordinate system (e.g., G54). The machine will move to this intermediate point first, and then continue to the reference point.
    • Warning: Using G28 with G90 and specifying an intermediate point can be dangerous if the intermediate point is not carefully chosen. The machine will make a rapid move to that point before going home, potentially causing a collision.
    • If no axis words are specified with G28 in G90 mode, the behavior is control-specific. Some controls might treat it as a direct return to reference (like G91 G28 X0 Y0 Z0), while others might generate an alarm or exhibit unpredictable behavior. Always check your manual.
  • G91 (Incremental Mode) + G28: In incremental mode, any axis words specified with G28 are interpreted as incremental distances from the current position. This is the most common and recommended way to use G28.
    • G91 G28 X0 Y0 Z0 (Mill) or G91 G28 U0 W0 (Lathe): This commands a direct return to the reference point for the specified axes. The X0 Y0 Z0 (or U0 W0) values are not an intermediate point; they are incremental distances of zero. This means, “move zero distance from the current position along each axis, and then go to the reference point.” Since moving zero distance doesn’t change the position, the result is a direct return to home.
    • Best Practice: It’s common and recommended to home one axis at a time, especially on mills:
G91 G28 Z0 ; Home the Z-axis first (retract the tool)
G91 G28 X0 Y0 ; Then home the X and Y axes

3. Syntax (Fanuc and Similar Controls)

The general syntax (although the behavior is what matters, as explained above) is:

G28 X... Y... Z... A... B... C... ;  (With or without intermediate point)
  • G28: The reference point return command.
  • X..., Y..., Z... (and rotary axes A..., B..., C...): These are optional axis words.
    • G90 (Absolute): These represent an intermediate point in the active work coordinate system.
    • G91 (Incremental): These represent incremental distances from the current position. X0 Y0 Z0 means “return directly to reference.”
  • No Required Parameters It is very common to use G28 without any axis words, especially on lathes.

4. G30 (2nd, 3rd, and 4th Reference Point Return)

  • The command G30 is used to return to a position other than machine home.
  • The syntax for the command is: G30 Pn X... Y... Z...
    • Pn: Defines which reference point. P2 is the second, P3 the third, and P4 the fourth. P1 is also possible, but this will return the machine to home, which can also be done with G28.

5. Applications on CNC Lathes

On CNC lathes, G28 is most commonly used with G91 (incremental mode) for a safe and direct return to the reference point:

  • G28 U0 W0: This is the standard and safest way to home a lathe. U and W are the incremental axes parallel to X and Z, respectively. U0 W0 means “move zero distance in the incremental system,” resulting in a direct return to the reference point.

Example (Lathe - Safe Homing):

G28 U0 W0 ; Return to reference point (home) directly and safely

Common Uses:

  • Tool Changes: Return the turret to a safe position for a tool change.
  • End of Program: Return the machine to a known, safe position at the end of the program.
  • After Manual Jogging: If you’ve manually moved the axes, use G28 U0 W0 to ensure the machine is back at its reference point before resuming automatic operation.

6. Applications on CNC Machining Centers (Mills)

On machining centers, G28 is also commonly used with G91 (incremental mode):

  • G91 G28 Z0: This is the standard way to home the Z-axis (retract the tool) first, before homing the other axes. This is a crucial safety practice to prevent the tool from colliding with the workpiece or fixtures.
  • G91 G28 X0 Y0 Z0: This homes all three axes (X, Y, and Z) directly.
  • G91 G28 X0 Y0: Homes X and Y.

Example (Mill - Safe Homing and Tool Change):

G91 G28 Z0 ; Home the Z-axis first (retract tool)
G91 G28 X0 Y0 ; Then home the X and Y axes
T02 M06 ; Tool change
; ...

Common Uses:

  • Tool Changes: Retract the tool to a safe height (G91 G28 Z0) and then move to the tool change position.
  • End of Program: Return the machine to a known, safe position.
  • After Manual Jogging: Verify the machine’s position before resuming automatic operation.

7. Interaction with Other G-Codes

  • G90/G91 (Absolute/Incremental): Critically affects the behavior of G28. G91 G28 is the recommended usage for direct return.
  • G53 (Machine Coordinate System): G28 (and G30) move the machine within the machine coordinate system. G53 can be used to temporarily select the machine coordinate system for other movements.
  • G54-G59 (Work Offsets): G28 returns to the machine reference point, not the work offset. Be very clear about this distinction.
  • G27: Checks to see if machine is at the home position.

8. Control-Specific Variations

  • Fanuc: G28 is standard, with the behavior described above. The behavior of G28 alone (without axis words) in G90 mode can vary – check your manual.
  • Siemens: Siemens controls use G28 for reference point return, with similar behavior to Fanuc.
  • Haas: Haas controls use G28, and the G91 G28 combination for direct return is standard practice.
  • Mazak: G28 is standard for reference point return. In Mazatrol, the homing procedure might be handled differently.
  • Mitsubishi: G28 is standard.
  • Other Controls: Always consult your documentation.

9. Troubleshooting

  • Unexpected Movements:
    • G90/G91 Confusion: The most likely cause of problems with G28 is using it in G90 mode with unintended intermediate point coordinates. Always use G91 G28 for direct return unless you have a very specific reason not to.
    • Incorrect Intermediate Point (G90): If you are using G28 with G90 and an intermediate point, make sure that point is safe and within the machine’s travel limits.
  • “Overtravel” Alarms: This can occur if the intermediate point in G90 mode is outside the machine’s limits.
  • Machine Not Homing Correctly: This is usually a mechanical or electrical problem (limit switches, encoders, etc.), not a programming error with G28 itself.

10. CAM Software

CAM software typically handles G28 automatically, generating the appropriate G91 G28 sequence for safe return to the reference point (often with Z-axis retraction first). You usually don’t need to program G28 manually when using CAM. However, it’s essential to:

  • Verify the Post-Processor Settings: Ensure the post-processor is configured correctly for your machine and control, including the correct homing sequence.
  • Check the Generated Code: Always review the generated G-code, including any G28 commands, before running it on the machine.

11. Frequently Asked Questions (FAQ)

  • Q: What’s the difference between G27 and G28?
    • A: G27 checks if the machine is at the reference point; it doesn’t move the machine. G28 commands a move to the reference point.
  • Q: What’s the safest way to use G28?
    • A: Use G91 G28 Z0 (to home Z first on a mill) followed by G91 G28 X0 Y0 (or G28 U0 W0 on a lathe).
  • Q: Can I use G28 with absolute coordinates (G90)?
    • A: Yes, but be extremely careful. Any axis words specified with G28 in G90 mode are treated as an intermediate point in the current work coordinate system. This is not generally recommended for beginners.
  • Q: What happens if I use G28 without any axis words? * A: The behavior is control-specific, and you must check the manual.
  • Q: Does G28 use the work offset (G54, etc.)? * A: No, G28 moves to the machine reference point, not a work offset.

12. Conclusion

The G28 G-code is a fundamental command for returning your CNC lathe or mill to its reference point (home position). However, its behavior depends critically on whether you’re in absolute (G90) or incremental (G91) mode. G91 G28 Z0 (mills) and G91 G28 U0 W0 (lathes) are the standard and safest ways to use G28. G27 is a separate command that checks the current position against the reference point, without commanding any movement. Always consult your machine’s documentation, understand the implications of G90 and G91, and use CAM software for complex operations. By mastering G28 (and understanding the difference from G27), you can ensure safe and efficient machine operation.