CNC machining is the backbone of modern manufacturing. As a seasoned CNC machinist, I can tell you that these magical codes breathe life into the CNC machines, guiding their every move. Let’s dive into this treasure trove and unearth the secrets of standard G-Codes and M-Codes. Keep in mind these codes are focused on CNC milling.
You can learn about how to read and write g-codes from here.
You can find G-Codes and M-Codes for turning from here.
For specific machine language codes, you need to check your machine`s manufacturer guide.
G-Codes: Geometrical movement codes
G-Codes, my friends, are like the conductor of an orchestra. They dictate the movements, the rhythm, and the flow. Here’s a nifty table to get you started:
G-Code | Description | Possible Parameters |
---|---|---|
G00 | Rapid positioning | X, Y, Z |
G01 | Linear interpolation (Straight line move) | X, Y, Z, F |
G02 | Circular interpolation (Clockwise) | X, Y, Z, I, J, K, F |
G03 | Circular interpolation (Counterclockwise) | X, Y, Z, I, J, K, F |
G04 | Dwell (Pause) | P or X |
G09 | Exact stop check | None |
G10 | Programmable data input | L, P, X, Y, Z |
G17 | XY plane selection | None |
G18 | ZX plane selection | None |
G19 | YZ plane selection | None |
G20 | Programming in inches | None |
G21 | Programming in millimeters | None |
G28 | Return to the secondary home position | X, Y, Z |
G30 | Return to the secondary home position | X, Y, Z |
G31 | Return to the secondary home position | X, Y, Z, F |
G32 | Threading with a single-point tool | X, Z, F |
G33 | Constant pitch threading | K, Z, F |
G40 | Cutter compensation cancel | None |
G41 | Cutter compensation left | D |
G42 | Cutter compensation right | D |
G43 | Tool length compensation positive | H, Z |
G44 | Tool length compensation negative | H, Z |
G49 | Cancel tool length compensation | None |
G53 | Machine coordinate system | None |
G54 | Workpiece coordinate system 1 | None |
G55 | Workpiece coordinate system 2 | None |
G56 | Workpiece coordinate system 3 | None |
G57 | Workpiece coordinate system 4 | None |
G58 | Workpiece coordinate system 5 | None |
G59 | Workpiece coordinate system 6 | None |
G61 | Exact stop mode | None |
G64 | Cutting mode | P |
G73 | High-speed peck drilling cycle | R, Z, Q, F |
G76 | Fine boring cycle | Z, R, P, Q, F |
G80 | Cancel canned cycle | None |
G81 | Simple drilling cycle | R, Z, F |
G82 | Counter boring cycle | R, Z, P, F |
G83 | Peck drilling cycle | R, Z, Q, F |
M-Codes: The Puppet Masters
M-Codes are like puppet masters controlling the machine’s states. Spindles, coolant, you name it! They turn things on and of, and they are more functional.
M-Code | Description | Possible Parameters |
---|---|---|
M00 | Program stop | None |
M01 | Optional program stop | None |
M02 | End of program | None |
M03 | Spindle start (clockwise) | S (speed) |
M04 | Spindle start (counterclockwise) | S (speed) |
M05 | Spindle stop | None |
M06 | Tool change | T (tool number) |
M07 | Coolant on (mist) | None |
M08 | Coolant on (flood) | None |
M09 | Coolant off | None |
M13 | The spindle on (counterclockwise) with coolant on | S (speed) |
M14 | The spindle is on (counterclockwise) with coolant on | S (speed) |
M19 | Spindle orientation | None |
M21 | Mirror image X-axis on | None |
M22 | Mirror image X-axis off | None |
M23 | Mirror image Y-axis on | None |
M24 | Mirror image Y-axis off | None |
M30 | Program end and reset | None |
M98 | Call subprogram | P (program number), L (number of repeats) |
M99 | End of subprogram | None |
Controller-Specific Variations
Different controllers have their own flavors of G-Codes and M-Codes. Variety is the spice of life, isn’t it? From my experience, I can say that easily most of the codes are the same, but some manufacturers have special M-codes and G-codes.
For example, some of the codes I found very helpful;
- G05.1 Q1: I used this code on Fanuc Milling controller-OM to activate highspeed machining mode with high precision mode. Machined parts are more precise with this mode and the controller also looks ahead automatically to smoothen movements.
- G08 P1: On Fanuc Milling controller-OM & Mitsubishi controller is a mode you can cancel very sharp movements to increase preciseness. But the program will move more slowly than before.
Mazak
Mazak, the maverick, has its own variation called Mazatrol. It’s like having a friendly chat with your machine.
Mazak Specific G-Codes, M-Codes(Milling)
Code | Description |
---|---|
G12.1 | Polar coordinate interpolation mode on |
G14 | Scaling on |
G15 | Polar coordinate interpolation mode off |
G22 | Stored stroke limit on |
G23 | Stored stroke limit off |
G31 | Skip function |
G35 | Coordinate system rotation on |
G37 | Coordinate system rotation off |
G68 | Mirror image on |
G69 | Mirror image off |
G135 | Cylindrical interpolation cancel |
G136 | Cylindrical interpolation (X-axis) |
Code | Description |
---|---|
M26 | Spindle gear range change, high gear |
M27 | Spindle gear range change, low gear |
M30 | End of the subprogram, wrap it up |
M36 | Automatic door open, let the breeze in |
M37 | Automatic door close, keep the secrets safe |
M38 | Chip conveyor forward, keep it moving |
M39 | Chip conveyor reverse, back it up |
M48 | Cancel override, back to normal |
M49 | Enable override, take control |
M97 | Local subprogram call, let’s get specific |
M98 | Call external subprogram, bring in the cavalry |
M99 | End of subprogram, wrap it up |
Siemens Specific G-Codes, M-Codes(milling)
Siemens, the stalwart, with its SINUMERIK series, is all about precision and finesse.
Code | Description |
---|---|
G70 | Finishing cycle |
G73 | Pattern repeating cycle |
G74 | Face grooving or drilling |
G75 | Outer/internal longitudinal grooving |
G76 | Fine boring cycle |
G96 | Constant cutting speed on |
G97 | Constant cutting speed off |
Code | Description |
---|---|
M17 | Chip the conveyor off, hold the debris |
M21 | External M-function, the wild card |
M22 | Spindle cooling on, keep it frosty |
M23 | Spindle cooling off, let it heat |
M25 | Engage the clamping device, lock it down |
M26 | End of the program with reset, the final bow |
M29 | High-speed spindle mode, turbocharge it |
M30 | Chip the conveyor off, hold the debris |
M38 | Chip conveyor on, clear the stage |
M39 | Chip the conveyor off, hold the debris |
M50 | Override cancel, back to basics |
M51 | Feedrate override, take the reins |
M52 | Rapid traverse override, speed it up or slow it down |
M53 | Spindle override, control the spin |
Fanuc Specific G-Codes, M-Codes(milling)
Fanuc, the workhorse, is everywhere. It’s like the bread and butter of CNC controllers.
Code | Description |
---|---|
G10 | Programmable offset setting |
G11 | Programmable offset cancel |
G28 | Return to the reference point |
G30 | Return to 2nd, 3rd, or 4th reference point |
G92 | Threading cycle with no-load constant pitch |
G96 | Constant surface speed on |
G97 | Constant surface speed off |
Code | Description |
---|---|
M19 | Spindle orientation, get it just right |
M21 | Mirror image X-axis on, like a reflection in the water |
M22 | Mirror image X-axis off, back to the original |
M26 | Spindle gear range change, like shifting gears on a mountain bike |
M29 | High-speed spindle mode, unleash the fury |
M41 | Low gear range, like treading carefully |
M42 | High gear range, pedal to the metal |
M52 | Single-direction positioning, like an arrow flying straight |
M53 | Disable override, stick to the plan |
M61 | Set constant surface speed, smooth as silk |
M62 | Single-direction positioning, like an arrow flying straight |
Conclusion
The best code is your machine’s specific code, so please check the guides if you have one. You should test these codes on MDI mode before using them on a real workpiece.