Haas Mill Programming Manual
Haas Mill Programming Manual
Haas Mill Programming Manual
Welcome to Productivity, Inc., your local Haas Factory Outlet (H.F.O.) for the Mill Programming Class. This
class is intended to give a basic understanding of the programming of a Haas Machining Center.
After 1945 design of wings for the US Air Force were becoming extremely complex and hard to
manufacture using conventional machine tools. MIT developed a machine that was able to control a
cutting tool path with a series of straight lines defined by axial coordinates at prescribed feed rates. The
first NC machine tool was introduced to the defense and aerospace industry by MIT in 1952. The contour
of a constantly changing curvature could be described by a series of short lines determined by a series of
coordinate in three axes.
The first machine tools were run with instructions or programs punched out on paper tape. The files of
the early machine tools were often in the format which later became known as G-code. The reason for
the name being that many of the lines of text began with the letter G.
In an NC machine, the tool is controlled by a code system that enables it to be operated with minimal
supervision and with a great deal of repeatability. "CNC" (Computerized Numerical Control) is the same
type of operating system, with the exception that a computer monitors the machine tool.
The same principles used in operating a manual machine are used in programming a NC or CNC Machine.
The main difference is that instead of cranking handles to a position on a slide to a certain point, the
dimension is stored in the memory of the machine control once. The control will then move the machine
to these positions each time the program is run.
The operation of the VF-Series Vertical Machining Center requires that a part program be designed,
written, and entered into the memory of the control. There are several options for getting these programs
to the control. RS-232 (serial port with a computer), 3.5 Floppy Disk, Ethernet / Networking/ and USB are
all viable ways to transmit and receive programs.
In order to operate and program a CNC controlled machine, a basic understanding of machining practices
and a working knowledge of math are necessary. It is also important to become familiar with the control
console and the placement of the keys, switches, displays, etc., that are pertinent to the operation of the
machine.
This manual is intended to give a basic understanding of CNC programming and its applications. It is not
intended as an in-depth study of all ranges of machine use, but as an overview of common and potential
situations facing CNC programmers. Also use of the new Haas Control feature Intuitive Programming
System or (IPS) will be demonstrated. It will produce G-Code programs for simple machine operations.
UpdatedCK11/14/11;Rev02/19/13
Productivity Inc - Haas CNC Mill Programming Manual Page 5
The principle of machine home may be seen when doing a reference return of all machine axes at
machine start-up. A zero return (POWER UP/RESTART) is required when you power on machine, all three
axes are moved to extreme positive locations until limit switches are reached. The reason the machine
does this is to double check its position with the Home switches of the machine.
This is crucial to the operation and function of a CNC machine as all of our programs, fixturing, and tooling
are based off of machine home.
Above:Therelationshipofmachinehometoworkhome,otherwiseknowasworkoffset
A work coordinate (otherwise known as a part offset) is how we tell the machine where our part (or parts)
are located at in the travels of the machine. Under the Work Offsets page in the control, we hand wheel
the machine to the X & Y Zero location for our part, and use the Part Offset Measure key under the
Reset key to set the corresponding work offset from our program (G54, G55, G56, etc..)
G54 59 Work Offsets #1 6
These are the first G-Codes that were assigned to work Coordinates. This is how we tell the machine that
we are working on Part #1, Part #2, etc. thru Part #6. Originally no one thought we would need more
than 6 part offsets, but thru time and the invention of new types of machines, more were needed..
G110 G129 Work Offsets #7 26 (Older Machines)
G154 P1-P99 Work Offsets #7-106 (Newer Machines)
These codes are the same as G54 to G59; they add more places as X & Y zero. We now can set up to 99
additional zeros within the travels of our machine.
MORE WORK COORDINATE SYSTEM SELECTION
Note: The G52 command works differently depending on the value of Setting 33. This setting
selects the FANUC, HAAS, or YASNAC style of coordinates, which are listed below.
G52 Global Work Coordinate Shift
G52 will shift all work offsets that are set in the machine. In the Work Offsets page of the control, if we
input a value of X +1.0000, ALL of the offsets will move one to the right by a value of 1.0000. This is most
commonly used in casting and forging work where we have core movement.
G53 Positioning In Regards to Machine Home (Non Modal)
G53 is used inside a program when we want to move the machine a certain distance and location from
Machine Home. This is quite often used if we want to establish a safe tool change position because we
have large parts or tools and need to clear the tool changer.
G92 Set Work Coordinate System
G92 Can be used to set our work offsets while on the fly in our program. G92 was used back when
machines only had one offset to choose from. We had to cut our first part, move the spindle over to the
second part X&Y zero, and then call G92 X0Y0 in our program. Our work offset is now set around the
second part. Using G54 G129 is much faster, more tunable, and easier to use.
There are two different systems used in positioning our machine. Both will steer the machine where we
need it to go, both can net the same results. The reason we use more than one, is flexibility. Below we
will talk about both, and they are the first two G-Codes that we are going to talk about.
Absolute Positioning:
With absolute positioning, we tell the machine where to move based on a common point, called X0 Y0 and
Z0. Every time we need to move to a certain position, the ending point of that move is in direct
relationship to this common point
G90 Absolute Positioning
Program to move the machine to these
4 hole locations when using G90 (Abs.)
X 1.0000 Y 1.0000
X 9.0000 Y 1.0000
X 9.0000 Y 9.0000
X 1.0000 Y 9.0000
Incremental Positioning:
With incremental positioning, we are telling the machine where to go in relationship to where it currently
is at. Basically like a set of directions given from where the machine stopped last.
G91 Incremental Positioning
Program to move the machine to the same
4 hole locations using G91 (Incr.)
X 1.0000 Y 1.0000
X 8.0000
Y 8.0000
X -8.0000
When do we decide which to use?
We switch between the two when it is more convenient. Once example is look at the above 2 prints.
Sometimes the print doesnt call out the hole-locations, but will give the distance between the holes.
Productivity Inc - Haas CNC Mill Programming Manual Page 10
The Cartesian Coordinate System
This unit will give a broad overview of word address programming; all alpha codes and their basic
functions will be discussed.
Objectives:
The definition of G code is typically referred to as a preparatory function. They establish the mode of
operation that the machine needs to be in to accomplish what the programmer intends. Imagine a rotary
switch like that on an older TV; we are just turning the switch to different modes.
Before considering the meaning and the use of codes, it is helpful to lay down a few guidelines:
1) Codes come in groups. Each group of codes will have a specific group number. (Imagine each group
of codes as a knob on a TV)
2) A G code from the same group can be replaced by another code in the same group. By doing this,
the programmer establishes modes of operation. The universal rule here is that codes from the same
group cannot be used more than once on the same line. (We cannot have a knob in two different
positions)
3) There are modal G codes, which, once established, remain effective until replaced with another code
from the same group (Like a light switch on a car, turn the switch on it stays on till it is turned off)
4) There are non-modal G codes which, once called, are effective only in the calling block and are
immediately forgotten by the control (Like a horn in a car, it is only on momentarily)
The rules above govern the use of all codes for programming the Haas (and other) controls. The concept
of grouping codes and the rules that apply will have to be remembered if we are to effectively program
the machine tool. The following is a discussion of the codes most basic to the operation of the machine.
The following two pages display a summary of the G codes, A " * " indicates the default within each group,
if there is one:
Productivity Inc - Haas CNC Mill Programming Manual Page 19
Code: Group: Function:
G00 *01 Rapid Motion
G01 01 Linear Interpolation Motion
G02 01 CW Interpolation Motion
G03 01 CCW Interpolation Motion
G04 00 Dwell
G09 00 Exact Stop (non-modal)
G10 00 Programmable Offset Setting
G12 00 CW Circular Pock Milling (Yasnac)
G13 00 CCW Circular Pock Milling (Yasnac)
G17 *02 XY Plane Selection (circular interpolation)
G18 02 ZX Plane Selection (circular interpolation)
G19 02 YZ Plane Selection (circular interpolation)
G20 06 Inch Programming Selection
G21 06 Metric Programming Selection
G28 00 Return to Machine Zero through Reference Point
G29 00 Move to Location through G28 Reference- never used
G31 00 Skip Function (used in probing)
G35 00 Automatic Tool Diameter Measurement (probing)
G36 00 Automatic Work Offset Measurement (probing)
G37 00 Automatic Tool Length Measurement (probing)
G40 *07 Cutter Comp Cancel
G41 07 Cutter Compensation Left
G42 07 Cutter Compensation Right
G43 08 Tool Length Compensation
G44 08 Tool Length Compensation (never used)
G47 00 Engraving
G49 *08 G43/G44 Cancel
G50 11 G51 (scaling) Cancel
G51 11 Scaling (option)
G52 12 Select Work Coordinate System G52 (global work shift) (Yasnac)
G52 00 Set Local Coordinate System (Fanuc)
G52 00 Set Local Coordinate System (HAAS)
G53 00 Non-Modal Machine Coordinate Selection
G54 *12 Select Work Coordinate System l
G55 12 Select Work Coordinate System 2
G56 12 Select Work Coordinate System 3
G57 12 Select Work Coordinate System 4
G58 12 Select Work Coordinate System 5
G59 12 Select Work Coordinate System 6
G60 00 Unidirectional Positioning (never used)
G61 13 Exact Stop Modal
G64 *13 G61 Cancel
G65 00 Macro Subroutine Call (used in conjunction with P value)
G68 16 Rotation (option, comes with probing)
G69 16 G68 Cancel
Productivity Inc - Haas CNC Mill Programming Manual Page 20
Code: Group: Function:
G70 00 Bolt Hole Circle (Yasnac)
G71 00 Bolt Hole Arc (Yasnac)
G72 00 Bolt Holes Along an Angle (Yasnac)
G73 09 High Speed Peck Drill Canned Cycle
G74 09 Reverse Tap Canned Cycle
G76 09 Fine Boring Canned Cycle
G77 09 Back Bore Canned Cycle
G80 *09 Canned Cycle Cancel
G81 09 Drill Canned Cycle
G82 09 Spot Drill Canned Cycle
G83 09 Peck Drill Canned Cycle (for deep holes)
G84 09 Tapping Canned Cycle
G85 09 Boring Canned Cycle
G86 09 Bore/Stop Canned Cycle
G87 09 Bore/Manual Retract Canned Cycle
G88 09 Bore/Dwell Canned Cycle
G89 09 Bore Canned Cycle
G90 *03 Absolute positioning
G91 03 Incremental positioning
G92 00 Set Work Coordinates - FANUC or HAAS
G92 00 Set Work Coordinates - YASNAC
G94 05 Feed per minute
G95 05 Feed per revolution
G98 *10 Initial Point Return
G99 10 R Plane Return
G100 00 Disable Mirror Image
G101 00 Enable Mirror Image (comes with probing)
G102 00 Programmable Output to RS-232
G103 00 Block Look ahead Limit (used in conjunction with P value)
G110-G129 Select Coordinate System 7 thru 26, group 12
G154 P1-P99 Select Coordinate System 7 thru 106 (Newer Machines) group 12
G136 00 Automatic Work Offset Center Measurement
G150 00 General Purpose Pocket Milling
G187 00 Accuracy Control for High Speed Machining
Productivity Inc - Haas CNC Mill Programming Manual Page 21
Machine Functions (M Codes)
Typical Haas M Codes:
M Codes are used by the programmer to turn on and off certain functions of the machine. Think of M
codes as codes that turn on and off different Machine Functions.
M00 Stop Program
The M00 code is used to stop a program. It also stops the spindle and turns off the coolant and
stops interpretation look ahead processing. This is used to force the operator to interact with the
machine (such as check a dimension, flip a part over, blow chips from a hole to tap, etc)
M01 Optional Program Stop
M01 works much like M00, providing the OPT STOP mode is ON. If this mode is turned on, the
machine will stop at M01, if it is turned off, it is ignored. Often used when the operator has
discretion on stopping the machine or not (usually at a tool change)
M03 Spindle Forward
The M03 code will start the spindle moving in a clockwise direction at whatever speed was
previously set. The machine will stop and wait for acceleration of the spindle to full speed prior to
moving to ensure the spindle is ready to make a cut.
M04 Spindle Reverse
The M04 code will start the spindle moving in a counterclockwise direction at whatever speed was
previously set.
M05 Spindle Stop
The M05 code is used to stop the spindle. The block is delayed until the spindle slows below 10
rpm.
M06 Tool Change
The M06 code is used to initiate a tool change. The previously selected tool (Tn) is put into the
spindle. If the spindle was running, it will be stopped. No previous axis commands are required
before the tool change unless there is a problem with tool/part/fixture clearance. The Z-axis will
automatically move up to the machine zero position and the selected tool will be put into the
spindle. The Z-axis is left at machine zero. The spindle will not be started again after the tool
change but the Snnnn speed and gear will be unchanged. The Tnn must be in the same block or in
a previous block. The coolant pump will be turned off during a tool change and a air purge will
open to keep chips out of the spindle.
M08 Coolant On
The M08 code will turn on the coolant supply. Note that the M code is performed at the end of a
block so that if a motion is commanded in the same block, the coolant is turned on after the
motion. The low coolant status is only checked at the start of a program so that a low coolant
condition will not stop a program which is already running.
Productivity Inc - Haas CNC Mill Programming Manual Page 22
M09 Coolant Off
The M09 code will turn off the coolant supply.
M10 Engage 4
th
Axis Brake
The M10 code is used to apply the optional brake to the 4
th
axis. It is only used when M11 is used
to release the brake.
M11 Release 4
th
Axis Brake
The M11 code will pre-release the 4
th
axis brake. This is useful to prevent the delay otherwise
occurring when a 4
th
axis is used with a brake and a motion is commanded in that axis. It is not
required, but without a prior M11, there will be a delay in motion in order to release the air.
M16 Tool Change
The M16 code is used to initiate a tool change. In the present machine configuration, M16 works
exactly like M06. (normally not used)
M19 Orient Spindle
The M19 code is used to orient the spindle to a fixed position. This command leaves the spindle in
that position and locked by a pin. The next spindle motion command (Snnnn, M3, M4, M41, or
M42) will release the pin and unlock the spindle.
M21-M24 Optional User M
The M21 through M24 codes are optional for user interfaces. They will activate one of relays 25
through 28, wait for the M-fin signal, release the relay, and wait for the M-fin signal to cease. The
RESET button will terminate any operation that is hung-up waiting for M-fin.
M27 Release Fifth Axis Brake, Wait for M-fin Signal
This code activates the fifth axis brake relay, which must be connected to relay M27 on the I/O
board. It activates the relay, waits for the M-fin signal, releases the relay upon receipt, and waits
for the M-fin signal to cease. The RESET key will terminate any operation that is hung-up waiting
for M-fin.
M30 Program End and Rewind
The M30 code is used to stop a program. It also stops the spindle and turns off the coolant. The
program pointer will be reset to the first block of the program and stop. The parts counters
displayed on the Current Commands display are also incremented. M30 will also cancel tool
length offsets.
M31 Chip Conveyor Forward
M31 starts the chip conveyor motor in the forward direction.
M32 Chip conveyor Backward
M32 starts the chip conveyor motor in the reverse direction.
M33 Chip Conveyor Stop
M33 stops conveyor motion.
Productivity Inc - Haas CNC Mill Programming Manual Page 23
M34 Increment Coolant Spigot Position Up
M34 increments the current spigot position up one place. When the machine loads a tool, and it is
equipped with the PCOOL option, it will associate a Coolant Position (0 is all the way up, 30 is
almost strait down) with each tool and change the coolant nozzle position for each individual tool.
M34 will pull the nozzle up one position from where it currently sits. If we need to go up three
positions, we need to call M34; M34; M34. One can actually use the nozzle to blow chips out of a
hole with a dwell and a series of M34 commands.
M35 Decrement Coolant Spigot Position
M35 increments the current spigot position down one place. When the machine loads a tool, and
it is equipped with the PCOOL option, it will associate a Coolant Position (0 is all the way up, 30
is almost strait down) with each tool and change the coolant nozzle position for each individual
tool. M35 will pull the nozzle down one position from where it currently sits.
M39 Rotate Tool Turret
The M39 is used to rotate the tool turret without performing a tool change. If you have a large
tool in an Umbrella Style tool changer, and are worried about running it into the part while
machining, we can index the turret to move the tool to the back of the sheet metal.
M41 Low Gear Override
If your machine has the optional high torque gear box option, M41 will force the machine into low
gear. Usually the machine will decide what gear to use based on RPM (0-1000 RPM uses low gear,
1000RPM and higher uses high gear)
M42 High Gear Override
If your machine has the optional high torque gear box option, M42 will force the machine into
high gear. Usually the machine will decide what gear to use based on RPM (0-1000 RPM uses low
gear, 1000RPM and higher uses high gear). This is useful if dont need all that torque at a lower
RPM.
M51-M58 Optional User M On
M51 through M54 codes are optional for user interfaces. They will activate one of relays 17
through 24 and leave it active. These are the same relays used for M21-M28. Use M61-M68 to
turn these off. The RESET button will turn off all of these relays.
M59 Output Relay Set (N)
M61-M68 Optional User M Off
The M61 through M68 codes are optional for user interfaces. They will deactivate one of relays
17 through 24. These are the same relays used for M21-M28.
M69 Output Relay Clear (N)
M76 Disable Displays
This code is used to disable the updating of the screen displays during high speed machining. It is
used to increase the speed of the central processing unit in the controls of the Haas machine tool.
M77 Enable Displays
This code is used to enable the updating of the screen displays at the end of high speed
machining.
Productivity Inc - Haas CNC Mill Programming Manual Page 24
M80 Automatic Door Open (option)
M81 Automatic Door Close (option)
M82 Tool Unclamp
This code is used to release the tool from the spindle. It is not normally needed since tool change
operations do this automatically and a manual TOOL RELEASE button is available to the operator.
This M code is not recommended for use since the tool will be dropped from the spindle and may
damage the tool, the machine, or your setup.
M83 Auto Air Jet On (option)
M84 Auto Air Jet Off (option)
M86 Tool Clamp
This code will clamp a tool into the spindle. It is not normally needed since tool change operators
do this automatically and a manual TOOL RELEASE button is available to the operator.
M88 Thru the Tool Coolant On (option)
This code turns on high pressure coolant thru the tool. Make sure you have a thru the tool
retention knob and also a tool with holes for thru the tool capability.
M89 Thru the Tool Coolant Off (option)
M95 Sleep Mode (Long Dwell)
This code may be used to warm up the machine before operation. Format: M95(hh:mm)
The lines following may call up the spindle warm-up program (M98 P2020)
M97 Local Sub-Program Call
M97 is a code that we use to jump from where we currently sit in our program and to jump to a
different spot in the program. We follow the M97 with a P word that corresponds with a line
number. M97 P100 = Jump to line N100
M98 Sub Program Call
M98 works like M97, but jumps us out of the program we are currently in, and to another
program entirely. This is most often used when we have similar functions or features on different
parts (such as pockets, bolt hole patterns, etc.). M98 P510 = Jump to Program O510.
M99 Sub Program Return or Loop
M99 is used when we need to return from our M97 or M98 program jump. It tells the machine go
back from where you came. If we do not use a M97 or M98, but put in a M99, the machine will
jump to the beginning of the program and re-run the program.
Productivity Inc - Haas CNC Mill Programming Manual Page 25
The sequence of events necessary to successfully develop a CNC program will be discussed in detail in this
unit.
Objectives:
Upon completion of this unit, the student will:
1) Be familiar with the proper sequence of events that should be followed when developing a CNC
program.
2) Be able to define Safety Line and be familiar with the codes it contains.
3) Understand critical information that must be included before and after each tool.
4) Be capable of following an existing program and explain the sequence of events that it follows.
5) Understand the definition and purpose of default values.
Productivity Inc - Haas CNC Mill Programming Manual Page 26
Program Format
Program format, or style, is an important part of CNC machining. Each individual will have their own way
to format their programs differently but in most cases, a programmer could not identify a program
written by them 6 months after they wrote it. The point is that a programmer needs to be consistent and
efficient by writing code in the way it is listed and in the order it appears in the program. For example: X,
Y, Z, should be written in order of appearance. The machine will read X, Y, or Z in any order, but we want
to be consistent. Write X first, Y second, Z third. This will help ensure confidence and trust between you
the programmer and others who may use the program.
We should start any program with a safety line even though it may be redundant, we want to put our G
Code Switches (Grouping of G Codes) in the position we intend on using them at the start of our program.
G00 puts machine in a rapid mode. G17 selects the X-Y plane for circular interpolation. G40 cancels cutter
compensation. It is a good idea to cancel Tool Length Comp (G49). G80 cancels any canned cycles. G90
puts machine in absolute. G98 instructs machine to return to initial start point in any canned drill cycles.
This will FORCE the machine into what we want it to do. We do not want to assume the machine is already
set the way we want it.
G00 G17 G40 G49 G80 G90 G98 (SAFETY LINE)
The next line we want to return to machine zero in Z, the tool index position.
G28 G91 Z0 or (G00 G53 Z0)
The next line we want to enter is a tool change. The correct tool may be in the spindle already, and we
dont need to do a tool change to run our part, but the next time we start our program, that tool may not
be in the spindle. Force the machine to put the tool we want in the spindle. Never assume it is already
there.
T1 M06 (LOAD TOOL 1)
The fourth line or block will contain a rapid command (G00), an absolute or incremental command (G90,
G91), a work zero for X and Y (G54), a positioning X and Y coordinate, a spindle speed command (S---), and
a spindle ON clockwise command (M03).
G0G90G54 X______Y_____S_____M03 (RAPID, ABSOLUTE, OFFSET #1, SPINDLE ON)
The next line will contain a "read tool length compensation" command (G43); a tool length offset number
(H0l ), a Z-axis positioning move (Z.1), and an optional coolant ON command (M08).
G43 H01 Z1.0 M08 (TOOL LENGTH COMP OFFSET #1, GO TO Z1.0, TURN COOLANT ON)
An example program's first five lines will look like this:
G00 G17 G40 G49 G80 G90 G98;
G00 G53 Z0;
T1 M06;
G00 G90 G54 X0 Y0 S2500 M03;
G43 H01 Z1.0 M08;
All the necessary code is listed above for each approach we will make towards the part. There are several
variations on the above code that will work and net the same results, and it is up for you to decide what
you like best, but once you do, stay with it and be consistent!
Productivity Inc - Haas CNC Mill Programming Manual Page 27
QUESTION: If G00, G90, and G54 are defaults, why do we list them in the second line of a program and for
each different tool?
ANSWER: G00, G90, and G54 are listed for an operator/setup person's aid so he/she can determine if the
machine will rapid position, if the machine is in fact in the absolute coordinate mode, and most important,
the work zero. The work zero is always different between setups, and multiple work zeros are very
common.
QUESTION: Can we combine the third and forth lines excluding the M08 code? If so, why do we write the
lines separately?
ANSWER: Yes. The four G codes G00, G90, G54, and G43 all belong to different groups. Remember, no
two G codes of the same group can be listed on the same line.
The main reason for using two lines is SAFETY. Remember, only one line of information can be executed
at a time. The X and Y coordinates will position first and then the tool length and the Z coordinate move
will be executed. If combined, all three axes will move simultaneously, and any interfering clamps or
fixtures can be struck and/or destroyed. Combining an X, Y, and Z move together will increase the chance
of crashing the machine.
Machine Defaults
When we first power up the control, the machine loads it software and parameters, and the machine
needs to go to some sort of base settings as far as our G-Codes are concerned. The switches have to be
turned to some sort of position, and we call these the defaults.
The control automatically reads these G codes when power is turned on:
G00 Rapid traverse
G17 X, Y Circular plane selection
G40 Cutter Compensation cancel
G49 Tool length compensation cancel
G54 Work coordinate zero #1 (1 of 109 available)
G64 Exact stop cancel
G80 Canned cycle cancel
G90 Absolute programming
G98 Initial point return
There is no default FEED RATE (F code), but once an F code is programmed, it will apply until another is
entered or the machine is turned off.
The spindle is also set to a speed of 0 RPM when first turned on, so a S command is needed in order to
turn on the spindle even in manual mode.
A program is just a set of written instructions given in the order they are to be performed.
Imagine if we could send the machine an E-Mail in plain English telling it what we wanted it to do. The
program would look something like this:
STEP #1 = SELECT CUTTING TOOL
STEP #2 = TURN THE SPINDLE ON AT A CERTAIN RPM
STEP #3 = TURN THE COOLANT ON
STEP #4 = RAPID TO OUR START POSITION
STEP #5 = MAKE OUR CUTS AT A CERTAIN FEED RATE
STEP #6 = TURN OFF THE SPINDLE AND THE COOLANT
STEP #7 = RETURN TOOL TO HOME AND SELECT NEXT TOOL
and so on. But our machine control only understands these messages when given in machine code.
Why do we use G&M Code and not a different language (English for example)?
CNC Machines were first built in the 1940s and 50s with the invention of computers. They were custom
built, and several companies were trying to come to market with the first consumer available NC machine
tools.
It was the early 60s before CNC machines became commercially available, and not only was the machine
invented, so was the computer, and the software to run the computer. These first computers were limited
and didnt have enough memory to remember an entire language such as English. So Code had to be
invented, and was limited to words that had one letter and two numbers behind it (G 0 0 for Example).
Several inventors came out with machine and controls in the early days, and each one had to invent their
own code. Soon there were several brands and several different kinds of code. This is when the ISO
(International Standards Organization) said they were going to set a Standard code. They went with the
code that was by far the most popular at the time, FANUC. This is why it is also referred to as Fanuc G-
Code
The basics of this code remain the same to this day. Things get added from time to time, and it just adds
new codes to the end of the G-Code list. Last code invented was G187 Machine Accuracy Control, and
came out in the late 1990s. The first G-Codes were G00, G01, G02, and G03. They were established in the
50s. As a new need for a new machine mode is invented, new G-Codes will get added on to the list.
Why do we stick with the code since technology has come so far?
Standardization and Familiarity: It has been a great benefit in many ways. Operators and programmers
trained on one machine can move to another brand, control, shop, etc and with a little familiarization
can get up to speed quickly. Companies can share programs.
Productivity Inc - Haas CNC Mill Programming Manual Page 29
Program Structure
In the CNC world, the term Block is used to define what we know as a line of code. The reason it is
called a block is that the machine can read the entire line all at once, not from left to right as we are used
to. A typical program consists of one or more blocks of commands.
After each block we need to end the block with a semi-colon (;). On the operators panel, the EOB key (End
of Block) will generate this symbol. This is how the machine tells one line of code from the next.
The " / " symbol, sometimes called a back slash, is used to define an optional block. A block that contains
this symbol can be optionally deleted when the machine is in the block delete mode (BLKDEL) when
running a program.
The machine does not read left to right as we do, again it takes a whole block in at one time. We can
arrange our G-Codes, M-Codes, and Alphabetic Address Codes (X, Y, Z, etc..) in any order we want. The
rules are we can have one (G-Code) from each group, only one (M-Code), and alpha characters on each
line. The machine will ALWAYS run the G-Codes and alpha characters first and the M-Code last.
PROGRAM START-UP LINES
G00 G17 G40 G49 G80 G90 G98 (Safety Line)
G00 Rapid
G17 Selects X-Y Work Plane
G40 Cancels Cutter Comp
G49 Cancels Tool Length Offset
G80 Cancels Canned Cycle
G90 Absolute
G98 Initial Point Return for canned cycles
G91 G28 Z0 G28 This preparatory function causes a return to machine zero of all
(G00 G53 Z0) specified axes. If an X, Y or Z are specified, only those axis
move incrementally (G91) to machine home.
T1 M06 T1 Selects tool number one to be loaded into the spindle.
M06 Activates the tool change sequence.
G90 G54 G00 X__ Y__ S1200 M03
G90 Activates control to be in ABSOLUTE.
G54 Selects work coordinate system No. 1.
G00 Preparatory function for a Rapid Movement.
X__ Axis move to initial X position.
Y__ Axis move to initial Y position.
S1200 Informs the control that 1200 has been selected as the RPM for this tool
M03 Turns the spindle ON in a clockwise direction at a speed of 1200 RPM.
G43 H01 Z.1 M08 G43 Activates the tool length stored in the H code offset number.
H01 Informs control as to what the stored offset value is.
Z.1 Informs the control to move from full spindle retract to this Z value and
apply the tool length offset.
M08 Turns the coolant ON.
Productivity Inc - Haas CNC Mill Programming Manual Page 30
CUTTING TOOL PATH LINES
PROGRAM ENDING LINES
G00 Z1. M09 G00 Preparatory function for a Rapid Movement.
Z1. Retracts tool tip to 1.0 above PART or PROGRAM ZERO in preparation for
full spindle retract.
M09 Turns the coolant off.
G00 G49 G91 G28 Z0 M5
G28 This preparatory function causes a return to machine zero of all axes. If an X,
Y and Z are specified, only the axis specified will be moved to machine zero.
Machine must be in incremental mode (G91).
G49 Cancels Tool Length Offset
M5 Stop spindle rotation
(G00 G90 G53 Z0) G53 Non-modal selects machine coordinates.
G28 G91 Y0
(G53 Y0) G91 Preparatory function for INCREMENTAL mode, which is required for rapid
move to the G28 reference point.
Z0. This will ensure a full retract, of Z axis in the UP direction to machine zero.
Y0 Ensure Y axis is in the full out position for ease of loading and unloading.
M30 M30 Signals END OF PROGRAM AND REWIND to the control. The program will
reset to the first block of the program and stop. It also stops the spindle,
turns off the coolant and cancels tool length offsets. It also makes the
control ready for the next cycle.
Now with our numbers we need to input, we are somewhat limited when we go past the decimal, and
there are some unique ways of programming. In the early days, the controls didnt have enough memory
or smarts to even allow for a decimal, so all values were entered in what is called an 8 character
assignment. All numbers had to have 8 numbers, 4 in front of the decimal, 4 behind:
10.000 = 00100000
1.0000 = 00010000
.0010 = 00000010
.0003 = 00000003
As controls got smarter, they eventually were able to integrate a decimal into the machines. But, the
above programming method is still viable. With that said, when we are entering a whole unit (such as 1
inch) we need to input the decimal (1 inch should be 1.0). If we input the number one, with no decimal
behind it, the machine will read it as .0001, and one tenth of one thousandth is a long way away from 1.0
Productivity Inc - Haas CNC Mill Programming Manual Page 31
Tool paths are the movements that we program once we have loaded our tool, turned our spindle on, and
have approached the part. It is the motion that we generate with a particular tool to generate the shapes
and sizes we need to complete our parts.
Objectives:
Upon completion of this unit, the student will:
1) Understand the major differences in G01 and G00.
2) Understand and apply the five criteria needed to produce an arc.
3) Understand the principles of programming and applications with and without cutter
compensation and the advantages and disadvantages of each.
4) Be capable of producing a tool path program, containing lines and arcs, with and without cutter
compensation.
5) Be capable of determining feeds and speeds given an SFM and cutting tool, and be capable of
determining feed rate given an RPM and chip load.
6) Be able to integrate a tool path into a part program.
7) Understand the rules governing the use of cutter compensation.
8) Have a basic understanding of the concept of arc in/arc out and some of its applications.
Productivity Inc - Haas CNC Mill Programming Manual Page 32
Linear/Circular Movement Creating Tool Path
Tocutacompletecircleof360degrees,programI,J,orKtodefinethecenterofthecircle.You
donotneedtospecifyX,Y,orZasanendingpoint.Thefollowinglinewillcutacompletecircle:
G02I-2.5 (thiscommandwillinterpolatea360degrees,5.0diametercircle)
TheIandJvaluescanbedefinedfor90-degreecornersorfillets.
G02 Circular Interpolation Clockwise Command Using R
The letter address R can be substituted for the letter addresses I, J, and/or K for various corners or
fillets, which is more easily defined.
Just as I, J, and K are used to locate the ARC CENTER in relation to the START POINT, R serves the
same function with less input.
G03 Circular Interpolation Counterclockwise Command
G03 Works exactly the same as G02, all that changes is the direction of the arc (clockwise vs.
counterclockwise)
Productivity Inc - Haas CNC Mill Programming Manual Page 37
Positive R vs. Negative R
The first R capable controls were able to use the R, but only up to 180 degrees. The reason being, is that
for any two points in space, when a radius is defined, there are actually two paths that will use both points
and that defined arc that are correct. One is less than 180 degrees, one is greater. We only could use the
arcs less than 90 degrees. Eventually, we had enough computing power to tell the machine which one we
want. Examples are below.
The following line will cut an arc less than 180 degrees using an R positive:
G90 G54 G00 X-.25 Y-.25
G01 Y1.5 F12.
G02 X1.884 Y2.384 R1.25
To generate an arc of more than 180 degrees using a negative R minus:
G90 G54 G00 X-.25 Y-.25
G01 Y1.5 F12
G02 X1.884 Y.616 R-1.25
Dnn Cutter Compensation Value The actual offset amount must be input in the specified tool offset
display number. On the HAAS you have 200 tool offsets to use. Usually, you will have only one cutter
offset for a tool, and it is best to use the same cutter offset number as is the tool number. The cutter
GEOMETRY column, in the offset display, is to set the initial cutter offset value. It can be designated as
either a DIAMETER value or a RADIUS value by selecting the one you would like to use with SETTING 40.
The selection chosen will be listed at the top of the offset geometry column. The WEAR column on the
right of the tool GEOMETRY column is for any adjustments needed to make the initial tool GEOMETRY
offset. These values are added together by the control and used as one value.
Understanding cutter compensation can be simplified if one has a basic understanding of manual
machining. There are two common types of cutting conditions associated with milling machines:
1) CLIMB
2) CONVENTIONAL
Two common rules for these types of cuts are:
If the programmed cutter path needs to mill CLIMB cutting and it is a standard right handed tool,
it will then be programmed with G41 cutter LEFT of the programmed path.
If the programmed cutter path needs to mill with CONVENTIONAL cutting and it is a standard
right handed tool, it will then be programmed with the G42 cutter RIGHT of the programmed
path.
Program without cutter compensation:
G00 X-2.35 Y-2.
G01 Z-.45 F10
X-2.25
Y1.5
G02 X-1.5 Y2.25 R.75
G01 X1.5
G02 X2.25 Y1.5 R.75
G01 Y-1.5
G02 X1.5 Y-2.25 R.75
G01 X-1.5
G02 X-2.25 Y-1.5 R.75
G01 X-2.25
Productivity Inc - Haas CNC Mill Programming Manual Page 42
Program with cutter compensation (Diameter value for D01 would be .500 entered into diameter offset
register #1):
G00 X-2.35 Y-2.0
G01 Z-.45 F10
G41 X-2. D01 (turn on CC with an X and/or Y move)
Y1.5
G02 X-1.5 Y2. R.5
G01 X1.5
G02 X2. Y1.5 R.5
G01 Y-1.5
G02 X1.5 Y-2. R.5
G01 X-1.5
G02 X-2. Y-1.5 R.5
G40 G01 X-2.35 (turn off CC with an X and/or Y move off part)
Productivity Inc - Haas CNC Mill Programming Manual Page 43
When programming without cutter compensation to the center of the cutter, a problem occurs cutting
angle geometry. The cutter center must be offset to the part geometry to maintain the cutter tangency.
For example, the Y-axis move from Point A to Point B must have the Delta Y calculated dimension
added to the .75 dimension. The X-axis move from Point B to Point C must have the Delta X calculated
dimension subtracted from the 1.25 dimension.
Drilling, Tapping, Boring Canned Cycles
Early on in NC, if we needed to drill a deep hole and had to peck our drill to get it to depth, we had to
program each peck with 3 lines of code. A feed move in, a rapid move out, & a rapid move back in to the
hole.
If we had to make 20 pecks in a hole, it would take 60 lines of code. Again, with the acceleration of
computer technology, we were able to take all of this and condense it to one line of code, this is referred
to as a canned cycle.
Objectives:
Upon completion of this unit, the student will:
1) Be able to define canned cycle.
2) Be familiar with common canned cycles, their variables, the proper applications, and the correct
deployment of them.
3) Understand the usage of the L variable to loop canned cycles.
Productivity Inc - Haas CNC Mill Programming Manual Page 49
Canned Cycles
A canned cycle is used to simplify programming of a part. Canned cycles are defined for the most
common Z-axis repetitive operations such as drilling, tapping, and boring. There are 13 canned cycles to
choose from. Once selected, a canned cycle is active until canceled with G80.
There are five operations involved in every canned cycle:
1) positioning of X and Y axes (and optional A),
2) rapid traverse to R plane,
3) drilling, tapping and boring,
4) operation at bottom of hole,
5) retraction to R plane.
Once a Canned Cycle code is turned on, every time we move to a new X & Y location the machine will drill
a hole. This will continue until we cancel the drilling with a G80 code. This is how canned cycles save time.
If we had 100 holes in a part, we would save 6000 lines of code in the example above.
Canned cycles are presently limited to only operations in the Z-axis. That is, only the G17 X-Y plane is
allowed. This means that the canned cycle will be executed in the Z-axis whenever a position is selected
in the X or Y axes. The operation of a canned cycle will vary according to whether incremental (G91) or
absolute (G90) is active.
G98 and G99 are modal commands that change the way canned cycles operate. When G98 is active, the
Z-axis will return to the start position (initial plane) when it completes an single operation. When G99 is
active, the Z-axis will be returned to the R point (plane) when the canned cycle completes a single hole.
Then the machine will go to the next hole.
Productivity Inc - Haas CNC Mill Programming Manual Page 50
The following is a summary of the canned cycles defined for the VF Series Mill:
G
Code
Z Drilling
Direction
Operation at Bottom of
Hole
Retraction
Z Direction
Application
G73 Intermittent Feed None Rapid High Speed Peck Drilling
G74 Feed Spindle CW Feed Left Hand Tapping
G76 Feed then Stop Orient Spindle Rapid Fine Boring
G77 Rapid to Bottom Orient Spindle Back Bore/Rapid Back Boring
G81 Feed None Rapid Spot Drilling
G82 Feed Dwell Rapid Counter Boring
G83 Intermittent Feed None Rapid Peck Drilling
G84 Feed Spindle CCW Feed Tapping Cycle
G85 Feed None Feed Boring Cycle
G86 Feed Spindle Stop Rapid Boring Cycle
G87 Feed Spindle Stop Manual/Rapid Back Boring
G88 Feed Dwell, then Spindle Stop Manual/Rapid Boring Cycle
G89 feed Dwell Feed Boring Cycle
Incremental motion in a canned cycle is often useful as a loop (L) count, which can be used to repeat the
operation with an incremental X or Y move between each cycle.
NOTE: If an L0 is in the canned cycle line, the cycle will not execute until the control reads the next
X or Y location.
The G80 code is used to cancel a canned cycle. In addition to this, a G00 or G01 code will also cancel any
active canned cycle.
Once a canned cycle is defined, the canned cycle is repeated at every X-Y position in sequential blocks.
Some of the canned cycle numerical values can also be changed after the canned cycle is defined. The
most important of these are the R plane value and the Z depth value.
If these are changed in a block with an X-Y, the change doesnt take effect until the next block. All
subsequent blocks are performed with the new R or Z value.
Changes to the G98/G99 selection can also be made after the canned cycle is active. If changed, the new
G98/G99 value will be active in the next block and all subsequent blocks.
Productivity Inc - Haas CNC Mill Programming Manual Page 51
G80 Canned Cycle Cancel
This G code is modal in that it deactivates all canned cycles G73, G74, G76, G77, or G81-G89 until a new
one is selected. Note that the use of G00 or G01 will also cancel a canned cycle.
G81 Drill Canned Cycle Straight Drilling without Peck
F Feed Rate in inches (mm) per minute
R Position of the R plane
X Optional X-axis motion command
Y Optional Y-axis motion command
Z Position of bottom of hole
N1 T1 M06
N2 G90 G54 G00 X.3 Y.3
N3 S1200 M03
N4 G43 H01 Z1. M08
N5 G81 Z-.6 R.1 F10.
N6 X1.2 Y1.2
N7 G80 G00 Z1. M09
N8 G28 G91 Z0. M05
N9 M30
This G code is modal in that it activates the canned cycle until it is canceled or another canned cycle is
selected. Once activated, every motion of X or Y will cause this canned cycle to be executed.
Productivity Inc - Haas CNC Mill Programming Manual Page 52
G85BoringCannedCycleFeedDownandFeedUp
F FeedRateininches(mm)perminute
R PositionoftheRplane
X OptionalX-axismotioncommand
Y OptionalY-axismotioncommand
Z Positionofbottomofhole
N1T1M06
N2G90G54G00X.3Y.3
N3S1200M03
N4G43H01Z1.M08
N5G85Z-.6R.1F10.
N6X1.2Y1.2
N7G80G00Z1.M09
N8G91G28Z0.M05
N9M30
ThisGcodeismodalinthatitactivatesthecannedcycleuntilitiscanceledoranothercanned
cycleisselected.Onceactivated,everymotionofXorYwillcausethiscannedcycletobe
executed.
CANNED CYCLE AUXILIARY FUNCTIONS
G98 Canned Cycle Initial Point Return
This G code is modal and changes the way canned cycles operate. With G98, the canned cycle will return
to the initial starting point of the canned cycle when it completes a hole before moving to the next hole.
G99 Canned Cycle R Plane Return
This G code is modal and changes the way canned cycles operate. With G99, the canned cycle will return
to the R plane when the canned cycle completes before moving to the next hole.
Productivity Inc - Haas CNC Mill Programming Manual Page 68
Productivity Inc - Haas CNC Mill Programming Manual Page 69
Looping Command Cycles
Below is an example of a program using a drilling canned cycle that is incrementally looped.
Compare the grid plate drawing on the following page to the program below.
%
03400 (Drilling grid plate)
T1 M06
G00 G90 G54 X1.0 Y-1.0 S2500 M03
G43 H01 Z.1 M08
G81 Z-1.5 F15. R.1
G91 X1.0 L9
G90 Y-2.0 (Or stay in G91 and repeat Y-1.0)
G91 X-1.0 L9
G90 Y-3.0
G91 X1.0 L9
G90 Y-4.0
G91 X-1.0 L9
G90 Y-5.0
G91 X1.0 L9
G90 Y-6.0
G91 X-1.0 L9
G90 Y-7.0
G91 X1.0 L9
G90 Y-8.0
G91 X-1.0 L9
G90 Y-9.0
G91 X1.0 L9
G90 Y-1 0.0
G91 X-1.0 L9
G00 G90 G80 Z1.0 M09
G28 G91 Y0 Z0
M30
%
NOTE: The sequence of drilling used here is designed to save time and to follow the shortest path from
hole-to-hole.
Productivity Inc - Haas CNC Mill Programming Manual Page 70
Productivity Inc - Haas CNC Mill Programming Manual Page 71
Bolt Hole Patterns
There are three G codes that provide patterns usually used for bolt holes. These are G70, G71, and G72.
These G codes must be used with one of the canned cycles G73, G74, G76, G77, or G81-G89. The starting
angle is from 0 to 360.0 degrees CCW from horizontal starting from Three oclock.
G70 Bolt Hole Circle
I Radius (Minus Reverses Starting Position)
J Starting angle (0 to 360.0 degrees CCW from horizontal)
L Number of holes evenly spaced around the circle
The tool must be positioned at the center of the circle either in a previous block or in the G70 block. G70
belongs to Group zero and thus is non-modal. For a G70 to work correctly, a canned cycle should be active
so that at each of the positions, some type of drill or tap cycle is performed.
G71 Bolt Hole Arc
I Radius
J Starting angle (degrees CCW from horizontal)
K Angular spacing of holes (+ or -)
L Number of holes)
This G code is similar to G70 except that it is not limited at one complete circle. G71 belongs to Group
zero and thus is non-modal. For a G71 to work correctly, a canned cycle should be active so that at each of
the positions, some type of drill or tap cycle is performed.
G72 Bolt Holes Along An Angle
This G code drills L holes in a straight line at the specified angle. It operates similarly to G70 and G71. G72
belongs to Group zero and thus is non-modal. For a G72 to work correctly, a canned cycle should be active
so that at each of the positions, some type of drill or tap cycle is performed.
Example of G70 Bolt Hole Circle program used in conjunction with G83 Peck Drill Cycle.
%
O100
T1 M6
G0 G90 G54 X0 Y0 S1000 M3
G43 H1 Z1.0 M8
G83 Z-2.0 R.1 Q.2 F1.5 L0
G70 I1.0 J0 L8
G00 G80 Z1.0 M9
G53 Z0
G53 Y0
M30
%
Fig. 8 - 8 Round island programming using G150
O0500
G01 X0 Y0
X6.0
Y6. 0
X0
Y3.0
X2.0
G02 I1.0
G01 X 0
Y0
M99.
Productivity Inc - Haas CNC Mill Programming Manual Page 92
G150 EXERCISE:
Mill pocket using a 4 flute End Mill, to a final pocket depth of .5 inch. Step down in .25 increments.
Run end mill at surface feed of 120 ft/min with a chip load of .002in/rev. Set middle of part as the origin
for programming.
04500 (G150 pocket exercise)
T1 M06 (1/2 Drill tool #1 cuts entry for end mill)
G90 G54 G00 X0 Y0 (starting hole position)
S2000 M03
G43 H01 Z1.0 M08
G83 Z-.50 R.1 Q.25 F10.
G80 G00 Z1.0 M09
G28 G91 Z0 M05
T2 M06
G00 G90 G54 X0 Y0 S____ M03
G43 H2 Z.1 M08
G01 Z0 F10.
G150 X ____ Y____ Z____ F___ R___ Q___ I____ K___ P4600 D___ G41 OR G42
G00 Z1.0 M09
G28 G40 G91 Y0 Z0
M30
04600
G01 X____ Y____
X____
Y____
G ___X____ Y____ R____
G___ X_____
G___ X_____Y____ R____
Y_____
G1_____
X_____
M99
Productivity Inc - Haas CNC Mill Programming Manual Page 93
Engraving (G47)
G47 ENGRAVING GROUP 00
E = Plunge rate (units/min)
F = Engraving feed rate (units/min)
I = Angle of rotation (-360. to +360.), default is 0.
J = Scaling factor in inches (minimum = 0.001 inches), default is 1.0 inch
P = l for Sequential Serial Number Engraving
= 0 for Literal String Engraving
R = Return plane
X = X start of engraving
Y = Y start of engraving
Z = Depth of cut
The text to engrave should be in the form of a comment on the same line as G47, with either a P1 or P0
before it. P1 selects Sequential Serial Number Engraving and P0 selects Literal String Engraving.
SEQUENTIAL SERIAL NUMBER ENGRAVING
This method is used to engrave numbers on a series of parts, with the number being incremented by one
each time. The '#' symbol is used to select the number of digits in the serial number. For example: G47
P1 (#### )
will limit the serial number to four digits.
The initial serial number can be either programmed or set manually. If it is programmed , for example:
G47 P1 (1234)
This code will set the initial serial number to "1234".
The initial serial number can also be set manually into a macro variable. The "MACROS" option does not
have to be enabled to do this. Macro variables are temporary storage locations for numbers. Macro
variable #599 is used to hold the initial serial number to be engraved. To set this variable, go to the
CURNT COMDS page and press the PAGE DOWN key until the "Macro Variables" page appears. Then type
in "599" and press the (DOWN ARROW). Now enter the desired initial serial number at the cursor and
press the WRITE key. For example, when macro variable #599 is set to "1234",
G47 P1 (####) will produce this: 1234
If the number in macro variable #599 has more characters than specified in the format string, only the
quantity specified will be printed. For example, if #599 is set to"12345" and only four places are specified
in the format string, only "2345" will be engraved.
Productivity Inc - Haas CNC Mill Programming Manual Page 94
LITERAL STRING ENGRAVING
This method is used to engrave desired text on a part. The characters available for engraving are:
A..Z
a..z
0..9
! # & ( ) * + , / : ; < = > ? [ \ ] ^ { }
However, programs downloaded through the serial port or the floppy drive can take advantage of
characters not available on the mill keypad. For Literal String Engraving, the text should be in the form of
a comment on the same line as the P0 statement.
For example: G47 P0 (ENGRAVE THIS)
will produce: ENGRAVE THIS
Note that P0 is used, instead of P1, for Literal String Engraving.
Productivity Inc - Haas CNC Mill Programming Manual Page 95
EXAMPLE
This example will create the engraving opposite.
O05555 (TEXT ENGRAVING)
T7M06
G00 G90 G98 G54 X2.0 Y2.0
M03 S3000
G43 H07 Z0.03 M08
G47 P0 X2.0 Y2.0 I45.J.5 R.05 Z-.005 F15.0 E10.0 (TEXT TO ENGRAVE)
G00G80Z0.03M09
M05
G28G91Z0
G00G90G54X0Y0
M30
In this example:
G47 P0 select Literal String Engraving
X2.0 Y2.0 select 2.0, 2.0 as the starting point for the text.
I45. places the text at a positive 45 degree angle
J.5 sets the text height to 0.5 inch
R.05 commands the cutter to retract to .05 inches (mm) above the cutting plane after
engraving each character
Z-.005 selects a .005 inch (mm) deep cut
F15.0 selects an engraving feed rate of 15 units/min
E10.0 commands the cutter to plunge at a rate of 10 in/min
Productivity Inc - Haas CNC Mill Programming Manual Page 96
Subroutines (Subprograms)
Subprograms are a very important part of CNC programming, however, they can make programming
become more complicated. This unit will give a brief introduction to subprograms and some of their basic
applications.
Objectives:
Upon completion of this unit, the student will:
1) Have a good working definition of a subprogram.
2) Understand the basic application and deployment of subprograms.
3) Know the differences between M97 (local) and M98 (separate) subprogram options.
4) Be able to integrate a subprogram into a standard program to achieve the desired results.
5) Looping subprograms with an L variable.*
A subprogram is a separate program called up by another program. The use of subprograms can
significantly reduce the amount of programming on some parts. Subroutines allow the CNC programmer
to define a series of commands that might be repeated several times in a program and, instead of
repeating them many times, can be called up when needed.
A subroutine call is performed using an M97 or M98 and a Pnnnn. The P code command identifies the O
program number being used when executed with M98 or an N sequence number to identify the block
where a local subroutine starts when executed with M97.
Local subroutines are called with an M97. This can be easier to use than the M98 because the subroutine
is contained within the main program without the need to define a separate Onnnn program. With local
subroutines, you define an M30 for the end of your main program portion followed by a sequence
number to define the beginning of your subroutine.
This subroutine call causes the blocks in the subroutine to be executed as if they were included in the
main program. To return back to the main program, you need to end the subroutines with an M99, which
sends it back to the next line after the subroutine call in the main program.
Another important feature of a subroutine call is that the M98 block may also include an L (loop) or
repeat count. If there is an Ln with the subroutine call, it is repeated that number of times before the
main program continues with the next block.
The most common use of subroutines is in the definition of a series of holes, which may need to be center
drilled, peck drilled, taped, and/or chamfered. If a subroutine is defined that consists only of the X-Y
position of the holes, the main program can define the canned cycles and the hole locations can be called
up in the subroutine to do each of the tool operations. Thus, the X-Y positions can be entered only once
and used several times for each tool.
O0100 (main program using subroutines);
T01 M06 (center drill);
G90 G54 G00 X0.5 Y0.5;
S2000 M03;
G43 Z0.5 H01;
G81 Z-0.3 R0.1 F15. (define canned cycle);
M98 P0200 (call subroutine O200);
T02 M06 (peck drill);
G90 G54 G00 X0. 5Y 0.5;
S1500 M03;
G43 Z0.5 H02;
G83 Z-1. R0.1 Q.100 F10. (define canned cycle);
M98 P0200 (call subroutine O200);
T03 M06 (1/4 20 tap);
G90 G54 G00 X.5 Y.5;
S400 (G84 will turn spindle on, no M03 is needed);
G43 Z1. H03;
G84 Z-1. R.1 F10. (define canned cycle);
M98 P0200 (call subroutine O200);
Productivity Inc - Haas CNC Mill Programming Manual Page 98
T04 M06 (chamfer);
G90 G54 G00 X.5 Y.5;
S2500 M03;
G43 Z0.1 H04;
G81 Z-0.1 R0.1 F20. (define canned cycle);
M98 P0200 (call subroutine O200);
G28 Y0.;
1. M30 (end of main program);
(SUBROUTINE) (LISTING ALL THE HOLE POSITIONS)
O0200
X1.5;
X2.5;
X2. Y1.;
X1.;
X.5 Y1.5;
X1.5;
X2.5;
G80 Z1.0 M09;
G28 G91 Z0. M05;
M99 (end of subroutine);
To return back to the main program, you need to end the subroutines with an M99, which sends it back to the next line after
the subroutine call in the main program.
O0300 (example using a local subroutine);
T1 M06;
G90 G54 G00 X.5 Y.5;
S2000 M03;
G43 Z1.0 H01;
G81 Z-0.1 R0.1 F20 (define canned cycle);
M97 P0500 (call local subroutine using sequence N#);
T02 M06 (peck drill);
G90 G54 G00 X.5 Y.5;
S1000 M03;
G43 Z1. H02 M08;
G83 R0.1 Z-1. F10. (define canned cycle);
M97 P0500 (call local subroutine using sequence number 500);
G28 Y0.;
M30 (end of main program);
N0500 (local subroutine example listing all hole positions);
X1.5;
X2.5;
Y1. X2.;
X1.;
X0.5 Y1.5;
X1.5;
X2.5;
G80 G00 Z1. M09;
G28 Z0. M05;
M99 (end of local subroutine);
Productivity Inc - Haas CNC Mill Programming Manual Page 99
Exercises
Canned Cycle Exercise #1
TOOL NUMBER ONE
Diameter Center/Spot Drill (use G81 canned cycle)
surface speed (SFM) = 190
feed inch/rev = .0035
TOOL NUMBER TWO
Diameter Drill (use G83 canned cycle)
surface speed (SFM) = 190
feed inch/rev = .006
TOOL NUMBER THREE
3/8 Diameter 4 flute End Mill (use G82 canned cycle)
surface speed (SFM) = 190
inch/rev/tooth = .003
Productivity Inc - Haas CNC Mill Programming Manual Page 100
O0068 (CANNED CYCLE EXERCISE)
N1 (1/2 DIA. SPOT DRILL)
G53 Z0 G49
T__ M__
G__ G__ G__ X.__ Y.__ M__S____
G__ Z._ H__ M__
G__ Z-.___ R__ F__ L_
M__ P___
M_
N2 (1/4 DIA. DRILL)
T_ M__
G__ G__ G__ X___ Y___ M__ S____
G__ Z___ H__ M__
G__ Z-___ R__ F__ Q.____ L_
M__ P____
M__
N3 (3/8 DIA. ENDMILL)
T__ M__
G__ G__ G__ X___ Y___ M__ S____
G__ Z___ H__ M__
G__ Z-___ R___ F___ P___ L_
M__ P____
G__ G__ Y_
M__
N1000 (HOLE SUBROUTINE)
X___ Y___
Y___
X___
Y___
G__ G__ Z___ M__
M__
Productivity Inc - Haas CNC Mill Programming Manual Page 101
Canned Cycle Exercise #2
TOOL NUMBER ONE
5/8 Diameter Spot Drill (use G81 canned cycle)
surface speed (SFM) = 190
feed in/rev. = .0035
TOOL NUMBER TWO
27/64 Diameter Drill (use G73 canned cycle)
surface speed (SFM) = 190
feed in/rev = .006
TOOL NUMBER THREE
-13 Tap (use G84 canned cycle)
600 RPM
Productivity Inc - Haas CNC Mill Programming Manual Page 102
O0071(CANNED CYCLE EXERCISE)
N1 (5/8 DIA. SPOT DRILL)
T__ M__
G__ G__ G__ X.___ Y.____ M__S____
G__ Z.___ H__ M__
G__ Z-.___ R__ F___ L_
M__ P____
M_
N2 (27/64 DIA. DRILL)
T__ M__
G__ G__ G__ X___ Y___ M__ S____
G__ Z___ H__ M__
G__Z-___ R___ F__ L_ Q.____
M__ P____
M__
N3 (1/2 - 13 TAP)
T__ M___
G__ G__ G__ X___ Y___ M__ S____
G__ Z___ H__ M__
G__ Z-___ R__ F____ L_
M__ P____
G__ G__ Y___
M__
N2000 (HOLE SUBROUTINE)
X___ Y____
X____
X____
X___Y___
X___
X ___Y___
X___
X___
G__ G__ Z___ M__
M__
Productivity Inc - Haas CNC Mill Programming Manual Page 103
FINAL EXERCISES
Tool #1 - 2.00 diameter 4 flute end mill finish diamond shape contour 1 pass at .3 depth
275 SFM - .005 inch/rev per tooth
Tool #2 1 diameter insert drill rough 1.800 circular pocket at .480 depth
250 SFM - .0075 inch/rev
Tool #3 5/8 diameter 4 flute end mill finish mill 1.800 diameter circular pocket .5 depth
220 SFM - .0045 inch/rev per tooth
Tool #4 diameter spot drill drill 6 holes .2 depth
200 SFM - .005 inch/rev
Tool #5 5/16 diameter drill (6) holes through
200 SFM - .005 inch/rev
Tool #6 3/8 16 tap (6) holes through
Tap at 600 RPM and your machine has rigid tapping
Tool #7- Engrave your name anywhere on the part using a1/8 inch ball end mill
Engrave at 200ft/min - .001 in/rev
Productivity Inc - Haas CNC Mill Programming Manual Page 104
CLASS EXERCISE
Tool #1 2.00 diameter 4 flute end mill - climb cut a finish pass around diamond shape contour - 1 pass at
.3 depth using cutter compensation.
275 SFM - .005 inch/rev per tooth
01234
T____ M____ (tool #1 2.00 diameter end mill)
G____ G____ G____ X____ Y____
M____ S____
G____ H____ Z____ M____
G____ Z____ F____
G____ Y____ D____ F____
X____
X____ Y____
X____ Y____
X____ Y____
X____ Y____
G____ Y____
G____ Z____ M____
G____ G____ Y____Z____
M____
Be sure to position cutter at least half the cutter diameter off of the part surface before canceling cutter
comp.
Productivity Inc - Haas CNC Mill Programming Manual Page 105
CLASS EXERCISE
Tool #2 1 3/4 diameter insert drill rough 1.800 circular pocket at .480 depth
Speed 250 SFM. Feed .0075 inch/rev
T____ M____ (tool #2 1 3/4 diameter insert drill)
G____ G____ G____ X____ Y____
M____S____
G____ Z____ H____ M____
G____ Z____ R____ F____
G____ G____ Z____ M____
G____ G____ Z____
M____
Productivity Inc - Haas CNC Mill Programming Manual Page 106
CLASS EXERCISE
Tool #3 5/8 diameter 4 flute end mill mill a 1.800 diameter circular pocket .5 depth
220 SFM - .0045 inch/rev per tooth
T____ M____ (tool #3 5/8 diameter 4 flute end mill)
G____ G____ G____ X____ Y____
M____S____
G____ Z____ H____ M____
G____ I____ K____ Q____ Z____ D____ F____
G____ Z____ M____
G____ G____ Z____
M____
Productivity Inc - Haas CNC Mill Programming Manual Page 107
CLASS EXERCISE
Tool #4 1/2 diameter spot drill spot drill 6 holes .2 depth
200 SFM - .005 inch/rev
Tool #5 5/16 diameter drill drill 6 holes through
200 SFM - .005 inch/rev
Tool #6 3/8 16 Tap (6) holes through tap at 600 RPM
Your machine has rigid tapping
T____ M____ (tool #4 1/2 diameter spot drill)
G____ G____ G____ X____ Y____
M____ S____
G____ Z____ H____ M____
G____ G____ Z____ R____ F____ L____
M____ P____
G____ G____ Z____
M____
T____ M____ (tool #5 5/16 diameter drill)
G____ G____ G____ X____ Y____
S____ M____
G____ Z____ H____ M____
G____ G____ Z____ R____ F____ L____
M____ P____
G____ G____ Z____
M____
Productivity Inc - Haas CNC Mill Programming Manual Page 108
T____ M____ (tool #6 3/8-16 tap)
G____ G____ G____ X____ Y____
M____ S____
G____ Z____ H____ M____
G____ G____ Z____ R____ F____ L___
M____ P____
G____ G____ Z____
M____
T____M____ (tool #7 1/8 ball end mill)
G____ G____ G____ X____ Y____
M___ S____
G___ H___ Z____ M____
G____ P___ X____ Y____I____J____ R____ Z____ F____ E____ (YOUR NAME)
G____G____Z____M____
M____
G____G____Z____
G____G____Y____
M___
(Subprogram)
O1000 (subprogram)
X-.___ Y-__.__
G__ __ X-___ Y-.___
Y.____
X__.__
G__ __ Y-.____
X.____ Y-__.__
G__ G__ Z__M__
M__ __