simCNC - supported G-codes and M-codes (reference)

Created by Andrzej Rogozynski, Modified on Mon, 23 Nov at 7:43 AM by Andrzej Rogozynski

Reference for simCNC 3.604 · CS-Lab s.c.

This document lists the G-codes recognised by the simCNC G-code interpreter, and the M-codes built into simCNC or installed with a new profile. Codes that are not listed (for example G95, G96, G97, G51) are not supported: the program reports the error "Unknown code G" when it is loaded.

Axis words refer to up to 6 machine axes: X Y Z A B C. The number of active axes depends on the machine configuration.

Program format

  • Line numbers (N10, N20, ...) are optional. If used, N must be the first word of the line and a whole number (0 or more), and only one N per line.
  • % characters (e.g. the first and last line of a program) are ignored.
  • Comments are written in brackets ( ... ) or after a semicolon ; .... Use only one bracket comment per line: with two, everything from the first ( to the last ) is removed, including any G-code between them.
  • M-codes: most of them (M3, M5, M6, M30, ...) are Python macros in the simCNC profile and can be adapted to the machine; see M-codes at the end.
  • Start each program by setting the modes it needs (G21/G20, G90, G17, G54, ...), so that it does not depend on the state left by a previous program.

Units

Axis words (including arc I J K and R), G92 offsets and G68 centres follow G20/G21. These values are always in the machine base units (mm for linear axes, degrees for rotary axes), also in inch mode:

  • G10 coordinates
  • the P diameter of G41/G42
  • the P tolerance of G64
  • the Q peck depth of G83 (do not mix G83 with G20)

In G93 mode the F word is a reciprocal time and has no units (see Feed rate mode).

Motion

CodeParametersDescription
G0axesRapid traverse (positioning move) to the given position.
G1axesLinear feed move to the given position at the active feed rate (F).
G2axes, I J K or RClockwise arc in the active plane (G17/G18/G19). Centre given as I J K offsets from the start point, or as radius R. Motion of the axis perpendicular to the plane gives a helix.
G3axes, I J K or RAs G2, counter-clockwise.
G32axesStraight move synchronised with the spindle (single-point threading). The lead per revolution is F / commanded rpm, i.e. F = pitch × S. The pitch holds when the spindle slows down under load, but changing S or the spindle override changes the pitch. At least one axis word is required. Needs the spindle-speed and encoder-index (trajectory trigger) signals to be configured, and cutter compensation off. The feed rate override does not apply.
G53axesNon-modal: the axis words on this line are machine coordinates (work offset, G92, tool offset and G68 rotation are bypassed) for this move only. Must be combined with a motion code, e.g. G53 G0 Z0.

Units, plane and distance mode

CodeParametersDescription
G17—XY plane (arcs, G68 rotation, cutter compensation; canned cycles drill along Z).
G18—XZ plane (canned cycles drill along Y).
G19—YZ plane (canned cycles drill along X).
G20—Units: inches.
G21—Units: millimetres.
G90—Absolute distance mode.
G91—Incremental distance mode.

Work coordinate systems and offsets

CodeParametersDescription
G54…G59—Select work offset 1–6.
G59.1…G59.250—Select extended work offset 7–256.
G10L2 P<1-256> [axes]Sets the origin of work offset P (1 = G54 … 6 = G59, 7–256 = G59.1…G59.250) to the given machine coordinates, only for the axes given. L2 and P must be the first two words after G10, followed by at least one axis word. Values in base units (G20 not applied).
G92axesSets an offset so that the given axis words become the current position. Only the axes given are changed. Activates the G92 offset.
G92.1—Cancels the G92 offset and resets it to zero.
G92.2—Cancels the G92 offset but keeps its value.
G92.3—Re-activates the stored G92 offset.

Tool length offset and cutter compensation

CodeParametersDescription
G40—Cancels cutter radius compensation.
G41D or P (optional)Cutter radius compensation, tool left of the path. D<n> takes the diameter from tool table entry n; P<diameter> gives it directly. Without either, the previously selected diameter is used.
G42D or P (optional)As G41, tool right of the path.
G43HActivates the tool length offset of tool H (0–255).
G49—Cancels the tool length offset.

Using cutter compensation

G41 D5      (compensate left, diameter of tool table entry 5)
G42 D5      (same, right of the path)
G41 P8.0    (compensate left, diameter 8.0 given here)
G41         (compensate left, diameter selected earlier)
G40         (off)
  • With D5 the diameter used is the diameter of tool table entry 5 minus its diameter wear; half of it is the path offset.
  • D is modal: it stays selected for later G41/G42 until another D or a P replaces it, and it is kept after a restart. T<n> does not select the compensation diameter, only D does.
  • A tool table entry with diameter 0 means no compensation, without a warning.
  • A line with only D5 is allowed; it selects the entry without switching compensation on.
  • Use D or P, not both. On one line (G41 D3 P6) P wins. D<n> switches back from a P diameter to the tool table.
  • D takes a whole number 0–255 (no # parameter). A number beyond the tool count is ignored and the previous entry stays selected.
  • Compensation must be off (G40) for canned cycles (G81/G82/G83), for G28/G30 and for G32; otherwise the error "Compensation has to be off for this segment" is reported.

Coordinate system rotation

CodeParametersDescription
G68X Y Z (centre), R (angle), optionalRotates the coordinate system in the active plane by R degrees (−360…360) around the given centre. An omitted X/Y/Z is 0 (not the current position). Without R the previous angle is kept; in G91 mode R is added to the current rotation.
G69—Cancels the G68 rotation.

Canned (drilling) cycles

Drilling runs along the axis perpendicular to the active plane (Z for G17, Y for G18, X for G19). R, P and Q are modal and reused by later cycle lines. A cycle line without axis words only updates these values and does not move. A/B/C words on a cycle line are ignored.

CodeParametersDescription
G80—Cancels the active canned cycle.
G81axes, R, KDrilling: rapid to the hole position, rapid to the R plane, feed to depth, rapid retract (G98/G99). K repeats the cycle n times (with G91: a row of equally spaced holes).
G82axes, R, P, KAs G81, with a dwell of P milliseconds at the bottom.
G83axes, R, Q, P, KPeck drilling: feeds in steps of Q, retracts to the R plane after each peck, rapids back to a clearance above the previous depth (peck tolerance in the machine settings). Optional dwell P [ms] at the bottom of each peck. Q must be greater than 0 and is in base units (not converted by G20).
G98—Retract to the starting level after each cycle.
G99—Retract to the R plane after each cycle.

Homing and reference points

CodeParametersDescription
G28axes (optional)Rapid through an optional intermediate point to reference point 1. With axis words only those axes move to the reference point; without, all axes do.
G28.1P<axis> (optional)Homing (drive to the home switches). Without P: all axes set to home with "home all". With P: only that axis. P counts from zero (P0 = X).
G30axes (optional)As G28, to reference point 2.
G30.1—Homing of all axes set to home with "home all" (as G28.1 without P).

Probing

CodeParametersDescription
G31axesStraight probing move with probe input 0; stops when the probe triggers. At least one axis word is required.
G31.1axesAs G31, probe input 1.
G31.2axesAs G31, probe input 2.
G31.3axesAs G31, probe input 3.

Feed rate mode (beta)

G94 (default): F is a feed rate in units per minute. G93: inverse time, F is the reciprocal of the move duration - the move takes 1/F minutes. CAM systems use this for simultaneous multi-axis moves.

G93
G1 X10 F2      ; 10 mm in 1/2 minute = 30 s
G1 X20 F0.5    ; 10 mm in 2 minutes
G1 A90 F1      ; 90 degrees in 1 minute
G94            ; back to units per minute
G1 X0 F500
  • In G93 mode every G1/G2/G3 line needs an F; otherwise "F is required in G93 mode".
  • G20/G21 do not change a G93 F.
  • G0 is not affected (rapid speed in both modes).
  • The feed rate override still applies (50 % doubles the move time).
  • Canned cycles cannot be used in G93 ("G93 is not allowed with canned cycles"). G32 ignores the feed rate mode.
  • Loading a G-code file resets the mode to G94.
  • With cutter compensation, or where very short segments are optimised away, the real move time can differ slightly from 1/F.

Dwell, path control and miscellaneous

CodeParametersDescription
G4P (required)Dwell for P milliseconds (at least 1).
G64P (required)Maximum path deviation when blending corners. P ≥ 0, in base units (G20 not applied).
G50—Accepted for compatibility, no effect.
G93—(beta) Inverse time feed rate mode, see above.
G94—(beta) Units per minute feed rate mode (default).

M-codes

Built into simCNC

These M-codes are handled by simCNC itself, not by macros.

CodeParametersDescription
M47—Jumps back to the first line of the program and runs it again (repeats the program until it is stopped).
M62P<0-3> (required)Switches the trajectory-synchronised output P on exactly at this point of the path, without stopping the motion. Outputs 0–3 are assigned in the special I/O configuration (trajectory sync outputs).
M63P<0-3> (required)As M62, switches the output off.
M98P<n> (required), L<repeats>Calls subprogram O<n>, L times (default 1, at least 1). Subprograms can be nested up to 10 levels. In 3.604 use a plain number for L: L#100 takes the stored value of parameter #100, not one assigned earlier in the program. Not available in MDI.
M99—Ends the subprogram and returns to the line after the calling M98.
O<n>—Subprogram label (start of subprogram n).
G90 G0 X0 Y0
M98 P100 L3     (run subprogram 100 three times)
M30
O100
G91 G1 X10 F500
Y10
G90
M99

Macros (Python scripts)

Any other M<n> runs the script m<n>.py from the scripts folder of the active profile. The scripts can be edited, and new M-codes can be added by creating a new script (e.g. m100.py for M100). An M-code macro takes no parameters on its line ("M code has wrong arguments"). A new profile is created with these default macros:

CodeScriptDefault action
M0m0.pyProgram stop. Motion stops; Start continues from the next line.
M1m1.pyOptional stop. The default script does the same as M0.
M2m2.pyProgram end.
M3m3.pySpindle on, clockwise (speed from S).
M4m4.pySpindle on, counter-clockwise.
M5m5.pySpindle off.
M6m6.pyTool change: the tool selected with T<n> (0–255) becomes the current tool and tool offset number. The default script does not move the machine; adapt it to the machine's tool changer.
M7m7.pyMist coolant on.
M8m8.pyFlood coolant on.
M9m9.pyMist and flood coolant off.
M30m30.pyProgram end and rewind to the first line.
M150m150.pyAutoLeveling correction off.
M151m151.pyAutoLeveling correction on.

CS-Lab s.c. · www.cs-lab.eu · simCNC postprocessors: en.cs-lab.eu – postprocessors

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article