INTRODUCTION:
Today, we are going to look at programming drilling holes on a standard rectangular plate. We are working on a plate that is 140mm wide and 120mm tall. Our "Work Zero" (the point where X=0 and Y=0) is located exactly in the center of the plate. We need to create four threaded holes, one in each corner by using canned cycles.
A canned cycle is essentially a shortcut: instead of writing dozens of lines of code to move the tool down and up, you use one line, and the machine's computer handles the logic.
Here is anatomy of the most common Canned Cycles used in CNC drilling:
G81XYZRF for single peck drilling
G83XYZRQF for peck drilling
G84XYZRF for tapping
• X, Y : horizontal coordinates of the hole. This tells the machine exactly where to stop and start drilling.
• Z : how deep the tip of the tool will go into the material.
• R (Retract Plane): This is the "Safety Height." The tool will move quickly (Rapid) to this height before it starts feeding into the metal. After finishing a hole, it will retract back to this plane.
• F (Feed Rate): How fast the tool moves down into the metal (measured in mm/min or inches/min).
• Q : this stands for the Peck Depth. The machine drills a distance of Q (e.g., 5mm), pulls all the way out of the hole to throw away the metal chips and let coolant in, then goes back in to drill another Q.
In professional machining, we rarely just "shove a drill bit" into the metal. We use a three-step process to ensure precision:
1. The Center Drill (T01) – Think of this as the "marker." It creates a tiny, stiff dimple so the next drill bit doesn't wobble or wander off-center.
2. The Twist Drill (T02) – This does the heavy lifting. We use a Peck Cycle (G83), which acts like a woodpecker, jumping in and out to clear away metal chips so the tool doesn't overheat or snap.
3. The Tap (T03) – This is the finisher. It cuts the internal threads. This requires perfect synchronization between how fast the tool spins and how fast it moves down. When the tool hits the bottom depth, the spindle stops, reverses direction, and "unscrews" itself back out.
Let's look at the program:
O1234 ;
G90 G80 G49 G40 G21 G17 G15 ;
G28 G91 Z0 ; (Return Z to home)
G28 X0 Y0 ; (Return XY to home)
(Tool 01 - center drill)
M06 T01 ;
G90 G54 G00 X60.0 Y50.0 ; (Position to first hole)
G43 H01 Z100.0 S1000 M03 ; (Tool length offset, Spindle ON)
G00 Z10.0 M08 ; (Coolant ON)
G01 Z0.0 F100;
G99 G81 Z-3.0 R2.0 F100 ; (G81 Center Drill Cycle, Depth -3mm)
X-60.0 ; (Hole 2)
Y-50.0 ; (Hole 3)
X60.0 ; (Hole 4)
G80 G00 Z100.0 M09 ; (Cancel cycle, Coolant OFF)
M05 ; (Spindle OFF)
(Tool 02 - drilling)
G28 G91 Z0 ;
G90;
M06 T02 ;
G90 G54 G00 X60.0 Y50.0 ;
G43 H02 Z100.0 S1000 M03 ;
G00 Z10.0 M08 ; (Coolant ON)
G01 Z0.0 F100;
G99 G83 Z-25.0 R2.0 Q5.0 F120 ; (G83 Peck Drill Cycle, 5mm pecks)
X-60.0 ;
Y-50.0 ;
X60.0 ;
G80 G00 Z100.0 M09 ;
M05 ;
(Tool 03 - tapping)
G28 G91 Z0 ;
M06 T03 ;
G90 G54 G00 X60.0 Y50.0 ;
G43 H03 Z100.0 S300 M03 ; (Slower RPM for Tapping)
G00 Z10.0 M08 ; (Coolant ON)
G01 Z0.0 F100;
(F = Pitch x RPM | 1.75 x 300 = 525)
G99 G84 Z-20.0 R5.0 F525 ; (G84 Tapping Cycle)
X-60.0 ;
Y-50.0 ;
X60.0 ;
G80 G00 Z100.0 M09 ;
M05;
G28 G91 Z0 ;
G28 G91 X0 Y0 ;
M01;
M30 ;
EXPLAINATION:
To understand the program, it helps to look at it in three phases: Setup (preparations), Canned Cycles (the actual work), and Ending.
1. Setup:
These codes ensure the machine is in the correct state before the tool ever touches the metal.• O1234: The program number. Every program starts with an 'O' followed by four digits.
• G21: Sets the machine to Metric units (millimeters).
• G90: Sets Absolute Positioning. This means all coordinates (X, Y, Z) are measured from one fixed "Zero" point (the center of your plate).
• G40 / G49 / G80: These are "cancel" codes. They turn off any previous tool radius compensation, tool length offsets, or active drilling cycles from the last job to prevent accidents.
• G28 G91 Z0: Sends the Z-axis (the spindle) to its home position. G91 (Incremental) is used here so the machine moves "0" distance from its home, essentially forcing it to go there immediately.
• M06 T01: M06 is the command for an automatic tool change; T01 selects Tool #1 (your Center Drill).
• G54: This is your Work Coordinate System. It tells the machine where your "Work Zero" is located on the table.
• G00: Rapid Traverse. Moves the tool at maximum speed to a position. Used for moving through the air, never for cutting.
• G43 H01 Z100.0: G43 activates the Tool Length Compensation. Since every tool has a different length, H01 tells the machine to look at the "Height" offset stored for Tool 1 so the tip knows exactly where Z0 is.
• M03 S1000: M03 starts the spindle rotating clockwise. S1000 sets the speed to 1000\text{ RPM}.
• M08 / M09: M08 turns the coolant on; M09 turns it off.
2. The Machining Cycles:
Instead of writing 20 lines of code for one hole, we use one "Canned Cycle" command.G81 (Spot Drilling Cycle):
It is used for making a shallow starting hole. This is a simple cycle where the tool goes to depth and immediately retracts. It creates a small dimple so the larger drill bit in the next step doesn't walk or wander across the surface. The program moves to (60, 50), then (-60, 50), then (-60, -50), and finally (60, -50). This hits all four corners of your 120 \times 100 plate. The tool will rapid to 2mm above the part before it starts feeding into the metal.Once the centers are marked, you switch to a standard drill bit. Machine goes to home position for tool changes by command G28 in G91. You should switch back to G90 as soon as possible after the G28 move is complete.
G91 G28 Z0. (Go home)
G90 (Switch back to Absolute immediately)
T02 M06 (Change tool)
Most machinists prefer to put the G90 immediately after the G28 line or on the same line as the next positioning move. This ensures the machine doesn't try to interpret your hole coordinates (X60. Y50.) as incremental distances from the home position. After tool changing completed.
G83 (Peck Drilling Cycle):
It is used for deep holes to clear out metal chips. For a depth of 25 mm, it is best to use a peck cycle. Instead of going all the way down at once, the tool drills a few millimeters (the Q value), retracts to clear chips and let coolant in, then goes deeper. This prevents the drill from breaking. Q5.0 is the peck amount. The drill will go down 5mm, pull back to clear chips, then go another 5mm, and so on until it hits Z-25.0. R2.0 tells the machine to start drilling from 2 mm above the part surface to ensure it doesn't hit the metal at full speed.Once the drilling completed, you switch to a tap.
G91 G28 Z0.
T03 M06
G90 G00 G54 X60. Y50. (Switch to Absolute and move to the hole)
G84 (Tapping Cycle):
It is used for cutting internal threads. This is the most sensitive part of the operation. In this cycle, the spindle rotation and the downward feed are perfectly synchronized. When the tool reaches the bottom (Z-20.0), the spindle automatically reverses direction to unscrew the tap from the hole.Before G81, G83 and G84 we used G99 to activate R-plane. If you know idea read:
3. Closing:
• G80: Cycle Cancel. This is extremely important. It tells the machine "I am done drilling; stop trying to drill at every X, Y coordinate I give you."• M05: Stops the spindle rotation.
• M30: Program End and Reset. This stops everything and moves the "cursor" in the machine's brain back to the very first line, ready to run the next part.
Calculating Feed (F) for Tapping:
For most Fanuc and similar controllers, the formula is:Feed(F) = Pitch × RPM
• Pitch: The distance between threads (e.g., for an M10 x 1.5 tap, the pitch is 1.5mm).
• RPM: The spindle speed you have chosen for the operation.
Identify the Pitch: Check your tap or the thread chart. Let's say it is 1.75mm.
Select a Spindle Speed (RPM): Tapping is usually done at lower speeds for safety. Let’s choose 300 RPM.
Multiply: 1.75 × 300 = 525
Result: Your code would be G84 Z-20.0 R5.0 F525.
• Metric (G21): Use the formula above (Pitch × RPM).
• Inch (G20): If you are using Threads Per Inch (TPI), the formula is RPM ÷ TPI. For example, for a 1/4-20 bolt at 200 RPM, it would be 200 ÷ 20 = F10.
If you forget to cancel a cycle with G80, the machine will try to drill a hole every time you give it a new coordinate—even if you're just trying to move the tool away to change it!"
Is it necessary to use G99 and G88?
Strictly speaking, you don't have to type them because one of them is always active by default usually G98 on most machines upon startup, but it is extremely important for safety.Use G81 when the hole depth is less than 3 times the diameter of the drill.
Your drilled hole should be deeper than your tapped threads. That's why we programmed the drill at 25mm and the tap at 20mm:
Here are three reasons why we plunge drill deeper than tap:
1. A standard twist drill has a conical tip (usually 118° or 135°). Because of this shape, the drill doesn't create a full-diameter hole all the way to the very bottom. If you drill to exactly 20mm, the "full-diameter" part of the hole might only be about 17mm deep. By drilling to 25mm, you ensure that you have a "full-diameter" hole at least 21–22mm deep, which gives the tap enough room to work.
2. When a tap cuts threads, it creates metal chips. In a "blind hole" (a hole that doesn't go all the way through the part), those chips have nowhere to go but down. If the drill depth and tap depth are the same, the chips will get packed at the bottom. The tap will hit those chips, jam, and likely snap off inside your part. That extra 5mm of space acts as a "trash can" for the chips to sit in so the tap stays safe.
3. Taps are not flat on the bottom; they have a "taper" or "lead" usually the first 3 to 5 threads that helps the tool start cutting. These starting threads do not cut a "full" thread. To get 20mm of usable thread, the tap actually needs to go slightly deeper than 20mm, or you need to ensure the hole is deep enough so the tap doesn't "bottom out" before it reaches the required depth.
0 Comments