# CNC Thread Mill Macro Programming

• MillGuy
MillGuy
TL;DR Summary
I've created a macro program used by a CNC milling machine to cut threads in a hole. It works when I arcs into the minor diameter of the thread at 90 deg. (alpha angle) but not when I decrease the alpha angle.
I've created a macro program used by a CNC milling machine to cut threads in a hole. I like to use macro programs because it allows me to use the same macro for any different size of feature just by changing a few variables. I like to first test out my macro programs using a spread sheet to plug in all of my formulas and check the outputs.

Everything works like it should when my alpha angle ( where the cutter enters the minor diameter) is 90 degrees from where the cutter will be cutting at the full diameter of the thread.

The problem is when I decrease my alpha angle, 45 deg. for example, the radius of the tangential arc is incorrect.

I don't have CAD software, and I don't want to be bothering the Engineers and Mech Tech's at my shop every time I want to visualize it, so I just use a protractor and a drafting compass to draw a bunch of circles

Most of the work we do is in Imperial measurements so our machines are in inches (lame, I know)

My Machine controller doesn't have arcsin or arccos functions just arctan, so I have to go the long way around to calculate angles

Example:

[VN=1.5] (THREAD NOMINAL DIA.)
[VM=1.375] (THREAD MINOR DIA.)
[VP=.125] (PITCH)
[VD=1.000] (TOOL DIA.)
[VC=.02] (MINOR DIA. CLEARANCE AMOUNT)
[VA=90.] (ENTRY ANGLE/ALFA ANGLE)

[VH=[[[VM*VM]/[360./VA]]+[[VN*VN]/[360./VA]]]/VN] (RADIUS OF TANGENTIAL ARC)
[VB=VA+ATAN[[SQRT[[[VN/2]*[VN/2]]-[[[VN/2]-VC]*[[VN/2]-VC]]]]/[[VN/2]-VC]]] (BETA ANGLE)

Below is the example I'm basing my macro on

Last edited by a moderator:
DeBangis21
MillGuy said:
TL;DR Summary: I've created a macro program used by a CNC milling machine to cut threads in a hole. It works when I arcs into the minor diameter of the thread at 90 deg. (alpha angle) but not when I decrease the alpha angle.

[VH=[[[VM*VM]/[360./VA]]+[[VN*VN]/[360./VA]]]/VN] (RADIUS OF TANGENTIAL ARC)
The image you posted of the sample calculation is unreadable, the resolution is too low (PF typically decreases the resolution of images before storing them).
Can you supply a link to the original? If not, can you break the scanned image into 4 pieces so each piece ends up with higher resolution... and hopefully readable.

I have no experience with CNC CAD software but your formula for VH looks somewhat suspicious for dividing by VN. Is this what is really needed?

Cheers,
Tom

Tom.G said:
Can you supply a link to the original? If not, can you break the scanned image into 4 pieces so each piece ends up with higher resolution... and hopefully readable.

https://www.kennametal.com/us/en/re...re/tooling-systems-metalworking-catalogs.html

The example is from the Kennametal 2018 Vol. 2 Rotating Tools Master Catalog, section W, page 53. You can get them in metric and inch versions, I have the inch version PDF downloaded.

In their example it uses a toolpath that is supposed to start at 90 deg. from the x-axis center line where the tool will be cutting at the full nominal diameter (VN) of the thread. I've programmed my macro to start entering the hole diameter/thread minor diameter (VM) at 90 deg.

In their example the radius of the tangential arc stays the same, even if I change the alpha angle to 45 deg. In my macro, the radius of the tangential arc (VH, should relabel it as VR) is in relation to the alfa angle. Like I stated before, it seems to work when my alpha angle is set at 90 deg., but when I set it to 45 deg. the radius seems to be too small, smaller than the radius of the cutter its self.

I'm able to ad logic like "IF" statements, so if tangential radius is too small it can adjust the tool path accordingly, but at 45 deg. alpha angle with the cutter diameter I'm using, it should still work. I think must have an incorrect ratio in my tangential radius calculation.

Their example also uses cutter compensation (G41=climb milling, G42=conventional milling, G40=cutter comp cancel) which the machine controller uses to compensate for the diameter or radius, depending on the controller, of the cutter being used (D60=tool # 60 diameter or radius). My macro is supposed to be compensating for the tool diameter within it tool paths.

Below is the full macro I have programmed with the updated labeling of the radius of the tangential arc from VH to VR. I'm not sure how relevant most of the macro will be, but it might help with trouble shooting the problem. I've added extra spaces for ease of reading.

[VZ=0] (Z-AXIS LOCATION OF HOLE SURFACE)
[VN=1.5] (THREAD NOMINAL DIA.)
[VM=1.375] (THREAD MINOR DIA.)
[VP=.125] (PITCH)
[VL=2.000] (LENGTH OF THREAD)
[VD=1.000] (TOOL DIA.)
[VG=.003] (FEED PER TOOTH)
[VT=3] (# OF TEETH)
[VW=.21] (TIP OF TOOL TO THREAD ROOT DISTANCE)
[VC=.02] (MINOR DIA. CLEARANCE AMOUNT)
[VA=90.] (ENTRY ANGLE/ALFA ANGLE)

( *** DO NOT ALTER *** )
[VI=[V1403-V[2500+[V1102]]]] (CURRENT Z AXIS COORDINATE, "I" POINT)
[VR=[[[VM*VM]/[360./VA]]+[[VN*VN]/[360./VA]]]/VN] (RADIUS OF TANGENTIAL ARC)
[VB=VA+ATAN[[SQRT[[[VN/2]*[VN/2]]-[[[VN/2]-VC]*[[VN/2]-VC]]]]/[[VN/2]-VC]]] (BETA ANGLE)
[VK=VP*[VB/360.]] (Z-AXIS MOVEMENT DURING ENTRY APPROACH)
[VE=VG*VT*V1111] (FEED RATE AT CUTTING EDGE)
[VF=VE*[[VM-VD]/VM]] (FEED RATE AT TOOL CENTRE LINE)

G90 G0 Z[VZ] (RAPID TO START OF HOLE)

G91 G1 Z[-VL-VW-VK] F[VE] (FEED INTO HOLE)

G91 G1 X[COS[360-VB]*[[[VM-VD]/2]-VC]] Y[SIN[360-VB]*[[[VM-VD]/2]-VC]] F[VE] (FEED TO CUTTING START POINT)

G91 G3 X[[COS[0]*[[VN-VD]/2]]-[COS[360-VB]*[[[VM-VD]/2]-VC]]] Y[[SIN[0]*[[VN-VD]/2]]-[SIN[360-VB]*[[[VM-VD]/2]-VC]]] Z[VK] R[VR-[VD/2]] F[VF] (ARC INTO CUTTING RADIUS)

G91 G3 I-[COS[0]*[[VN-VD]/2]] J-[SIN[0]*[[VN-VD]/2]] K[VP] (CUT THREAD FOR 1 REVOLUTION)

G91 G3 X[[COS[VB]*[[[VM-VD]/2]-VC]]-[COS[0]*[[VN-VD]/2]]] Y[[SIN[VB]*[[[VM-VD]/2]-VC]]-[SIN[0]*[[VN-VD]/2]]] Z[VK] R[VR-[VD/2]] (ARC OUT OF CUTTING RADIUS)

G91 G1 X-[COS[VB]*[[[VM-VD]/2]-VC]] Y-[SIN[VB]*[[[VM-VD]/2]-VC]] F[VE] (FEED BACK TO CENTRE OF HOLE)

G90 G0 Z[VI]

I'm not sure if you are familiar with G-code for programming CNC machine tools but here are some additional notes:

G90 is absolute location.
G91 is incremental location.
G0 is rapid positioning.
G1 is linear interpolation at a programmed speed.
G3 is counter clock wise circular interpolation at a programmed speed.
X/I_ Y/J_ Z/K_ are their respective Axis

Any help would be appreciated. I'm the only one who does macro programming at my shop.

From your catalog, the equation is:
$$\beta = 90° + asin\left(\frac{R_o - R_e}{R_e}\right)$$
Using ##atan## instead of ##asin## would mean:
$$\tan\theta = \frac{\sin\theta}{\cos\theta}= \frac{\sin\theta}{\sqrt{1 - \sin^2\theta}} = \frac{\left(\frac{R_o - R_e}{R_e}\right)}{\sqrt{1 - \left(\frac{R_o - R_e}{R_e}\right)^2}}= \frac{R_o - R_e}{\sqrt{R_e^2 - \left(R_o - R_e\right)^2}}$$
Thus:
$$\beta = 90° + atan\left(\frac{R_o - R_e}{\sqrt{R_e^2 - \left(R_o - R_e\right)^2}}\right)$$
And, if I translated correctly, your equation for ##VB## is:
$$VB=VA+atan\left( \frac{ \sqrt{\left(\frac{VN}{2}\right)^2-\left(\frac{VN}{2}-VC\right)^2} } { \frac{VN}{2}-VC } \right)$$
which looks terribly wrong no matter what ##R_o## or ##R_e## are supposed to be with respect to ##VN## or ##VC##. But I'm expecting you are supposed to have something like:
$$VB=VA+atan\left( \frac { \frac{VN}{2}-VC } { \sqrt{\left(VC\right)^2-\left(\frac{VN}{2}-VC\right)^2} } \right)$$
I haven't tried to figure out much more about your posts as they are too tedious to read.

Tom.G
That is a MUCH nicer way to write formulas. I need to learn how to post like that. The reason I write them the way I do is because that's how both Excel sheets and the machine controller use them.

The equations are written in ##\LaTeX##: Learn LaTeX for Math Equations

You can right-click on any equation and choose "Show Math As -> TeX Commands" to see how they were written.

MillGuy
You'll have to forgive me for taking a while to respond, it's fairly busy at work at the moment and I only get to work on this on my coffee breaks. Plus it's Friday

Tom.G
So here is where I am so far. The Beta angle is not that important, what I really need is the Radius of the Tangential Arc (Re)

I hope what I have so far makes sense, and that I'm going in the right direction.

The nominal dia. is N, and the minor dia. is M

Solve for Rn
$$\alpha = \arccos(1 - 2(R_n / N))$$

Solve for Wn
$$R_n = \frac{N - \sqrt{N^2 - {W_n}^2}}2$$

Solve for Rm
$$\alpha = \arccos(1 - 2(R_m / M))$$

Solve for Wm
$$R_m = \frac{M - \sqrt{M^2 - {W_m}^2}}2$$

Radius of Tangential Arc (Re)
$$R_e = \frac{({W_m}/2)^2 + ({W_n}/2)^2} {W_n}$$

I've tried isolating the R and W variables but solving for R and W is beyond my comprehension. It's been a couple of decades since I have last done anything of this complexity in school.

Last edited:
Wow! Totally disregard my last post. Way over complicated and pointless. W is just the chordal length, I can't believe I didn't realize this sooner.

Tom.G
Im still struggling to find the correct calculation for the Radius of the Tangential Arc (Re)

According to the Kennametal Catalog:
$$R_e=\frac{(\frac{M}{2})^2+(\frac{N}{2})^2}{N}$$
Which works if the alpha angle is 90 degrees, but stays constant even if the alpha angle is reduced to 45 degrees.

When I tried it as a ratio of the alpha angle divided by 360, it still works when the alpha angle is 90 degrees.
When I change the alpha angle to 45 degrees, the Tangential Radius ends up being less than my tool radius which is incorrect.
$$R_e = \frac{(({M}^2*({\frac{\alpha}{360}})) + (({N}^2*({\frac{\alpha}{360}}))} {N}$$

When I tried it as a ratio between the Minor Diameter and and Nominal Diameter chordal lengths, it still works when the alpha angle is 90 degrees. When I change the alpha angle to 45 degrees, the Tangential Radius still ends up being less than my tool radius which is still incorrect.
$$R_e = \frac{(\frac{W_m}{2})^2 + (\frac{W_n}{2})^2} {W_n}$$
$$W = \text{Diameter} * \sin\alpha$$
$$R_e = \frac{(\frac{M * \sin\alpha}{2})^2 + (\frac{N * \sin\alpha}{2})^2} {N * \sin\alpha}$$

I'm all out of ideas.
I've attached another drawing to help with my explanation.
The green arc is the Radius of the Tangential Arc with an alpha angle of 90 degrees.
The orange circle is the diameter of the cutting tool.
As you can see, an alpha angle of 45 degrees should have a Tangential Radius larger than the radius of the cutting tool.

Last edited:
@MillGuy
You give an unreadable picture in post #1.
I get too many wrong hits when I search for that.
Please provide a link for the download of that specific document.

Baluncore said:
@MillGuy
You give an unreadable picture in post #1.
I get too many wrong hits when I search for that.
Please provide a link for the download of that specific document.
Already answered in post #3

jack action said:
Already answered in post #3
That is a page reference, not a download link. I see more than 42 documents in that collection. I seem to get a different choice of documents depending on how I approach the site.
What is the specific document link to download the same original.pdf ?

Baluncore said:
What is the specific document link to download the same original.pdf ?
That is the link based on how that webpage works.
Scroll down a little bit until you see "Master Catalog 2018 Vol. 2 Rotating Tools". It will be near the top of the page. There should be a drop-down menu to select "Inch" or "Metric".

@Baluncore
You will have to view it in a regular web browser. I just tried it on my phone and it doesn't display properly.

Thanks, I have it now.

MillGuy

### Similar threads

• New Member Introductions
Replies
4
Views
208
• Mechanical Engineering
Replies
9
Views
2K
• Mechanical Engineering
Replies
1
Views
5K
• Mechanical Engineering
Replies
1
Views
19K
• Precalculus Mathematics Homework Help
Replies
1
Views
715
• DIY Projects
Replies
5
Views
2K
• Mechanical Engineering
Replies
20
Views
7K
• Classical Physics
Replies
16
Views
2K
• STEM Academic Advising
Replies
4
Views
2K
• Other Physics Topics
Replies
7
Views
3K