The Macro Loop vs. Sub Program
What the hell is a macro loop? I can hear some of you say that. Most of you who know G Code know what a sub program is. Some like the macro loop, some like the sub program. I think both have their place. The sub program is good for repeating a cycle of something over and over. The macro loop does the same thing, however you can use math to change a value within the loop, such as threading, or even peck drilling. Here is the difference
The Sub Program
The sub program, depending on your machine, looks like this. This is a basic hex mill. It mills a flat, indexes 60 degrees, then goes again until it does all six (L6)=Loop 6 times
Your tool gets called, you have all your prep commands, (as I like to call them), and then you have that "M98P1111L6" Essentially it is calling the subroutine 6 times. The subroutine is doing a move once, then indexing incrementally 60 degrees. The drawback is that the subroutine, depending on control, is either called at the end of the program or in a different file altogether. If its in a different file, you need to be sure that you load the subroutine file as well.
The macro loop
I like macro loops because they are efficient and you can see everything right there in one spot. Here is a macro loop for the same process:
Look intimidating? To some of you sure, to others not so much. Here is the breakdown
#100 is a variable that gets assigned an initial value, in this case 0
The WHILE statement is this: While the value of the variable #100 is Less Than or Equal to 330, DO the program labled 1. DO1 does NOT mean do it one time. 1 is the macro program number. That is why when it is done it says END1. So now the computer does math. It goes to the next line and says, "I see a #100, what is the value? ZERO? Is ZERO less than or equal to 300? YUP! Im going to continue. So it continues on. When it gets to G0C#100, the C-axis indexes to the value of #100, in this case 0, and it does its thing.
NOW, at the end it does a little math. It takes the CURRENT value of #100, adds 60 to it, and makes this the NEW value of #100, and it loops up back to the WHILE statement. So now, the value of #100 is 60. So now the computer does math. It goes to the next line and says, "I see a #100, what is the value? 60? Is 60 less than or equal to 300? YUP! Im going to continue. So it continues on. When it gets to G0C#100, the C-axis indexes to the value of #100, in this case 60, and it does its thing. It keeps going:
120,180,240,300
It does this until it reaches 360. Since 360 is MORE than 300, it skips over the loop to the END1 line.
This is a basic macro program and its pretty simple. Once you get your brain to wrap around this, the options are limitless. You know all those canned cycles you have in the machine? G81, G83, G87, G76? Those are all hidden macro loops
At first I didn't like the macro loop, but once i got used to it, i use it regularly. Its all right there. If I want to change any values of the block of code, I don't need to go anywhere else. its all right there. Its clean and efficient.
Macro statements can get pretty complex, so when you start getting into multiple variables, doing complex math statements, be careful. Write them out long hand to see if they will work, then assign them different values. Go slow. As always, if you need help, feel free to reach out to me
Thread Macros are unnecessary and confusing to teach to most people learning, a G76 or G92 cycle is the best way to teach. When it comes to bone screws you would thread whirl the profile in G32 or using your H values making sure your Z value comes out to the pitch on the part with number of rotations to obtain your thread pitch and z value. Thread Rolling is done in G32 just like tapping with a floating holder is G32 and Rigid Tapping with G84. Macros for me are when parts are from the same family and have different lengths or when you want to run a turn tool in T2 and T3 and a Threader In T5 And T6 to allow it to get more tool life hence more production when running lights out.
I use G33 (Tornos) macro loop on all of my threading if I am single pointing. I use G33 because you can alter the profile of the thread form. I do a lot of bone screw prototypes with crazy profiles, so it works well.
I forgot, great post Marc. Thanks.
Derek, I find that the Fanuc Control is more prevalent than most using Macro B system
Marc in your experience is one G-code system (A, B or C) much more prevalent. I.e G33 vs G32 for threading G92 vs G50 for max spindle speed? I worked on two machines side by side. One's R value in a canned cycle was incremental, the other absolute position. Also, +1 for educating on Macro-B. I use cycles exactly like this every day and I've come to learn that of the few skilled machinists in this area, fewer still can functionally use Macro-b For anyone looking to expand their knowledge Peter Smid's "Fanuc custom Macro-b" is a great read!