Murray State University School of Engineering CourseWiki

CNC Program Structure

Read program identifiers, startup modes, machine functions, feed modes and drilling cycles in common milling G-code.

A block can combine motion, settings and machine functions

A block can combine motion, settings and machine functions

A word is a letter and value, such as X12 or F100. A block is a line of words. The control applies its execution rules; words are not necessarily executed in left-to-right typing order. N numbers label blocks and are often optional. Many Fanuc-style programs use an O number such as O2468 as the program identifier. File naming, percent delimiters and identifiers vary by control.

A modal command stays active until replaced or cancelled within its group. G01 can remain active while G90 changes to G91, because motion and distance mode are different groups. A startup line sets specific modes; it does not clear every stored setting or offset.

A safe-start line declares assumptions; it does not prove the setup

A safe-start line declares assumptions; it does not prove the setup

A common milling startup example is G17 G21 G90 G94 G40 G49 G80: XY plane, millimetres, absolute endpoints, feed per minute, cutter compensation cancelled, tool-length compensation cancelled and canned cycles cancelled. This is a reading example, not a universal restart line. Cancelling an offset changes the coordinate relationship; startup and restart sequences must match the actual control and tool position.

  1. Identify the program and establish required units, plane and modes.
  2. Select the intended work coordinate system and tool; apply the correct offset data.
  3. Establish spindle, feed and coolant settings for the operation.
  4. Perform positioning and machining blocks, including any cycle cancellation.
  5. Use the machine-approved retract and shutdown sequence, then end the program.

The order and motion details around tool changes and offset activation require the machine manual. See CNC Axes and Offsets and CNC Programming and Prove-Out.

Separate spindle, tool and coolant commands from motion; Practice

Separate spindle, tool and coolant commands from motion

These are common Fanuc-style meanings, not a promise for every machine.

CodeCommon meaningRead with it
M03 / M04 / M05Spindle clockwise / counterclockwise / stopS sets the speed value. Direction is conventionally viewed from the spindle toward the work; confirm machine orientation.
M06Tool change on many millsT selects a tool. The changer may be manual or automatic; offset activation is a separate issue.
M08 / M09Flood coolant on / coolant offAvailable coolant systems and auxiliary M codes depend on the machine.
M30End program and commonly reset/rewindIt does not command a return to machine or work zero, and does not mean automatically run another part.

For example, S1800 M03 requests 1800 rpm in a fixed-rpm mode; it is not a cutting recommendation. A lathe using constant surface speed interprets S differently. See Feeds and Speeds.

Practice code meanings

Units, feed mode and plane answer different questions

Units, feed mode and plane answer different questions

SettingCommon milling interpretation
G20 / G21Inch / millimetre length units.
G94 / G95Feed in units per minute / units per spindle revolution, where supported.
G17 / G18 / G19XY / XZ / YZ plane for plane-dependent operations such as arcs.
G00 / G01Rapid positioning / straight-line motion at programmed feed.
G02 / G03Clockwise / counterclockwise arc in the selected plane.

In G21 G94, F90 means 90 mm/min. In G21 G95, F0.15 means 0.15 mm/rev; at 600 rpm that corresponds to 90 mm/min. G20/G21 alone does not choose the time basis. Some lathes use G98/G99 for feed mode, while mills commonly use those codes for drilling return levels.

Rapid path shape depends on the control and can differ from G01. G01 may feed through air as well as cut. Learn the motion and arc geometry in G-code and Toolpaths, including the existing simulator; learn distance modes in Absolute and Incremental Positioning.

G81 and G83 repeat a drilling sequence at hole locations

G81 and G83 repeat a drilling sequence at hole locations

A canned cycle packages repeated motions. In common milling use, G81 feeds a drill to depth then retracts; G83 divides the depth into pecks with retracts for chip clearance. X/Y locate the hole, Z specifies the drill-tip depth, R specifies a return/approach plane, F sets feed, and Q commonly specifies peck depth for G83. Q is not the final hole depth.

With G90 on a conventional mill, Z and R are coordinates in the active work system. Incremental canned-cycle rules need separate study in the manual. G98 commonly returns to the initial level and G99 to R; choose a return level for the actual setup. G80 cancels the cycle. Modal hole cycles can drill again at subsequent position blocks.

The simulator in G-code and Toolpaths demonstrates G81, not G83. See Tormach's programming reference for control-specific modes and cycles, and the Haas lathe manual for examples of meanings that differ from milling.