587,402 active members*
3,104 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 29
  1. #1
    Join Date
    Feb 2006
    Posts
    1792

    custom macro question

    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. #2
    Join Date
    Mar 2005
    Posts
    1498
    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. #3
    Join Date
    Feb 2006
    Posts
    1792
    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. #4
    Join Date
    Mar 2005
    Posts
    1498
    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. #5
    Join Date
    Feb 2006
    Posts
    1792
    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).

  6. #6
    Join Date
    Jun 2008
    Posts
    1511
    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. #7
    Join Date
    Feb 2006
    Posts
    1792
    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. #8
    Join Date
    Feb 2006
    Posts
    1792
    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. #9
    Join Date
    Jun 2008
    Posts
    1511
    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.

    :withstupi Brain fart.

    Stevo

  10. #10
    Join Date
    Feb 2006
    Posts
    1792
    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.

  11. #11
    Join Date
    Jun 2008
    Posts
    1511
    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. #12
    Join Date
    Feb 2009
    Posts
    52
    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
    %

  13. #13
    Join Date
    Jun 2008
    Posts
    1511
    What series control are you using?

    Stevo

  14. #14
    Join Date
    Feb 2009
    Posts
    52
    Fanuc O-T

  15. #15
    Join Date
    Feb 2009
    Posts
    52
    Quote Originally Posted by stevo1 View Post
    What series control are you using?

    Stevo
    Fanuc O-T

  16. #16
    Join Date
    Jun 2008
    Posts
    1511
    Chetan it appears that your machine is using G160 as a macro call. Look at parameters 220-229 to see if anyone of these is set to 160. These parameters are for a custom macro call using a G-code. If anyone of these are set to 160 these are the programs they will call:

    Parameter 220 calls program 9010
    221 calls 9011

    229 calls 9019

    To allowing Edit of programs 9000-9999 parameter 10.4

    Your program appears to be using MacroA for this counter. I have not used it in eons. Any macro A guys please feel free to step in and help out. I am a bit thrown off by the G161 call as this appears to be using macroB…You need to find out what programs are being called via G160 and look at those programs and post them.

    Stevo

  17. #17
    Join Date
    Feb 2009
    Posts
    52
    Stevo

    Thanks for reply,
    actually i m new to cnc. i have back up of parameters below is the list of parameter which you have stated.
    N0221 P 00000000
    N0222 P 00000000
    N0223 P 00000000
    N0224 P 00000000
    N0225 P 00000000
    N0226 P 00000000
    N0227 P 00000000
    N0228 P 00000000
    N0229 P 00000000

    You said parameter 10.4. Doest it mean 4th bit of paramter no. 010? If not then where is this 10.4? what value should i input?
    And also can you tell me what are this diagnostic no.?

    Thanks

  18. #18
    Join Date
    Jun 2008
    Posts
    1511
    Chetan,

    Yes 10.4 is parameter 10 bit 4. Bits run from right to left (76543210). So to allow editing of the 9000 programs you should have to set #4.

    According to the Ot manual to call custom macros with a G-code it is parameters 220-229. It looks like what you are showing for these parameters they are bits. Normally for example if you wanted to call program 9010 with a G160 you would have to set parameter 220 to 160. If that is not possible then I will have to do some more searching why you can’t.

    Stevo

  19. #19
    Join Date
    Feb 2009
    Posts
    52
    In our machine after pressing menu offset button, we are not able to display w.shift. I mean we can see "Wshift" but after pressing soft key it dosnt responds. Is there any parameter to display this. Control Is Fanuc OT.

    And also i want to know that how to use wear offsets. suppose after 100 jobs i want tool no 1 to adjust by 0.05mm in X axis, then how to set it for.

    Thanks
    Thanks

  20. #20
    Join Date
    Jun 2008
    Posts
    1511
    To adjust you’re Wear of the tool you should have to press the Offset key and you should see Wear Offset. Once you select this then you select tool 1 and put in -.05 in the X.

    I don’t show the workshift as being an option so I am not quite sure why you can’t display the workshift. How do you currently set up the machine? Do you have Workoffsets G54-G59?

    I have attached a few documents of the Offset screen and setting the tool data.

    Stevo
    Attached Files Attached Files

Page 1 of 2 12

Similar Threads

  1. Macro B Question
    By Bluetech in forum Fanuc
    Replies: 7
    Last Post: 03-10-2009, 06:58 AM
  2. custom Macro B options
    By gup in forum Fanuc
    Replies: 2
    Last Post: 03-09-2009, 05:41 PM
  3. Custom Macro Screens, Series 0MC
    By RLMTS in forum Fanuc
    Replies: 0
    Last Post: 01-03-2007, 12:54 PM
  4. Custom Macro B On A 18t.
    By JIMMYZ in forum Fanuc
    Replies: 3
    Last Post: 10-19-2006, 04:08 AM
  5. custom macro
    By The Metal in forum Daewoo/Doosan
    Replies: 2
    Last Post: 09-28-2006, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •