In the field of precision machining, the Post Processor plays a critical role as a “translator,” converting data from CAM software into machine language (G-code/M-code) that CNC controllers can interpret and execute. Mastering the G & M code system in CNC programming is not only a mandatory requirement for machine operators but also a fundamental foundation for developing optimized Post Processors that ensure accuracy and operational safety. Even a minor error in code definition can lead to serious consequences, including damage to cutting tools, workpieces, or even the machine spindle.

Các mã G&M bạn cần biết khi phát triển CNC Post Processor
Essential G & M Codes You Need to Know When Developing a CNC Post Processor

1. Basic Motion Commands

These are the most fundamental commands that every Post Processor must accurately define to ensure the cutting tool follows the correct toolpath.

1.1. G0, G1, G2, G3 Commands

  • G0 (Rapid Motion): Enables the machine to move at maximum speed (rapid traverse) to a specified position. This command is not used for cutting operations.
  • G1 (Cutting Motion): Performs controlled linear cutting motion with a specified feed rate.
  • G2/G3 (Circular/Helical Interpolation): Executes circular or helical movements. G2 represents clockwise (CW) motion, while G3 represents counterclockwise (CCW) motion.

1.2. Accuracy Control with G61/G64

  • G61 (Exact Stop Check): Forces the machine to come to an exact stop at sharp corners before changing direction. This ensures geometric accuracy but may leave marks on the workpiece.
  • G64 (Continuous Cutting): In contrast to G61, this command allows the machine to generate very small corner radii to maintain continuous motion without stopping, resulting in smoother surface finishes.
Nhóm lệnh chuyển động cơ bản
Basic Motion Commands

2. High-Precision and Timing Control Commands

2.1. G4 (Dwell) Command

Used to pause the program for a specified period of time. This is commonly applied during hole-bottom drilling or when transitioning between motion directions.

Syntax: G4 P__ (P in milliseconds) or G4 X__ (X in seconds)

Example: G4 P1000 or G4 X1.0 both indicate a 1-second pause in the program.

2.2. G5.1 High-Precision Machining Command

This command is especially critical in mold and die machining, where precise control of motion accuracy and contour deviation is required.

  • Syntax: G5.1 Q1 R__ (Activation with levels from R1 to R10)
  • R1: Rough machining
  • R5: Semi-rough machining
  • R10: Finish machining
  • Cancel: Use G5.1 Q0

Note: As the R value increases, the machine prioritizes higher accuracy and may automatically reduce the feed rate along curved segments. 

Các lệnh thiết lập thời gian và độ chính xác cao 
High-Precision and Timing Control Commands 

3. Coordinate System Setup and Offsets with G10

The G10 command is extremely powerful for defining offset values programmatically, eliminating the need for manual input on the machine control panel.

  • L2: Set Work Offsets (G54, G55, etc.)
  • L10: Tool length offsets
  • L11: Tool length wear offsets
  • L12: Tool radius offsets
  • L13: Tool radius wear offsets

Typical Examples:

  • G90 G10 L2 P1 X-250. Y300: Sets the G54 origin (P1) at X-250 and Y300 relative to the machine zero.
  • G91 G10 L10 P5 R0.8: Increases the length of tool #5 by 0.8 mm (incremental mode).
  • G91 G10 L12 P4 R0.2: Increases the radius of tool #4 by 0.2 mm.

4. Machining Planes and Units

4.1. Plane Selection Commands G17/G18/G19

  • G17: XY plane (commonly used in milling)
  • G18: XZ plane (commonly used in turning)
  • G19: YZ plane

Selecting the correct plane is essential for proper execution of G2/G3 commands, tool radius compensation, and drilling cycles.

4.2. Unit Commands G20/G21

  • G20: Sets units to inches
  • G21: Sets units to millimeters (mm)

5. Reference Return Commands G28/G30

These commands move the tool back to the machine’s reference position (home) or an intermediate reference point.

  • G28: Return to machine home position
  • G30: Return to secondary reference position (commonly used for tool changes)

Operational Examples:

  • G90 G28 X100. Y100. Z50: The machine first moves to (100, 100, 50), then returns to home.
  • G28 U0. W0: Direct return to home (commonly used on lathes).
  • G91 G30 X200. Y100. Z100: The machine moves incrementally by (200, 100, 100), then returns to the G30 position.
Lệnh về điểm tham chiếu G28/G30 
Reference Return Commands G28/G30 

6. Advanced Multi-Axis Programming (Multi-axis Commands)

For Post Processors designed for 4-axis and 5-axis machines, the following commands are critical to ensuring machining accuracy.

6.1. G43.4 (TCPM – Tool Center Point Management)

Allows programming based on the tool tip position rather than the machine’s pivot center. When G43.4 is activated, the tool tip remains fixed relative to the workpiece even as rotary axes move.

Syntax: G1 G43.4 X__ Y__ Z__ H__ F__ (H = tool length offset number)

6.2. G68.2 and G53.1 (Tilted Working Plane)

  • G68.2: Defines a tilted working plane by rotating the coordinate system around the I, J, K axes.
  • G53.1: Automatically rotates the machine’s physical axes (table or head) to align perpendicular to the plane defined by G68.2.

Example: G68.2 X0 Y0 Z0 I0 J0 K90 (Rotate 90 degrees about the Z-axis)

7. Hole Machining Cycles (Canned Cycles)

Developing a Post Processor requires precise definition of parameters within canned cycles to ensure safe and efficient machine operation.

7.1. Drilling Cycles G81/G82

  • G81: Standard drilling cycle
    G81 X__ Y__ Z__ R__ F__
  • G82: Drilling cycle with dwell time (P) at the hole bottom for improved surface finish

Example: G99 G82 X20. Y40. Z-20. R5. P2. F300 (Pauses for 2 seconds at the bottom, then retracts to the R level)

7.2. Peck Drilling Cycles G73/G83

  • G73: High-speed peck drilling (short retracts within the cutting zone)
  • G83: Deep-hole peck drilling with full retract to the R level for chip evacuation
  • Parameter Q: Defines the depth of each peck (peck depth)

7.3. Tapping Cycle G84

Must be used in conjunction with M29 to synchronize spindle speed (S) and feed rate (F).

  • Formula: Thread pitch = F / S
  • Example: M29 S500; G84 X50. Y40. Z-15. R5. P3. F250.
    (Thread pitch = 250 / 500 = 0.5)

7.4. Boring Cycle G85

Used for hole enlargement or finish boring operations. Syntax: G85 X__ Y__ Z__ R__ F__ K__ (K = number of repetitions)

Các chu trình gia công lỗ
Hole Machining Cycles (Canned Cycles)

8. Subprogram Calls and Macro Programming with G65

Post Processors can use G65 to pass parameters into complex subprograms.

  • G65 P__: Calls subprogram number P
  • The accompanying letters assign values to corresponding variables within the subprogram (e.g., A = #1, D = #7, etc.)

Example: G65 P1234 A15 D26 assigns #1 = 15 and #7 = 26 inside subprogram O1234.

9. M-Code Group (Miscellaneous Functions)

  • M0/M1: Program stop (unconditional or optional)
  • M2/M30: End of program (M30 returns to the program start)
  • M3/M4/M5: Spindle clockwise (CW), counterclockwise (CCW), or stop
  • T/M6: Tool change on machines with a tool magazine: T5 M6; On lathes (turret): T0709 (Tool 7, Offset 9)
  • M8/M9: Coolant ON/OFF
  • M98/M99: Call and end subprogram

10. Frequently Asked Questions about G & M Code Programming

10.1 Why use G98 and G99 in drilling cycles?

G98 retracts the tool to the initial position (initial safe Z level), while G99 retracts only to the R level.
G98 is typically used when the tool needs to clear fixtures or obstacles between holes.

10.2 How does G12.1 (Polar Coordinate Interpolation) work?

This function converts the Y-axis into a C-axis on lathes. When programming a contour using X and Y coordinates, the machine automatically calculates the synchronized motion of the X and C axes to generate the desired geometry.

10.3 What is the difference between G32 and G33 in thread cutting?

G32 can be used for both straight and tapered threading, while G33 is primarily used for straight threads.
Both require a constant feed rate (F) corresponding to the thread pitch.

Mastering the full range of G & M codes in CNC programming is the key to developing high-quality Post Processors, ensuring smooth machine operation and extending tool life. At SDE Tech, we are committed to delivering professional CAM solutions and customized Post Processor services, helping manufacturers optimize machining performance and productivity. We hope this detailed compilation, along with practical examples, will serve as a valuable reference for your daily work. Please feel free to contact us if you need further consultation on CNC solutions.

  • Website: sde.vn
  • Email: sales@sde.vn
  • Hotline/Zalo: 085 256 2615 – 0909 107 719

Leave a Reply

Your email address will not be published. Required fields are marked *