CNC programs list instructions to be performed in the order they are written. They read like a book, left to right and top-down. Each sentence in a CNC program is written on a separate line, called a Block. Blocks are arranged in a specific sequence that promotes safety, predictability and readability, so it is important to adhere to a standard program structure.
Typically, blocks are arranged in the following order:
The steps listed above represent the simplest type of CNC program, where only one tool is used and one operation performed. Programs that use multiple tools repeat steps two through nine for each.
Table 5.3 and Table 5.4 on section G & M Codes show the most common G and M codes that should be memorized if possible.
Like any language, the G-code language has rules. For example, some codes are modal, meaning they do not have to be repeated if they do not change between blocks. Some codes have different meanings depending on how and where there are used.
While these rules are covered in this chapter, do not concern yourself with learning every nuance of the language. It is the job of the job of the CAD/CAM software Post Processor to properly format and write the CNC program.
The program in Table 5.1 below machines a square contour and drills a hole.
Block |
Description |
Purpose |
% O0001 (PROJECT1) (T1 0.25 END MILL) N1 G17 G20 G40 G49 G80 G90 |
Start of program. Program number (Program Name). Tool description for operator. Safety block to ensure machine is in safe mode. |
Start Program |
N2 T1 M6 N3 S9200 M3 |
Load Tool #1. Spindle Speed 9200 RPM, On CW. |
Change Tool |
N4 G54 N5 M8 N6 G00 X-0.025 Y-0.275 N7 G43 Z1. H1 N8 Z0.1 N9 G01 Z-0.1 F18. |
Use Fixture Offset #1. Coolant On. Rapid above part. Rapid to safe plane, use Tool Length Offset #1. Rapid to feed plane. Line move to cutting depth at 18 IPM. |
Move to Position |
N10 G41 Y0.1 D1 F36. N11 Y2.025 N12 X2.025 N13 Y-0.025 N14 X-0.025 N15 G40 X-0.4 N16 G00 Z1. |
CDC Left, Lead in line, Dia. Offset #1, 36 IPM. Line move. Line move. Line move. Line move. Turn CDC off with lead-out move. Rapid to safe plane. |
Machine Contour |
N17 M5 N18 M9 (T2 0.25 DRILL) N19 T2 M6 N20 S3820 M3 |
Spindle Off. Coolant Off. Tool description for operator. Load Tool #2. Spindle Speed 3820 RPM, On CW. |
Change Tool |
N21 M8 N22 X1. Y1. N23 G43 Z1. H2 N24 Z0.25 |
Coolant On. Rapid above hole. Rapid to safe plane, use Tool Length Offset 2. Rapid to feed plane. |
Move to Position |
N25 G98 G81 Z-0.325 R0.1 F12. N26 G80 N27 Z1. |
Drill hole (canned) cycle, Depth Z-.325, F12. Cancel drill cycle. Rapid to safe plane. |
Drill Hole |
N28 M5 N29 M9 N30 G91 G28 Z0 N31 G91 G28 X0 Y0 N32 G90 N33 M30 % |
Spindle Off. Coolant Off. Return to machine Home position in Z. Return to machine Home position in XY. Reset to absolute positioning mode (for safety). Reset program to beginning. End Program. |
End Program |