Objective. Students write syntactically correct G-code blocks using proper word-address format, define every field in a program header and footer, and explain the difference between modal and non-modal codes.
This lesson, its worked examples and its practice questions has not yet been verified by a licensed engineer or certified journey-level tradesperson or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Every line of G-code you write follows a convention called word-address format. A word is a single letter (the address) paired with a number (the value). For example, `X1.500` is one word: address `X`, value `1.500`. A complete line of G-code is called a block. A block is a sequence of words that the control reads and executes as one command.
The general structure of a block looks like this:
```
N0010 G01 X1.500 Y-0.750 Z-0.100 F15.0
```
The control reads left to right within the block, but on Haas controls the order of word types is largely fixed by convention: N, G, axis words, feed/speed, M. Always follow the format your control expects.
Each letter of the alphabet has a defined role in CNC. The most common ones you will use every day:
| Address | Meaning |
|---------|---------|
| O | Program number |
| N | Block sequence number |
| G | Preparatory function |
| M | Miscellaneous function |
| X, Y, Z | Axis moves (mill); X, Z (lathe) |
| A, B, C | Rotary axis moves |
| I, J, K | Arc center offsets |
| R | Arc radius or canned-cycle retract |
| F | Feed rate |
| S | Spindle speed |
| T | Tool number |
| H | Tool length offset number |
| D | Cutter diameter offset number |
| P, Q | Canned-cycle parameters |
| L | Subprogram repeat count |
Memorise these. NIMS and Haas assessments both test address recognition.
Every CNC program has a defined beginning and end.
Header (mill example):
```
O0100 (PROGRAM NUMBER)
% (start-of-tape character — Haas convention)
G20 (inch mode)
G17 G40 G49 G80 G90 (safety block)
T1 M06 (tool call: tool 1, execute tool change)
G43 H1 (tool length compensation on, using offset 1)
S2500 M03 (spindle 2500 RPM, clockwise)
M08 (coolant on)
```
Safety block explained: `G17` selects the XY plane. `G40` cancels cutter compensation. `G49` cancels tool length offset. `G80` cancels any active canned cycle. `G90` selects absolute positioning. Writing all five on one line at the start of every program is an industry habit that prevents the machine from inheriting a dangerous mode left over from a previous program.
Footer:
```
M09 (coolant off)
G28 G91 Z0. (return Z to machine home, incremental)
G28 G91 X0. Y0. (return X and Y to machine home)
G90 (back to absolute)
M30 (program end and rewind)
%
```
`M30` ends the program and rewinds the pointer to the top. Never leave it out — a program without `M30` will continue reading whatever memory follows, which can cause unexpected motion.
Lathe header differences: Use `G18` (XZ plane), omit `G17`. Replace `H` with `T` format (on most lathes, `T0101` means tool 1, offset 1). Spindle direction for turning is typically `M03` (forward). Feed is often in inches per revolution (`G99`) rather than inches per minute.
This distinction appears on every major credentialing exam.
Modal codes stay active until cancelled or replaced. Once you write `G01`, every subsequent block commands linear interpolation until you write a different motion code such as `G00` or `G02`. Modal codes belong to modal groups. Only one code from a group can be active at a time. For example, `G90` (absolute) and `G91` (incremental) are in the same modal group — you cannot have both on simultaneously.
Non-modal codes are active for one block only. `G04` (dwell) is a common example: it pauses motion for the time or number of revolutions you specify, then the control acts as if `G04` was never written.
Knowing the modal group of a code helps you avoid conflicts. Haas publishes a complete modal-group table in their operator's manual — keep a copy at your machine.
Before running any program you have written:
1. Dry run — use the machine's single-block mode and feed-hold to step through the program with the spindle off and the part clear.
2. Verify tool offsets — an incorrect `H` or `D` value can drive the cutter into the part or fixture.
3. Check rapid moves — `G00` moves at full machine speed; confirm the path is clear.
4. Lockout/tagout (LOTO) applies whenever you are inside the machine envelope performing setup. Program editing at the control pendant does not require LOTO, but tool changes and workholding adjustments do.
5. Wear safety glasses any time the machine is powered.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.