INTRODUCTION:
Today we are going to look at a fundamental technique in CNC manual programming: using subprograms to perform complex, repeating multi-depth operations like face milling.
When you are programming manually, you want your code to be concise and easy to understand. Imagine a face milling job where you need to remove 10 mm of material in 2 mm steps, using a complex zigzag pattern. If you wrote that entire pattern out line-by-line for all five depths, the program would be massive, difficult to read, and very hard to debug.
Instead, we use a main program that handles the setup, positioning, and loop control, and we write a single subprogram that performs the required cutting action for one single depth. This single subprogram is then "looped" as many times as we need.
The Challenge of Multi-Directional Cutting and Multi-Depth:
While looping sounds easy, we often run into specific challenges during multi-depth face milling, which this example is designed to solve.
1. You may have noticed that some face milling patterns start on the left, but if there is an odd number of passes, the tool finishes on the far right. If you just simply loop that subprogram, the tool will spend most of its time in "air-cuts" or try to start the next depth from the far side, which can be inefficient and risky.
2. To go deeper with every loop, we use Incremental (G91) coordinates for our depth moves. This means "go 2 mm deeper from where you are now." However, the actual face cuts themselves must be programmed using Absolute (G90) coordinates to maintain precise part dimensions.
Learning how to "balance" these transitions, switching to G91 for the depth change, back to G90 for the cut, and then managing the return to the starting corner is the core focus of this example. The program we are about to review uses a standard, professional solution to address all these issues, ensuring every loop is predictable, safe, and efficient. Let's look at the code.
Program:
O0001 (MAIN PROGRAM - FACE MILL FIX)
(SAFETY BLOCK & INITIAL SETTINGS)
G00 G90 G80 G49 G40 G17 G21; (Metric, Absolute, Cancellation)
G91 G28 Z0.0; (Home Z)
G28 X0.0 Y0.0; (Home X and Y)
T1 M06; (Tool Change to T1 - Ø30 Face Mill)
(INITIAL POSITIONING - SAFE START POINT)
G00 G90 G54 X-95.0 Y-35.0; (Move to safe start XY in clear air)
G43 H01 Z100.0 S1000 M03; (Spindle ON, Tool Offset ON, Rapid to Z100)
G00 Z10.0 M08; (Coolant ON)
G01 Z0.0 F500; (Rapid to initial safe Z-plane)
(CALL SUBPROGRAM - REPEAT 10 TIMES)
(Goal: Cut from Z-0.5 down to Z-5.0)
M98 P1235 L10; (Calls subprogram O1235)
(POST-CUTTING & RETRACTION)
G00 Z100.0 M09; (Rapid up, Coolant OFF)
M05; (Spindle OFF)
G91 G28 Z0.0; (Home Z)
G28 X0.0 Y0.0; (Home X and Y)
M01; (Optional Stop)
M30; (End of Main Program)
O1235 (SUBPROGRAM - DEPTH, CUT)
(--- BLOCK 1: PLUNGE NEW DEPTH ---)
G91 G01 Z-0.5 F100; (Sink 0.5mm deeper into material from current level)
G90; (MUST Switch back to G90 for absolute XY pattern)
(--- BLOCK 2: CUTTING PATTERN ---)
X95.0 F500; (Pass 1 - Cut RIGHT)
Y-15.0; (Step over)
X-95.0; (Pass 2 - Cut LEFT)
Y5.0; (Step over)
X95.0; (Pass 3 - Cut RIGHT)
Y25.0; (Step over)
X-95.0; (Pass 4 - Cut LEFT)
Y45.0; (Step over)
X95.0; (Pass 5 - Cut RIGHT, Tool ends on Far-Right Side)
(Safety move to return to start without hitting the finished surface)
G91 G00 Z2.0; (Rapid UP 2mm from the current cutting plane)
G90 X-95.0 Y-35.0; (Rapid back to the original Start Point in Absolute XY)
G91 G00 Z-2.0; (Rapid BACK DOWN 2mm to return to the active cut level)
M99; (End Sub, return to P1235 loop)
EXPLAINATION:
If you didn't read article on format of programming, then I will request you to learn that before. Because I will only explain cutting block here. So let's go.
M98 P1235 L10; (Calls subprogram O1235)
• This single line triggers the entire face milling process. It tells the controller: "Go to subprogram O1235 and run it exactly 10 times." This is where the magic (and the fix) happens.
The subprogram contains the most critical updates. It is designed to be self-balancing: it ends at the exact state and Z-height it started at, only 0.5 mm deeper. This is why we can loop it 10 times without issues.
O1235;
G91 G01 Z-0.5 F100; ( Sink 0.5mm deeper into material)
G90; ( Switch back to G90)
• Let's trace the first loop. The tool starts at Z0.0. The G91 move plunges from its current position, meaning the new depth is Z-0.5.
• We immediately switch back to G90. If we forgot this, every subsequent X and Y move would be added to the last, and the tool would fly off the machine. All face cuts must be done in absolute G90.
X95.0 F500; (Pass 1 - Cut RIGHT)
Y-15.0; (Step over)
X-95.0; (Pass 2 - Cut LEFT)
...
X95.0; (Pass 5 - Cut RIGHT, Tool ends on Far-Right Side)
• After pass 5, the tool finishes the entire face. At this line, the tool center is at X95.0, Y+45.0 and depth Z-0.5. We are on the far opposite side of where we started. If we simply put M99 here, the next loop (L2) would try to rapid across the material from the far side.
We must get the tool back to the start corner (X-95, Y-35) and back to the current cut level (Z-0.5) without ruining the finished part and without making the G91 logic fail on the next loop.
G91 G00 Z2.0; ( Rapid UP 2mm from the current cutting plane)
• This is the safety jump. We use G91 to lift the tool 2.0 mm vertically. (the tool goes from Z-0.5 to Z1.5).
G90 X-95.0 Y-35.0; (Rapid back to the original Start Point in Absolute XY)
• We switch back to G90 just to execute the return move. We rapid over the part to get back to the initial XY corner.
G91 G00 Z-2.0; ( Rapid back down 2mm to return to the active cut level)
• We use G91 to drop exactly 2.0 mm, cancelling out the safety lift. The tool drops from Z1.5 back to Z-0.5.
• The tool is now back in the correct XY starting corner, at the correct depth (Z-0.5), ready for the next loop.
M99; (Loop back)
• Control returns to the M98 line in the main program to check if L has reached 10. If not, it loops back to G91 G01 Z-0.5, which drops the tool to Z1.0 (another 0.5 deeper), and the process repeats.
In face milling, if you have an odd number of horizontal passes, you end up on opposite side. To solve this, retract and return tool in G91 (Incremental) as well. If you go up 0.5, you must eventually go down 0.5 plus your clearance.
• By using G91 Z2.0 and then G91 Z-2.0, you are "canceling out" the safety move.
• The tool ends the subprogram at the exact same Z-depth where it finished the cut.
• When it loops back to the top, the G91 Z-0.5 will successfully sink the tool another 0.5 mm into the part.
0 Comments