Preparatory Functions (G-Codes)
Preparatory Functions (G-Codes)
Example:
Notes:
Example:
Notes:
Syntax 1: G02 [two axis words (optional third)] [interpolation parameters] [optional feed word]
Syntax 2: G02 [two axis words (optional third)] [radius word] [optional feed word]
Example 1:
G17 (plane XY specified for clarity)
G00 X0 Y0 (get into start position)
G02 X2 Y0 I1 J0 F4
Example 2:
Moves from the current point to (2,0) in a
clockwise arc of 1 unit radius less than 180
degrees at 4 units per minute. Again, absolute
mode is assumed.
Notes:
I and J are incremental by default. (NOTE: In rev 3.00g and prior, the I and J word were
absolute in absolute mode, incremental in incremental mode. This is no longer the case. See
the dialect customizations section above for information on how to change this)
Using a negative radius chooses the arc greater than 180 degrees that crosses both points, a
positive radius takes the arc that is 180 degrees or less. The program will stop with a warning if
you have a radius that is impossible. The R form is notoriously inaccurate for arcs very close to
180 degrees.
The sense and 2D plane of the arc is set by the current plane mode. Axis words appropriate to
the plane must be included i.e.:
G17 – XY plane, X and Y [offsets I, J] [linear Z axis]
G18 – ZX plane, X and Z [offsets I, K] [linear Y axis]
G19 – ZY plane, Y and Z [offsets J, K] [linear X axis]
The order of parameters on the program line is not important. Use the I word for offset in the X
direction, J for offset in Y, and K for offset in Z to describe the relationship of center position
from the starting point. See the plane selector information section for more detail.
Start, destination and offset information for arcs can be specified using expressions, For
example:
Full Circles:
If the destination letters are omitted, or, the distance between the start and end points of the arc
is less than one full step for each axis on the plane, a full circle will be described by the tool
motion. You must specify the move using the IJK form when omitting the axis end points for a
full circle move, as the R form is indeterminate for these cases.
Feed rates are applied along the helix (i.e.: cutter path) during a three dimensional move.
If the specified feed rate is higher than either the computer, or the CNC machine, is capable of
achieving the feed rate will then be clamped at the system's maximum capability. The feed rate
is clamped at the lower of that specified by Mav Vel, or that sustainable by the acceleration
available at the axes. The formula used to determine the maximum feed rate based on
acceleration is dependent upon the radius of the arc and is computed as follows:
The following chart shows the effect of radius on the maximum feed rate for various
accelerations.
G03 CCW circular interpolation (3D)
Function: Moves to a new position in a counter-clockwise circular arc. The arc center is
specified with signed offsets from the start position or implicitly by the magnitude of the radius.
G04 Dwell
Function: Pauses execution for an integer number of seconds
Example:
Notes:
The P symbol and units of integer seconds are used. See the customization section for
instructions on how to change the unit of time to milliseconds.
WARNING
Never use G04 dwells and your hands as a tool-changer. It
!
takes longer than you think... Use M00 or M06 instead.
Background:
The original TurboCNC through rev 3.1a allowed an implicit plane specification in which the first
two axes called out on a G02/03 line became the plane of action for the interpolation. In this
mode, only the I and J parameters were used. The "I" offset was applied to the first axis on the
line, the "J" axis to the second. This affected G02, G03, G72, and G73. For the helical moves,
the third axis was always the direction of linear travel.
The idea here was to allow unusual interpolation schemes to be used on machines with many
axes or non-conventional axis names.
This code is no longer supported! Use the conventional plane selectors (G17 through 19) for
defining arc planes in new programs.
G18 Function: Sets plane for circular and helical interpolation to Z-X.
G19 Function: Sets plane for circular and helical interpolation to Z-Y.
Syntax: none
Notes:
For lathe users, if +Z is away from the headstock, and +X is increasing diameter, then in G18
mode CW/CCW will look reversed if you look down at the slide. This is because in this right
hand system, -Y is looking up.
Syntax: none
Notes:
All coordinates and feed rates will be in inches after this command is executed.
Saving the .ini file while in either mode makes it modal on startup.
Syntax: none
Notes:
All coordinates and feed rates will be in millimeters after this command is executed.
G20 and G21 are identical to G70 and G71.
Saving the .ini file while in either mode makes it modal on startup.
TurboCNC stores and uses all values in Imperial measure internally. This will cause very small
conversion errors (> 0.00001 inch or 0.000004 mm) to show up on the display in Metric mode.
Notes:
Each axis with a home switch will be driven to the home position where its coordinates will be
reset. G28 is often used to recalibrate your machine during long cycle times where temperature
creep or other position loss sources are a factor.
Each axis with a home switch moves simultaneously in the home direction.
As each home switch goes active, each axis will stop
When they are all on their switches, each axis will simultaneously move in the opposite
direction
As each home switch goes inactive, each axis will stop again
Each axis position is re-established as configured in machine coordinates
The speed of the homing action is set by the modal F word and current feed mode.
Example:
Notes:
The move works in a similar fashion to G01. If the probe hits something, the machines stops
and write the position to the file POINTS.DAT in the same directory as the executable.
If nothing is hit, the move ends at the position specified and no data is written.
Use G31 to get off of the part again if you need to, the program only accepts the inactive to
active transition as valid input.
WARNING Note that if you move twice in the same direction with G31 or any other
codes, you can smash your probe! Good practice is to design your probe
! with built in over travel that activates the panic stop input if exceeded.
G32 Probe cycle
Function: Repetitive probing to digitally scan a 2D or 3D surface
Syntax: G32 [axis bound 1] [bound 2] [optional bound 3] [discretization] [optional feed word]
Example:
Notes:
This is 2 or 3-axis general, so the last axis cycles the most and the first axis only once
through a number of points determined by the discretization distance. You need at least
two axes moving to scan. Using a single axis will move in the same way as G31.
The digitizing scheme is of the "bed of nails" variety, e.g.: straight up and down in the
last axis on the line.
The output is written to a scan file in the same directory as the executable, with a
filename of SURFSCAN.DAT.
WARNING Rounding error may prevent the last row or column from being
scanned. Add a small amount to the bounding distance to avoid
!
this:
G32 X1 Y1 Z-1 I0.250 F10 ;X1,Y1 ;may or may not be reached
G32 X1.001 Y1.001 Z-1 I0.250 F10 ;This is better
Example:
Notes:
A spindle index pulse must be enabled and present for this to work. See the section on hooking
up a spindle encoder for details on how to do this.
The program will time-out after 5 seconds of spindle pulse inactivity. Similarly, the operation will
be halted if the speed detected at the spindle is greater than 5000 rpm. This offers a measure of
protection against the failure modes of signal noise, signal loss, or stalls.
K is the lead parameter for the Z-axis, I is for X, and J is for Y. See the dialect customization
section if you want to specify pitches instead or change K for some other letter.
Multiaxis Operations: You can thread up to three axes simultaneously for tapered threading or
unusual machining situations like gear hobbing. The lead and distance should work out to an
equal number of revolutions for each. An axis with no lead specified will move at the regular
feed rate.
Allow a few revs of "lead in" for the axis to synchronize. You need a lot of acceleration to keep
up with the changes in velocity. If the axis falls behind and can't keep up, the program will stop
and warn you.
The synchronization is always from the start point for each pass, so for multi-start threads,
offset the start position by some fraction of the thread lead. For 30 degree infeed, change the
start position on each pass along a 30 deg vector.
Notes:
Put the probe inside the hole approximately in the center, and call G50 from within a program or
the MDI window.
This is an orthogonal six hit probing algorithm - clock positions struck are 12,6,9,3,12,6 in the
XY plane as you normally view the part on a mill. You must have a touch probe installed and the
probe input configured for this to work. Hole probing is always in the XY plane.
The speed of G50 probing is given by the modal feed word and mode.
Watch out for keyways and similar things that can throw you off. Use this command for auto-
setting boring operations or fixture locating where some part-to-part variation is expected and
you need to locate to a hole center exactly.
Syntax: none
Notes:
In master coordinate mode, no fixture offset is active. If tool 0 is set as well, you are in Machine
Coordinates. These are the coordinates that are active while homing, and in setting up feed
screw error compensation.
At startup, you are in machine coordinates by default. No offsets are active in machine
coordinate mode.
Syntax: none
Notes:
When the fixture offset is changed, all the tool offsets follow. Machining in a new offset mode is
like having "zero" in a new place on your machine.
The coordinates you see on the screen are the master coordinates + the fixture offset in use +
the tool offset in use. Tool 0 is no tool offset, G53 is no fixture offset.
The most common use for these is multiple fixtures on the same table. For example, home the
machine in G53. Your usual 6" vise can be "zeroed" in G54 mode, and the center of a 5C collet
vise, say, can be zero in G55. Changing modes puts you in a new coordinate system painlessly
and allows different classes of parts to be machined on a large table.
G53-59 are modal. A fixture offset stays in effect until a new one is commanded.
G70 Inch mode
Function: Sets distance unit to inches.
Syntax: none
Notes:
Same as G20.
Syntax: none
Notes:
Same as G21.
Background:
Originally (through version 3.1a), TurboCNC used G02 and G03 as strictly 2D arc functions, and
a separate G word for helical interpolation. This was unnecessary, and violated the Standard.
This function is no longer supported. Use G02 with a third axis callout instead.
This function is no longer supported. Use G03 with a third axis callout instead.
G76 Multi-pass threading
Function: Machines an OD or ID thread completely on a lathe.
Syntax: G76 [X coord] [Z coord] [K height] [D first pass] [F lead] [A tool nose angle]
Example:
Notes:
The starting point is returned to after each pass. The X location of the starting point determines
the back out distance after each cut it complete.
The A word specifies the included tool nose angle, which is customarily 60 degrees for common
threads. The tool will automatically feed on an angle of 1/2 A. If A is not specified, it defaults to
0, which produces a radial infeed.
K, D and F are always positive, regardless of the actual orientation or "hand" of the thread.
Each successive pass will remove the same area of material as the first pass did, in order to
equalize the torque load. This is standard, and helps to improve the finish.
Example:
X0.050 slowly
Z-1.250 slowly
X-0.025 slowly
Z0 rapidly
X0.100 slowly
Z-1.250 slowly
etc...
Notes:
The order of the operands defines the motion. The back-and-forth action will occur from the
current position of the first axis on the line to the position specified. The second axis called out
will eventually reach the position specified by feeding in increments of I each pass.
The sign of I is unimportant. Always use I for the infeed, no matter what other axes are being
used.
Infeed is applied to the second axis on the line. Creative use of this command can be made for
fly cutting / slab-milling or cutting deep blind slots on mills or trimming the edges of stock.
After each pass, the control "backs off" by 1 1/2 times the infeed. So if you're boring, make sure
you have enough clearance for the bar.
If the infeed doesn't divide into an even number of passes, a small finishing pass will be taken.
Syntax: G78 [axis of action] [peck distance] [optional feed word] [optional dwell]
Example:
Notes:
The sign of I is unimportant, but this code is always used with I, regardless of the actual letter
for the moving axis.
If you put in a dwell parameter with the P operator, a dwell in milliseconds will be taken at the
end of each pass.
A good use of this code is "peck turning" plastic on a lathe to keep the chips short.
G80 Cancel drill cycle
Function: Cancel canned drill cycle
Syntax: none
Notes:
It's good practice, but not strictly necessary, to put this code after a series of the G81, G82, or
G83 drill cycles. It clears the canned cycle variables from memory.
Some CAM programs automatically generate this code after every series of drilled holes.
Example:
Move the table to the XY position (1,1) specified; holding Z at the point it was before.
Notes:
This is the canonical RS-274D drill cycle. Drills a hole at a specific XY position, to a depth Z at
the current feed rate, and retracts to a release plane "R".
To drill another hole just like the first, just input the XY position on the next line:
Release plane: If the R plane is between the current Z position and the bottom of the hole, the
control will rapid to the R plane after moving XY and before drilling. If the R plane is "above"
where the drill is in Z at the start of G81, the control will rapid to the R plane first before moving
XY. This affords maximum safety without overly compromising speed.
Note that R is absolute in absolute mode, incremental in incremental mode! All the other
parameters behave similarly.
All of the coordinates (XYZR) need to be called out on the first G81. These will "stay in effect"
thereafter until G80 is called (modality). So, if you have a series of holes that are all to the same
depth, you can use this:
Syntax: Similar to G81, but requires a # parameter for the dwell at the bottom of the hole in
milliseconds.
Example:
Drills at coord (0,0.5) to a depth of Z=-1 at 10 IPM. Dwells for a quarter second, and then
retracts to Z=0.25.
Notes:
Dwell is in milliseconds for this code by default. This can be customized to seconds, or some
other letter chosen besides P for CAM compatibility.
Syntax: Similar to G81/82, but requires an I parameter for the peck increment when drilling.
Example:
Notes:
The dwell parameter (P) is optional with G83 as a convenient departure from the Standard. The
above example will dwell a quarter second at the end of each peck. The dwell is in integer
milliseconds by default.
The sign of Q is unimportant. The letters P and Q, and the dwell units are customizable.
Syntax: none
Notes:
In absolute mode, all axis words and many parameters refer to an absolute coordinate position.
G90/91 are modal. Either mode will stay in effect until the other is called.
Syntax: none
Notes:
In incremental mode, all axis words and many parameters are a signed offset from the current
position.
G90/91 are modal. Either mode will stay in effect until the other is called.
G92 Preload of registers/Set machine coordinates
Function: Set position without motion
Example:
This code sets the position of any or all axes to a specific value. Use this to reset the position
inside a program. No motion will occur.
In machine coordinate (G53 T0) mode, the machine coordinates themselves are updated.
In any fixture offset mode (G54-G59) and T0, the fixture offset is updated.
Syntax: none
Example:
In this mode, the length of time that each block will take to execute is controlled. The unit is the
reciprocal of length of time in minutes. (e.g.: 60 is 1/60th of a minute or one second).
G93/94/95 are modal to one another. Each mode will stay in effect until another is called.
This mode is useful for unusual situations where the feed rate is difficult to calculate directly, but
the overall time to move is known - such as when several axis types are moving simultaneously.
As with the other feed modes, if the commanded feed rate is too fast for the machine, the
motion will be performed at the fastest available speed.
With arcs, each arc segment is treated as an individual block in this mode.
Syntax: none
Notes:
G93/94/95 are modal to one another. Each mode will stay in effect until another is called.
Example:
Notes:
Be sure to have set the "S" word for spindle speed when calling this function for the first time
before any motion takes place. You can also read the spindle speed after engaging G95 mode
by using the M50 code if you have a spindle encoder on your machine.
G93/94/95 are modal to one another. Each mode will stay in effect until another is called.
Example:
This function is a "placeholder" in the source code. Registered users can use it as a starting
point to program their own spindle control routines into TurboCNC.
If you use units/rev feed rates by calling G95, you must use this code or otherwise set the S
parameter with the spindle speed before trying to move.
Syntax: G178 [axis of action] [peck distance] [optional feed word] [optional dwell]
Example:
Notes:
This command is single axis only, and is identical to G78, except that no retracts are made
while machining. Only the dwells are taken.
In some cutting situations you can use this to avoid dangerous continuous chips while
machining, and saving a significant amount of time in the process by not retracting fully.
Notes:
This code operates in exactly the same manner as G83, except that it does not retract at all
between each peck. The dwells are taken.
In some cutting situations you can use this to avoid dangerous continuous chips while
conserving machining time if many holes are to be drilled.
Miscellaneous Functions (M-Codes)
Supported Miscellaneous Functions
Miscellaneous Functions are generally simpler than Preparatory Functions and seldom have
parameters.
Notes:
Comments included in the block containing M00 are displayed within the prompt that is raised.
A vertical bar, '|' can be used to force a new line. This feature is a convenient method of
presenting instructions to the machinist at runtime.
Notes:
Similar to M00. Use Optional Halts under the machining options menu to toggle whether these
are enabled.
This is commonly used for "first article" type checks while the part is on machine.
Comments included in the block containing M01 are displayed within the prompt that is raised.
A vertical bar, '|' can be used to force a new line. This feature is a convenient method of
presenting instructions to the machinist at runtime.
Notes:
Comments included in the block containing M02 are displayed within the prompt that is raised.
A vertical bar, '|' can be used to force a new line. This feature is a convenient method of
presenting instructions to the machinist at runtime.
M03 Spindle on CW
Function: Turns on spindle in the clockwise direction.
Notes:
Clockwise is the usual direction for a lathe or mill. If the spindle is commanded to run forward
while it is already on, it will be shut off for 7 seconds and then re-activated in the new direction.
Notes:
Similar to M03.
Turn the spindle off with M05 before changing directions or calling M03/04. If the spindle is
commanded to reverse while it is already on, it will be shut off for 7 seconds and then re-
activated in the new direction.
Notes:
Turns off the spindle output line. No braking is assumed. The spindle direction line state is not
affected.
Example:
Notes:
This is essentially the same as M00, but with a prompt to tell the user which tool is being
requested. Registered users may program their own, more sophisticated routines for automated
tool changes here.
The T word is required with M06. It may also be placed on any program line to change the tool
offset without pausing the program.
If the tool turret index line is enabled, M06 will not prompt the user, but activate the turret index
line briefly instead. The default time period is two seconds, the maximum period is 120 seconds.
The delay period for the turret index line is set in the ini file or the configuration menu under the
General heading.
Comments included in the block containing M06 are displayed within the prompt that is raised.
A vertical bar, '|' can be used to force a new line. This feature is a convenient method of
presenting instructions to the machinist at runtime.
Notes:
This code is traditionally associated with flood coolant. It can be used as a generic output to
control anything.
M08 Coolant B on (mist)
Function: Turns on relay B.
Notes:
This code is traditionally associated with mist coolant. It can be used as a generic output to
control anything.
Notes:
Both coolant outputs (A and B, see M07 and M08) will be set to inactive.
M10 Clamp
Function: Closes a machine clamp
Example:
Use numbers 0-15 for the clamps. If Q is not specified, it defaults to clamp 0.
At a minimum, the clamp drive, direction, and closure sense lines need to be configured on the
machine to use this command.
The clamp address appears on the four clamp select output lines in binary, if they are
configured on the machine. Clamp 0 is all lines inactive; clamp 15 sets all lines active.
You do not need to configure all 4 clamp select lines. For example, if you only have four clamps
to control then it is permissible to use the first two clamp select lines only.
The clamp will be driven until the closure line goes active, or when 15 seconds has elapsed,
whichever comes first.
M11 Unclamp
Function: Identical to M10, except that it opens a machine clamp.
Notes:
At a minimum, the clamp drive, direction, and open sense lines need to be configured on the
machine to use this command.
The clamp will be driven until the open line goes active, or when 15 seconds has elapsed,
whichever comes first.
Notes:
The Stepper World SP3 and some versions of the MAXNC drives require an enable signal in
order to operate. After the drive enable output lines have been configured in TurboCNC, use
this code to turn them on.
Notes:
Notes:
When this code is executed, the Collet Open line goes active for a short time, and then returns
to the inactive state. The default length of time is two seconds and the maximum is 120.
Change the length of time allowed by editing the ColletOpenTime(ms) entry in the ini file.
No feedback is required from the actual machine. This is designed to work with a pneumatic
collet closer on a lathe.
The delay periods for M21 and M22 are set in the ini file or the configuration menu under the
General heading.
Notes:
Similar to M21, this code activates the Collet Close output line for some length of time. Two
seconds is the default, 120 seconds is the maximum. Change the length of time allowed by
editing the ColletCloseTime(ms) entry in the ini file.
Notes:
Functionally identical to M02. Hard disks don't need to be "rewound" of course, but paper tapes
used to be! Some CAM programs generate this code instead of M02 at the end of a program, so
it's here for compatibility.
Comments included in the block containing M30 are displayed within the prompt that is raised.
A vertical bar, '|' can be used to force a new line. This feature is a convenient method of
presenting instructions to the machinist at runtime.
M40 – M46: Gear Changes
Function: Selects the speed map associated with the specified gear.
Notes:
Spindle speed control is oriented to the Sherline spindle. As such the default compilation only
implements M40 through M43. Increase MaxRatios in the spdmap unit to 7 to take advantage
of the full range of codes.
Notes:
This brings the feed override back to whatever it was just before the most recent M49 call.
Notes:
This resets the feed override to 100% "from the inside". Use it before entering a critical section
of your program that requires an exact feed rate. The feed override can be restored with the
M48 code.
Notes:
This reads the spindle speed into the program for use with per revolution feed rates (see G95)
by reading the spindle index pulse.
You must have an index pulse enabled to use this code. See the hardware section for details on
how to set this up.
The operation will time out if five seconds goes by without a signal from the spindle.
An error will be triggered if the spindle appears to be going faster than 5000 rpm.
Example:
The jump target word is set to 'O' by default. This can be reconfigured using the
'Configure/Dialect' menu.
Jumps to the line with the N word identical to the jump target word (N0100 in the example).
The N word of the line with the M98 is saved for the return (10 in the example). Naturally, this
means you should have a different N word on both the calling line and the target line.
Syntax: M62
Example:
See M60
Notes:
The next block to be executed will be found on the line following the most recent M60 call.
See SAMPLE.CNC for a simple nested subroutine example. Please note that when using
subroutines, you'll need a unique N code on each calling line so that the program knows where
to go back to.
To visualize program execution with subroutines, imagine all the code in the subroutine invisibly
pasted in beneath the calling line. None of the modal codes are affected.
Notes:
Two PLC handshaking lines can be configured in TurboCNC. These are for telling external
logic, such as an automatic tool changer or what-have-you to do some work. M70 sets the
output handshake line to the inactive state. This can also be used to control extra solenoids or
relays.
Notes:
Similar to M70, M71 sets the output handshake line to the active state.
Notes:
When this code is called, the program stops running and waits for the PLC input line (separate
from the output line) to go to the inactive state. This is intended to be used to synchronize the
program with external logic that might be loading more stock, or performing some other
function.
M73 Wait for PLC handshake input to go active
Function: Wait for PLC handshake input to go active
Notes:
Similar to M72, this pauses until the PLC line goes to the active state. With either of these two
codes, the user can press a key to bypass the wait condition.
M97 Jump
Function: Jump to a new block
Example:
The jump target word is set to 'O' by default. This can be reconfigured using the
'Configure/Dialect' menu.
Jumps to the line with the N word identical to the jump target word (N0200 in the example).
Code following an M97 in a block is not executed. M-Codes within a block are executed first, in
the order that they are encountered. Only the parameters that follow the M97 for M-Codes
encountered earlier in the block will be used. Every other code or parameter is ignored.
The jump function is very useful when combined with 'Conditional Programming'
If there is a parsing error in the line containing the jump target, the message 'Jump Target not
Found' will be displayed.
Example:
The jump target word is set to 'O' by default. This can be reconfigured using the
'Configure/Dialect' menu.
Jumps to the line with the N word identical to the jump target word (N0100 in the example).
The N word of the line with the M98 is saved for the return (10 in the example). Naturally, this
means you should have a different N word on both the calling line and the target line.
If there is a parsing error in the line containing the jump target, the message 'Jump Target not
Found' will be displayed.
Syntax: M99
Example:
See M98
Notes:
The next block to be executed will be found on the line following the most recent M98 call.
Code following an M99 in a block is not executed. M-Codes within a block are executed first, in
the order that they are encountered. Only the parameters that follow the M99 for M-Codes
encountered earlier in the block will be used. Every other code or parameter is ignored.
See SAMPLE.CNC for a simple nested subroutine example. Please note that when using
subroutines, you'll need a unique N code on each calling line so that the program knows where
to go back to.
To visualize program execution with subroutines, imagine all the code in the subroutine invisibly
pasted in beneath the calling line. None of the modal codes are affected.
If there is a parsing error in the line containing the jump target, the message 'Jump Target not
Found' will be displayed.