What's new
What's new

Calling subprogram from inside macro

GiroDyno

Hot Rolled
Joined
Apr 19, 2021
Location
PNW
I have a 'master' program that begins with a macro 'subprogram' that does a bunch of probing to test for parts and set offsets based on user inputs A, B and C. There are also some 'subroutines' (What I'm calling a program that is inside the master program, as opposed to a subprogram which would be saved independently on the controller)
Based on the macro results there is some logic to decide which of the subroutines I need to run; for example I may only have 1 part loaded and it needs the CW slots, or I may have 2 parts and the first needs CCW and the second needs CW...
Is there a way to call up those subroutines (located in the master) from my macro subprogram (independent from the master)?
What I can do right now is save some variables from my O5678 macro and use those to do logic inside my O1234 master, but I like the idea of making updates to the O5678 macro program and it automatically applies to all the different masters. We may have 20 different part #s running in a day (each with its own master and subroutines), which means I may have to make the same edit 20 different times... If I can call the subroutine from inside the macro then I only change it once and all 20 run the updated cycle.

Hope that makes sense, its got my head spinning this afternoon!

Example code "layout" shown here:

O1234 (MASTER PROGRAM)
G65 P5678 A1 B2 C3 (PROBING MACRO)
...
M97 P501
...
M97P502
...
M30

N501 (CLOCKWISE SLOTS)
...
M99
N501 (COUNTERCLOCKWISE SLOTS)
...
M99

O5678 (PROBING MACRO)
...
(PROBING)
...
(LOGIC)
...
I want to run P501 (CW SLOTS) from O1234 here
...
M30
 
"I want to run P501 (CW SLOTS) from O1234 here"

This is possible.

Note that if a macro calls a subprogram, the subprogram will use the local variables of the macro.
 
Last edited:
Hello GiroDyno,
You should specify the Control you're using to allow the Forum members a better chance of giving you good information. However, as you're calling the Subprogram with M97, I suspect that the machine and control is a HAAS.

The Subprogram you want to call is a Local Subprogram of O1234, therefore, you won't be able to call the Subprogram that is Local to Program O1234 and specified by Sequence Number N501, directly. The best you will be able to do without a lot more thought, is call Program O1234 as a Subprogram and in doing so, Local Subprograms N501 and N502 will be executed.

Although M99 would normally send control; back to the next Block in the calling program, because N501 and N502 are being called as Local Subprograms in O1234, I suspect that control will go to the next Block after where N501 and N502 in O1234 were called when the M99 in each of the Local Subprograms is executed. This is what would happen with Nested External Subprograms called with M98.

If M99 after each of the Local Subprograms did hand control back to the Block following the call of N501 and N502, then your next problem will be the M30 in Program O1234. When this is read, it would be considered the End Of Program for O1234 and the Control would Reset to the top of O1234 and not the program that called O1234.

You could accomplish what you want to do, but it would require a rewrite of O1234 with the call of Local Subprograms subject to Conditional Statements.

If this were a Fanuc, or Mitsubishi Control, it would be very simple to do what you're wanting to do. These controls have the facility to call an External Subprogram, O1234 in this case, and start from within that program from a particular Sequence Number. For example, to call the Local Subprogram N501 of Program O1234, the syntax would be as follows:

O5555
-------------
-------------
-------------
-------------
M98 P1234 Q501 (Call Program O1234 and start at N105 within O1234)
-------------
-------------
-------------
-------------
M30

In the above example, Program O1234 would be called as a Subprogram by Program O5555 and start at Sequence Number N501 within Program O1234. When M99 is executed at the end of the Local Subprogram N501, control would revert back to the next Block after where Program O1234 was called as a Subprogram from within Program O5555.

However, if your machine is a HAAS, as far as I know, it doesn't have the facility to start at a particular Sequence Number within a Subprogram that's been called.

Regards,

Bill
 
Last edited:
Hi Bill, you are correct it is a 2008(?) Haas with the "classic" controller, but it is the in-between version that has the weird 'racecar' display.
Sorry I left out such an important bit of info, I did say my head was spinning!

I don't see anything like that start sub from sequence number in the manuals. Sounds like I can't get it to run exactly the way I want...bummer...
At least I can handle most of the decision making in the macro program and write a few variables and use those in some conditional statements in my master program to get where I need to go. I'm just going to cross my fingers I get it dialed the first time around and won't have to go back and make any updates to those conditional statements in every program six weeks from now.
This will still be a huge advantage over the current system of hand editing every batch of parts that comes through.
 








 
Back
Top