G-Code Modal vs Non-Modal Commands: How Modes Work in CNC Programming
In CNC programming, modal and non-modal commands control how instructions behave across multiple blocks of code.
Understanding the modal system is essential to write efficient, compact, and safe G-code programs.
🧠 What Are Modal Commands?
Modal commands stay active until they are changed or canceled by another command from the same group.
Think of modal commands as a “sticky” setting — once activated, they remain in effect.
🧪 Example:
G01 X10 Y10 F100 ; G01 = linear interpolation (modal)
X20 Y20 ; Still uses G01 automatically
In the second line, G01 is not repeated, but still active.
⚠️ What Are Non-Modal Commands?
Non-modal commands are only active for one line of code. They do not persist to the next line.
🧪 Example:
G04 P1 ; Dwell for 1 second (non-modal)
G01 X10 Y10 ; G04 no longer active
G04 (dwell) affects only the line it’s on — then it’s forgotten.
🧭 Common Modal G-Codes by Group
G-code commands are grouped into modal groups. Only one code in each group can be active at a time.
| Group | Modal Commands | Description |
|---|---|---|
| 1 | G00, G01, G02, G03 | Motion commands |
| 3 | G90, G91 | Absolute/incremental mode |
| 5 | G94, G95 | Feed rate per minute/rev |
| 6 | G20, G21 | Inch/mm units |
| 7 | G40, G41, G42 | Cutter compensation |
| 17 | G17, G18, G19 | Plane selection (XY, XZ, YZ) |
Each group allows only one active command at a time.
⛔ Modal Conflict Example
G90 G91 ; ❌ Invalid: both absolute and incremental selected
You must only use one command per modal group at a time.
Correct:
G90 ; Use absolute positioning
...
G91 ; Later switch to incremental
🧪 Non-Modal Command Examples
| Command | Function |
|---|---|
| G04 | Dwell |
| G53 | Move in machine coordinates |
| G65 | Custom macro call |
| G66 | Modal macro call |
| G67 | Cancel modal macro |
🧰 Modal Programming Example
G21 ; mm mode (modal)
G90 ; absolute mode (modal)
G01 F200 ; linear move with feedrate
X10 Y0 ; Still using G01
X20 Y10 ; G01 and G90 still active
G00 X0 Y0 ; Now switched to rapid (G00 modal)
Notice how settings persist until changed.
🧪 Non-Modal Example with G53
G53 Z0 ; Move Z to machine zero (non-modal)
G01 Z5 ; Back to G01, previous modal remains
G53 affects only one line — then G01 resumes.
🧠 Benefits of Modal Commands
- ✅ Shorter programs
- ✅ More readable
- ✅ Efficient for long toolpaths
- ✅ Lower risk of conflicting commands
🧱 Programming Tips
- ✅ Know which commands are modal
- ✅ Avoid repeating modal codes unnecessarily
- ✅ Always reset critical modes (G90, G17, G94) at the start
- ✅ Watch out for dangerous modal leftovers (e.g., G91, G41)
🔄 How to Reset Modes
Some modal commands are canceled with other codes:
G40cancels cutter comp (G41/G42)G80cancels canned cyclesG67cancels modal macroG90replaces G91, and vice versa
Always clean up your modal states before retract or end of program.
🧠 Summary Table
| Type | Description |
|---|---|
| Modal | Stays active until replaced (e.g., G01) |
| Non-Modal | Active for one block only (e.g., G04, G53) |
🧩 Modal vs Non-Modal in Real Life
Think of modal commands like gear settings in a car. Once you set the gear, it stays until you change it.
Non-modal commands are like a horn or blinker — they act only once and reset automatically.
🔚 Final Thoughts
Understanding modal behavior in G-code is essential to:
- Reduce program size and complexity
- Avoid accidental errors from lingering modes
- Structure programs for clarity and safety
Always track what modes are active. Modal commands save time but demand awareness and discipline.
Leave a comment