CNC Tips and Techniques A Reader for Programmers

CNC Tips and Techniques
A Reader for Programmers
Peter Smid

During the past decade, Peter Smid wrote dozens of column for Shop Talk magazine that addressed the full gamut of CNC topics, such as tapping and threading and knurling; program length and memory needs; G-codes, M-functions, cycles, macros … and more still.

Ever since Shop Talk ceased publication, these columns have been unavailable. Now, in CNC Tips and Techniques, we are delighted to bring them back—over 60 of the best of Peter’s columns --- all under one cover, so that you can have full and easy access to the advice Peter has been sharing during the past decade.

CNC Tips and Techniques is a treasure trove of Peter Smid’s “lost work” that is certain to be an invaluable addition to your CNC toolkit.  We hope the advice and instructions contained in these readings will help you do your job more efficiently and more effectively – and that you find them a good read besides.


  • Offers more than 60 focused columns which have been thoroughly reviewed since its initial publication and updated as needed to reflect ongoing changes in the field.
  • Columns are presented here in chronological order of when they first appeared.
  • Includes an alternative table of contents, organized by topic.
  • Provides several useful appendices and an extensive index.
  • Appeals to both veterans and newcomers with tips and techniques that can be applied at work and speed up the learning curve.

Sample Readings

 1. Programming a Long Thread
 2. Trial Cut for Measuring
 3. Special-Purpose G-Codes
 4. Running the First Part — Economically, That Is
1. Programming a Long Thread
In the essay Limitations in Threading, the main focus was on limitations in single point threading caused by spindle speed that is either too high or too low. In this essay, we look at the effect of threading feedrate, particularly how it applies to long threads.

What exactly is a long thread may be a subject for some discussion. For the purposes of this article, a long thread is a thread with a ratio of rather small diameter to long threading length. In most everyday threading operations, you will work with threads that have a length relatively short respective to their diameter. These threads, which do not require any physical support at the machine, generally do not present any problems in programming or machining. Machining long threads does have a few challenges, however. Long threads often require suitable support devices, at least a tailstock for basic support, but often a follower rest or a steady rest as well, in order to prevent deflection of the part.

Many CNC machine tool builders provide lathes specially designed for machining long parts, such as shafts and tubular stock. These lathes (often of the flat bed type) are also capable of threading over their entire Z-axis travel. From the CNC programmer's perspective, a possible problem lies with the feedrate for certain imperial threads. Feedrate for threading is always the thread lead, and no rounding is necessary for metric threads. Some imperial threads have to use rounding for feedrate calculation, when the threads per inch (TPI) are converted to the thread lead (cutting feedrate).

As an example of a possible problem of feedrate rounding, consider a single start, standard form 60 degree thread 6.0-12, over the threading length of 70 inches (actual use of the thread is not important for the illustration):

•Thread diameter = 6.0 inches
•Thread per inch (TPI) = 12
•Length of thread = 70 inches

Assuming a suitable tooling and part setup, the thread cutting program is easy:

N51 T0500

N52 G97 S550 M03  (SPINDLE SPEED 550 RPM)

N53 G00 X6.25 Z0.4 T0505 M08  (START POINT CLEARANCE)

N54 G76 P011060 Q005 R0.002  (G76 - BLOCK 1)

N55 G76 X5.8978 Z-70.0 R0 P0511 Q0120 F0.0833  (G76 - BLOCK 2 - 0.0833 IPR)

N56 G00 X12.0 Z5.0 T0500   (TOOL CHANGE CLEARANCE)

N57 M01

All program data look reasonable, but let's focus on the programmed feedrate of F0.0833. For twelve threads per inch, the pitch is 1/12 = 0.08333333, which is also the thread lead and programmed feedrate. Now, consider the feedrate actually used in the program, F0.0833. It has been rounded to four decimal places, as is customary for imperial dimensions.

Inevitably, the rounding has brought in a certain amount of inaccuracy. Over one inch length, the error is:

1 - 12 * 0.0833 = 0.0004 inches

In most cases, this error can be absorbed by the thread tolerances. Now, consider the same error over a significant thread length, such as our example of 70 inches:

70 * 0.0004 = 0.0280 inches — this is a significant error

Because the 0.0833 amount was the correct rounding to four decimal places, any other rounding would make the accumulative error even worse. The solution to this problem is quite simple — just change the programmed feedrate of F0.0833 to a new feedrate of F0.083333, from four to six decimal places. Fanuc-type controls allow this method, for the exact purpose of minimizing the accumulative error for long threads. With F0.083333, the error over 70 inches will be:

1 - 12 * 0.083333 = 0.000004 inches * 70 = 0.00028, which is less than three tenths.

Older Fanuc and similar controls could not use F-addresses with six decimal places, but the control provided E-addresses, specifically for threading, which did allow six decimal places. The six decimal place accuracy is not required for threads that have lead divisible into four or fewer decimal places, for example 16 TPI = 1/16 = 0.062500.

The G76 threading cycle itself will be discussed in two other essays looking at basics and details.


2. Trial Cut for Measuring
Precision CNC machining is always a cooperative effort between CNC programmers and CNC machine operators. Programmers can employ certain program features that will enable the machine operators to perform functions that would otherwise be difficult or even impossible. One such method is programming a trial cut for measuring.

There are many factors in machining that influence the final size of a part, such as heat, tool deflection, tool wear, and even lubrication to some extent. For those parts that require very tight tolerances, the negative effect of these factors may result in an out of tolerance size and even a possible scrap. Another problem that is quite common is machining certain hard-to-measure shapes, such as a cone on CNC lathes. By using a simple programming method known as the trial cut, CNC programmers can greatly influence the final size of a part.

Take the already mentioned cone as an example. Without a suitable custom gauge, a cone is a difficult shape to measure at the machine, as there is no flat spot for the micrometer to use. Even if such a special gauge is available, it will be too late to find out that the cone is out of tolerance. The method of using a trial cut is to provide a special flat area (diameter) that can be easily measured, before the final cone is machined, following a few simple rules.

Normally, a cone machined from round stock, such as the 5.0 inch diameter used in the following example, will include G71 roughing cycle and G70 finishing cycle in the part program:



N3 G42 G00 X5.2 Z0.1 T0101 M08 (START POINT FOR CYCLE)

N4 G71 U0.15 R0.025

N5 G71 P6 Q8 U0.07 W0.02 F0.015

N6 G00 X2.8 (CONE START)

N7 G01 X4.6 Z-3.5 F0.008 (CONE END)


N9 G40 G00 X10.0 Z4.0 T0100 (CLEAR POSITION)

N10 M01


N12 G96 S500 M03 (CUTTING SPEED)

N13 G42 G00 X5.2 Z0.1 T0303 M08 (START POINT FOR CYCLE)

N14 G70 P6 Q8

N15 G40 G00 X10.0 Z4.0 T0300 (CLEAR POSITION)

N16 M30


Although correct, the program above does not offer any means to measure the conical part efficiently. By adding several blocks of trial cut in the program and using the finishing tool (T03), a suitable straight cut can be machined first.

When measured, various offsets can be adjusted as necessary — all this is done before any roughing cuts take place:


/ N2 G96 S500 M03 (CUTTING SPEED)

/ N3 G42 G00 X5.2 Z0.1 T0303 M08 (INITIAL POSITION)



/ N6 U0.2 (RETRACT)

/ N7 G40 G00 X10.0 Z4.0 T0300 (CLEAR POSITION)



N10 G96 S300 M03 (CUTTING SPEED)

N11 G42 G00 X5.2 Z0.1 T0101 M08 (START POINT FOR CYCLE)

N12 G71 U0.15 R0.025

N13 G71 P14 Q16 U0.07 W0.02 F0.015

N14 G00 X2.8 (CONE START)

N15 G01 X4.6 Z-3.5 F0.008 (CONE END)


N17 G40 G00 X10.0 Z4.0 T0100 (CLEAR POSITION)

N18 M01


N20 G96 S500 M03

N21 G42 G00 X5.2 Z0.1 T0303 M08 (START POINT FOR CYCLE)

N22 G70 P14 Q16

N23 G40 G00 X10.0 Z4.0 T0300 (CLEAR POSITION)

N24 M30


The first eight blocks are shown with a block skip function, represented by the / symbol. It is more likely that the actual measuring will not be required for each part. This approach to part programming is more efficient because it eliminates a re-cut and greatly enhances accuracy. Setting the block skip mode OFF, CNC operator checks the trial dimension (note the message attached to M00 program stop function), adjusts the suitable offset if necessary, and continues machining with block skip set ON. Note that the trial cut was done with the same tool that will be used for finishing.

When selecting trial cut diameter, make sure the tool removes about the same amount of material that is removed in the finishing cut. In the example, the trial cut diameter is 4.925, resulting in the actual depth of cut (5.0 – 4.925) / 2 = 0.0375 per side, which is almost equivalent to the amount of stock left for finishing:  0.07 / 2 = 0.035 per side. The length of such a cut should be sufficient for micrometer (0.35 in the example).  Also, the machining speed and cutting feed rate should be the same for best results.

The trial cut is a special cut performed on demand only. Although a lathe example has been presented here, trial cuts have many applications in milling operations as well. The main key is to identify the need first; then, provide a suitable program.


3.    Special Purpose G-Codes

Anybody even loosely associated with CNC work is probably familiar with the G-codes, at least with their existence. Preparatory commands, as they are officially called, have a single purpose — they give a specific meaning to other commands in the part program. For example, a programmed command X10.0 can be interpreted as 10 mm, 10 inches, or even as 10 seconds. If this command represents a dimensional program entry, it could be an absolute position or an incremental distance and direction, in rapid or feedrate mode. The exact meaning is defined by one or more G-codes. For example, an incremental feedrate motion of 10 mm will require that G21 (metric mode), G91 (incremental motion), and G01 (linear interpolation) commands are in effect, along with appropriate feedrate.

Many preparatory commands are well known to CNC programmers and operators alike, as they are used in virtually every program, such as those shown in the example. Yet, a list of G-codes for a particular control can be quite long and contain many that are hardly used. Typically, a preparatory command will have two digits following the letter G. Three digit G-codes generally identify the G-code as a particular cycle or function to the CNC machine that uses them; they are not usable anywhere else. Three-digit G-codes are often special macros supplied by a particular machine tool builder. Within the two-digit category of G-codes, there are also several that are fairly common, yet hardly ever used in a part program.

One pair is G22/G23, defined as Stored Stroke Check, ON and OFF respectively. In plain terminology, using these commands allows the programmer to define special three-dimensional zones either as ones that allow a tool from entering or as zones that prohibit a tool from entering. Such definitions may prevent a collision with a certain part of the machine or a fixture.

A relatively recent pair of other G-codes, G25/G26, is used to detect severe spindle fluctuation caused by heat. When G26 Spindle Fluctuation ON is in effect, the control system monitors whether the fluctuation is within specified tolerance range or not. Should the tolerance be exceeded, the control will issue an alarm, warning the user. In order to use this function correctly, a consultation with a service technician is recommended.

Another set of G-codes is a foursome related to the return to machine zero:  G27/G28/G29/G30. Whereas the G28 command and, to a large extent, the G30 command are used to move the specified axis or axes to the machine zero (G28 to the primary and G30 to the secondary machine zero), the G27 and G29 are seldom, if ever, used in a typical part program. Command G27 is a machine zero position check. It is programmed with one or more axes and checks whether the position specified corresponds to machine zero position. If not, the program processing stops and alarm is raised by the control. Its practical application has ceased with the demise of G92 (G50) programming (position register). There is no need for this command in a program that uses work offsets (G54 to G59 or higher). G29 is the opposite of G28/G30. Whereas G28/G30 represents a motion to machine zero via an intermediate point, G29 is a motion from machine zero to a specified position via an intermediate point. This command is virtually useless in typical programs.

Another virtually useless command is G44 (tool length offset negative). It may have its adherents, but there is nothing that the ubiquitous G43 command (tool length offset positive) cannot achieve.

A command that may be somewhat of a puzzle is G31, defined simply as the Skip command. This command is indeed a very special one because it is exclusively used with probing on CNC machines (in-process gauging). Its purpose is to move the probe from a clear position, at a feedrate (just like G01), to a position to be probed. Once the probe detects a contact with the material, the motion stops and the remainder of the motion is not completed; it is skipped, hence the command name.

Finally, there are several G-codes in the G6x range, namely G60 (Single direction positioning), G61 (Exact stop check mode), G62 (Automatic corner override mode), G63 (Tapping mode), and G64 (Normal cutting mode). The default is G64, normal cutting mode.

G61 is the modal version of G09, and can be useful for increased precision when a tool has to move around a sharp corner at a high feedrate, particularly if the corner forms a narrow angle. G62 may improve the surface finish when used to cut sharp inner corners in cutter radius offset mode. Its function is to automatically adjust the cutting feedrate. A tapping mode programmed with G63 disables the feedrate override and the feedhold button, and G64 returns the cutting motions to their original programmed mode. Each mode selected replaces any other mode.

G60 stands separately. Its purpose is to force a unidirectional tool positioning, regardless of which direction the tool comes from. It can be used to compensate for some minor backlash, but it does not remove it. Backlash problems require qualified service technicians.

There may be other G-codes not commonly used, but the ones mentioned in this column should provide some understanding of the more common special purpose G-codes.


4.    Running the First Part — Economically, That Is

Machining a batch of the same parts in a single production run is probably the most common reason for purchasing a CNC machine. The CNC technology offers a great amount of predictability. There is consistency between parts, dimensional accuracy is maintained over many parts, and the program and setup — once verified — can be used over and over in the future.

Yet, even with proven part programs, the production always hits one weak spot when running a new batch. Yes, it is the first part. Every supervisor knows that the first part of the batch is also the most expensive part of the whole batch; its cost of manufacturing proportionally affects all remaining parts. To minimize the cost of making the first part, it is worth looking at several influencing factors and possible solutions.

Comparing Programs

There is a significant difference between running the first part using a new program and a program that had already been verified.

New part programs

CNC programs that have never been used must be carefully inspected. Even programs generated by a CAD/CAM system require certain scrutiny, although on a much smaller scale. Programming errors and oversights can find their way into any program in various forms, some quite hard to detect. For example, the depth and width of a cut may be out of a reasonable range, clearances may be too large or too small, spindle speeds and feed rates may be overrated or underrated, a tool may not be the most suitable one for the job, and so on. These oversights are virtually impossible to see in print or even on the screen — they show only when the first part is run on the CNC machine. In addition to the program itself, the machine setup is always new, regardless of whether the program is new or previously verified.

Verified part programs

These are part programs accepted for production and verified at some earlier date. Keep in mind that only the programs have been verified, not the setups or tools. Setups and tools are subjects to frequent changes; they must be verified every time. Another important consideration is the CNC machine tool being used. Even verified programs have to be checked if they are used on a different machine than the previous time.

Decreasing Costs

Decreasing the cost of the first part — and, therefore, the whole batch — has to be considered at four levels, all interrelated:


Process planners or supervisors have to evaluate many aspects of the production. One of their key considerations is the number of parts produced in a single batch. The more batches per period of time, the more expensive each batch will be, mainly because of the repeated setups. Assuming that more parts produced in a batch will have no negative side effects (for example, on inventory), fewer batches per period of time might provide part of the solution.


CNC programmers can literally do wonders to decrease the cost of the first part through the program. Here are only some ideas. Using consistent tool numbers for commonly used tools saves time during setup, as tool registration and many related offsets will not change. Another very effective programming method is to include one or more trial cuts with the block skip function in the program. These cuts will only be used for the first part testing, but turned off for a full run (except the occasional inspection). Don't forget to provide sufficient comments in the program, so the operator knows the purpose of these special cuts. Another consideration, especially for programs developed manually, is to invest in reliable CNC simulation software. Although no software can simulate every detail of CNC machining, it can be an excellent tool to find errors and areas of improvement.


At the machine, the CNC operator is normally responsible for setting up tools and fixtures, registering tool numbers and various offsets, troubleshooting the program, and monitoring the operation. Speeding up the non-productive time required for setup is the most significant single saving available. Modular fixturing, common tooling, general setup consistency, and the operator's skill all add up to make the transition between setup and operation faster and smoother.


During machining, the CNC operator relies heavily on the program itself. During the first part run, it should not be enough for the CNC operator to look just for errors or monitor the program flow. Operators can and should do much more at the same time. For example, they can think about optimizing the program for better performance. Speeds and feeds are the most common areas to focus on, but many more “little things” also influence the cost of manufacturing (including the first part).

Lowering the cost of the first part should be a team effort. CNC programmers may be the key people in such efforts. However, mutual cooperation of everybody involved will offer many benefits and have a positive effect on the proverbial bottom line.

Quick Find
Use keywords to find the product you are looking for.
Advanced Search
0 items
Share Product
Share on Twitter