![]() | |
| Home Page | Mark Forums Read | Today's Posts | My Replies | Classifieds | Reviews | Photo Gallery | Web Links | Share Files | Advertise With Us | Ad List |
| |||||||
| G-Code Programing Discuss G-code programing and problems here! |
| This forum is sponsored by: |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
| |||
| |||
Can we call subprograms (using M98) from a macro and vice-versa (using G65/66)? If the answer is "yes", can we have a total of 8 levels of mixed nesting (4 for macro and 4 for subprograms)? If the answer to the previous question is "yes", I believe, all the nested macros will have different "levels" of the local variables (#1 to #33), but the local variables of the nested subprograms will have the level of the calling program (which can be a macro or another subprogram). Am I right? Thanks. |
|
#2
| |||
| |||
| 070325-2009 EST USA sinha_nsit: On a HAAS machine, similar to Fanuc, a G65 subroutine call allows parameter passing on the G65 line thru alphabetic addresses on the G65 line that map to local addresses in the called routine. The local addresses in a G65 subroutine (which is a separate O-numbered program) are independent of any other local addresses in any other G65 subrountine. My guess is that these local variables are stored on the computer stack. This means they are volatile, and may be unique. Note: there is no way to pass values back to the calling program level other than thru common variables. Also, the local variables of a given level are not destroyed by calling a subprogram. But when you go up a level those on the level you go up from are destroyed. Other subroutines than G65 do not allow parameter passing thru addresses on the calling line. Thus, common variables are used for parameter passing and these must be preset before calling the subroutine. G65 subroutines at each level have a new set of local variables created. I suspect that since M98 is an external subroutine call that its local variables are different than those in the calling program, but I have never tested this. My guess is that a local subroutine call, M97, may share the local variables of the calling program. I might think to test this later or someone else can maybe check these. You run tests like this by using a common variable to store the value of a local variable in the common variable for inspection later, or use DPRNT to output your test values. . |
|
#3
| |||
| |||
| Thanks for your reply. You have understood what confusion I have. Incidently, Fanuc 0i series uses M98 for internal subprograms and M198 for the external ones. In case you do get some additional information regarding combined nesting of subprograms and macros (I use the term subprogram for a program called by M98, and macro for a program called by G65), and how the local variables are treated by them, please let me know. We may discuss it with an example to pinpoint the confusion: The main program 1000 calls a subprogram 1001 by M98, 1001 calls a macro 1002 by G65, 1002 calls a subprogram 1003 by M98, 1003 calls a macro 1004 by G65, 1004 calls a subprogram 1005 by M98, 1005 calls a macro 1006 by G65, 1006 calls a subprogram 1007 by M98 and 1007 calls a macro 1008 by G65. Here we have used 8 level nesting - 4 for subprograms and 4 for macros. My question is that can we have a combined nesting of 8 levels in this manner? Actually, 4 levels of nesting each for subprograms and macros are allowed. Assuming such a nesting is permissible with Fanuc 0i series, let us assume that a local variable #1 is being used in the main program as well as in all the nested subprograms/macros. I believe (please correct me if I am wrong!), a subprogram called by M98 does not change the level of the local variables of the calling program, whereas a macro called by G65 does change the level. This means that #1 will have different meanings in the main program 1000 and the 4 macros (1002, 1004, 1006 and 1008), but #1 of the main program 1000 and that of subprogram 1001 will have the same meaning (i.e., they refer to the same memory location). Similarly, #1 of 1002 and that of 1003 will have the same meaning, and so on. Am I correct? I do have the original 0i series TC and MB manuals, but these things are not clear. Kindly help! Thanks. |
|
#4
| |||
| |||
| 070326-0543 EST USA sinha_nsit: See page 83 under MACROS in the HAAS on-line mill manual. This is 96-8000.pdf . A statement there says "Local Variables ..G65...the local variables are saved and a new set is available for use... ...Calling a subroutine via an M97 or M98 does not nest the local variables. .... " In this HAAS discussion they provide a very clear explanation. Do the following to verify what happens in your system: O1000 #1 = 101 #500 = #1 M98 P1001 #501 = #1 #506 = #2 M30 N 1001 #502 = #1 G65 P1002 A5.0 #504 = #1 #505 = #2 M99 O1002 #503 = #1 #1 = 1002 #503 = #1 #2 = 11002 M99 . |
|
#5
| |||
| |||
| I have verified on 0i TC. Yes, a maximum of 8 level of mixed nesting is allowed, with max 4 macros and max 4 subprograms. But, you cannot have, say, 5 macros or 5 subprograms. Nested subprograms always use the local variables of the calling program (which can be the main program, or a macro or another subprogram). So, even in a mixed nesting of 8 levels, there will only be 4 levels of local variables (plus one level for the main program). |
| Sponsored Links |
|
#6
| |||
| |||
| Wow sinha nsit you have been busy on this for quite some time. Anyhow I am glad that you have becasue this raises a question of mine that I have not bothered to try and see if it works or not. It has just been more of a personal wanting to know not that I have needed to use it. You are mixing the macro calls and sub calls to be able to nest up to 8 levels. I am going to use an example. When calling G65P8000A10 program 8000 is called and #1=10. Now in the 8000 program we do another macro call say G65P8001A50 now program 8001 is called and #1=50 now when returning from 8001 to 8000 via M99 #1 is restored to 10. My question is does this hold true when using a M98 call then returning to the previous macro? Or do you not rerun your previous macro? I do this quite often with macro calls but I have never dropped a M98 in the program to see if the values restore. Stevo |
|
#7
| |||
| |||
| No. A subprogram is only an "extended part" of the calling program, and M98/M99 just do copy-and-paste operation. So, a subprogram uses the local variables of the calling program with the same meaning, ie, using the same memory location. So, if a subprogram assigns to a new value to a local variable of the calling program, the original values defined in the calling program is lost for ever. After M99, the new values, as defined in the subprogram, become available in the calling program. Incidently, you can call a subprogram with G65 also, ie, without passing values for the local variables: M98 P1000 or G65 P1000 These two are NOT equivalent. O1000, called by M98, will use the local variables of the calling program. But, O1000 called by G65, will use a new set of local variables which will all be NULL, initially. |
|
#8
| |||
| |||
| No. A subprogram is only an "extended part" of the calling program, and M98/M99 just do copy-and-paste operation. So, a subprogram uses the local variables of the calling program with the same meaning, ie, using the same memory location. So, if a subprogram assigns to a new value to a local variable of the calling program, the original values defined in the calling program is lost for ever. After M99, the new values, as defined in the subprogram, become available in the calling program. Incidently, you can call a subprogram with G65 also, ie, without passing values for the local variables: M98 P1000 or G65 P1000 These two are NOT equivalent. O1000, called by M98, will use the local variables of the calling program. But, O1000 called by G65, will use a new set of local variables which will all be NULL, initially. |
|
#9
| |||
| |||
| That makes sense. I guess I have written programs in that manner I just never thought about using the variables coming out of the subprogram M98 as I normally do when nesting the G65 macros. The more I read my question the more I realize it was a pretty stupid question because I knew the answer to it. What I was asking is really no different than setting #1=10 in a main program then calling a sub via M98. #1 can be used as is never changed either by the sub call or the return call. Brain fart.Stevo |
|
#10
| |||
| |||
| No question is "stupid". Such a view stops the learning process. Nobody knows everything. In fact, I also have asked several questions on this forum. Many of these might be "stupid questions", but I learnt a lot in the process. Fortunately, many people (including you) on this forum are knowledgeable and helpful. It is great to see that so many people are spending hours to help those who are unknown to them. |
| Sponsored Links |
|
#11
| |||
| |||
| I agree there is no stupid question. I was just referring my stupidity to the fact that I asked a question that I knew the answer to but didn’t take the time to really look at what I was asking. It is nice to see so many people help each other. I love to share the knowledge. I believe in the pay it forward method. I have had a lot of people message me saying thanks I don’t know how I will every repay you. My response is always help the next person up when they stumble or need advice. Stevo |
|
#12
| |||
| |||
| Can anyone tell me. How G160 works? My machine is Tornos Bechler Enc 162 and in every program there is G160 H9810. I ref. program manual in which it is stated that it is Tornos- Bechler sub routine used to calculate no. of pieces. Can we read this sub routine 9810 on screen? As it is not available in program library. Below is the example % :0070 G10P10001X0Z-7.2R0Q9 G10P10002X0Z-11.2R0Q9 G10P10022X0Z-11.2R0Q9 G10P10004X0Z-9.9R0Q9 G161A13.2B0.06C0404F-34.38H2.5J2K1M15Q0 M8 G4X2 M4S4000 G160H9810 G160H9901 N5 G0Z0.2 X17T5000 M90 G92Z0.4 T0101 M4S5000 G0X14Z0 G1X-0.6F0.05 X4.03 N40Z0 N41X4.43Z-0.2F0.03 Z-3.6 N50G0X13.1Z-3.4 Z-4.38 N51G1X12.1Z-3.88F0.03 X4.44F0.05 X12.5Z-3.7F0.2 G0X17T0 T1300 T0202 M4S4000 M24 G0X13.2Z-4.98 G1X12.2Z-5.48F0.01 X5.125F0.03 Z-12.0F0.04 G1Z-12.23F0.01 T3222 G3X4.725Z-12.43R0.2F0.004 G1X4.71F0.01 X4.75Z-33.7F0.05 Z-33.88F0.01 G3X3.91Z-34.28R0.4F0.005 G1X13F0.2 G0X17T0 T0404 M4S4000 G0X13.2Z-34.18 M28 G1X5F0.08 X-0.2F0.04 M25 X-1.6F0.06 M29 M1 T1100 G160H9902 G65H80P5 M2 % |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Macro B Question | Bluetech | Fanuc | 7 | 03-10-2009 12:58 AM |
| custom Macro B options | gup | Fanuc | 2 | 03-09-2009 11:41 AM |
| Custom Macro Screens, Series 0MC | RLMTS | Fanuc | 0 | 01-03-2007 05:54 AM |
| Custom Macro B On A 18t. | JIMMYZ | Fanuc | 3 | 10-18-2006 10:08 PM |
| custom macro | The Metal | Daewoo/Doosan | 2 | 09-28-2006 07:26 AM |