585,741 active members*
5,223 visitors online*
Register for free
Login
Results 1 to 20 of 20
  1. #1
    Join Date
    Jan 2008
    Posts
    74

    programming a loop

    Hello all,
    I am running a Takisawa EX-110 lathe with a Fanuc 21i-T control. This is my program:

    :0100
    M98P0101
    M98P0102
    M98P0103
    M30

    What I want to do is loop through this program a specific number of times, (say 35 times) and then stop. I know you can use macros to create loops and logic and such but I have never used them. Could somebody help me with this problem?

    Thanks a lot!

  2. #2
    Join Date
    Feb 2008
    Posts
    586
    Quote Originally Posted by crazycnc View Post
    Hello all,
    I am running a Takisawa EX-110 lathe with a Fanuc 21i-T control. This is my program:

    :0100
    M98P0101
    M98P0102
    M98P0103
    M30

    What I want to do is loop through this program a specific number of times, (say 35 times) and then stop. I know you can use macros to create loops and logic and such but I have never used them. Could somebody help me with this problem?

    Thanks a lot!
    So many ways to skin this cat!

    You could write a short program:

    :O1000
    M98P0100L#500
    M30

    You'd have to end your original program with an M99 instead of an M30.
    Then, enter the number of repetitions into your Macro Variable table at #500.

    Not sure about the format for repetition values in the M98 line. Some controls are different there. Also, there's a limit to the depth of nested programs, so if you have subs in your subs, this might be problematic.

  3. #3
    Join Date
    Jan 2008
    Posts
    74
    ok, thanks that makes sense. Now I'm trying to figure out how to set or even how to access my variable table....

  4. #4
    Join Date
    Jan 2008
    Posts
    74
    ok, I found my variables. I would like to keep it all in one program if possible. If I were programming my computer, I would do something like this:

    :0100

    for(int i = 0; i < =35; i++) {
    // call program 101
    // call program 102
    // call program 103
    };

    M30

    Can I do something similar on the lathe?

  5. #5
    Join Date
    Aug 2009
    Posts
    684
    #500=1
    WHILE[[#500]LE[35.]]DO1
    M98P101
    M98P102
    M98P103
    #1=#1-1
    END1

    Just change the 35 to however many repeats you need. Set #500 in program. Just make sure your sub programs don't use #500 or WHILE loops...

    DP

  6. #6
    Join Date
    Jan 2008
    Posts
    74
    #1=#1-1
    Should this be #1=#1+1? I am assuming 'LE' is 'less than or equal'?

  7. #7
    Join Date
    Aug 2009
    Posts
    684
    Yep, you are quite correct, er, looks like I changed my mind halfway through didn't I - sorry 'bout that one.

    DP

  8. #8
    Join Date
    Jan 2008
    Posts
    74
    :0100
    #500=1
    WHILE[[#500]LE[2.]]DO1
    M98P101
    M98P102
    M98P103
    #1=#1+1
    END1
    I ran this program and it didn't stop after 2 parts, just kept on going. I have to leave now, I'll be back in the morning. Thanks for all your input so far, might have a few more questions tomorrow.

  9. #9
    Join Date
    Aug 2009
    Posts
    684
    Aaaaah yes. I appear to have changed my mind twice in my original post...

    Change it to #500=#500+1 and all will be well.

    Made myself look a right clown there eh? I changed from local macros #1-#33 to common macros #500+ as I wasn't sure if the locals would be affected by jumping in and out of main program.

    More often than not I spend longer debugging my programs than coming up with the original concept....

    DP

  10. #10
    Join Date
    Feb 2008
    Posts
    586
    Quote Originally Posted by christinandavid View Post
    #500=1
    WHILE[[#500]LE[35.]]DO1
    M98P101
    M98P102
    M98P103
    #1=#1-1
    END1

    Just change the 35 to however many repeats you need. Set #500 in program. Just make sure your sub programs don't use #500 or WHILE loops...

    DP
    Likewise,

    :O0100
    #500=#500+1
    IF [#500 GT 35] GOTO N999
    M98P101
    M98P102
    M98P103
    M99
    N999M30

  11. #11
    Join Date
    Aug 2009
    Posts
    684
    Damn, couldn't find a single mistake in your post, am I the only one with poor brain/finger co-ordination ('co-operation' may be the right word in my case)?...

    Of course the GOTO method would also be the best way to go if you wanted to eliminate the need for sub programs.

    DP

  12. #12
    Hello.

    Christian is right with his method. The only thing is though, 500 variables are not cleared until they are physically changed. Therefore use 100 variables.


    :0100
    WHILE[#100LE35]DO1
    M98P0101
    M98P0102
    M98P0103
    #100=#100+1
    END1
    M30

    Fanuc Mate

  13. #13
    Join Date
    Jan 2008
    Posts
    74
    :0100
    WHILE[#100LE35]DO1
    M98P0101
    M98P0102
    M98P0103
    #100=#100+1
    END1
    M30
    That does the trick! Now, this is starting to give me big ideas...Will this work?

    :0100
    WHILE[#100LT[[#500-2.875]/1.312]]DO1
    M98P0101
    M98P0102
    M98P0103
    #100=#100+1
    END1
    M30

    I will store the length of my bar in #500. 1.312 is the amount the bar gets pulled in every cycle of the main program, 2.875 is the length of the 'remnant'
    part of the bar when I'm done. I'll try it but will probably run into problems. Can I nest brackets like I did? Will it be able to compare an 'integer' with a 'floating point'? Guess I'll find out...

  14. #14
    Join Date
    Aug 2009
    Posts
    684
    Yep, you can do all sorts of crazy sh!t...you can nest brackets, hell you can nest while loops too.

    I tend to go a bit overboard with my bracketing, especially when a / is lurking about. I would probably put something way OTT like [[#100]LT[[[#500]-[2.875]]/[1.312]]] then spend the next half hour playing with it 'til it gave me the correct result...

    DP

  15. #15
    Join Date
    Feb 2006
    Posts
    1792
    Parameters may sometimes play havoc which you may never expect.
    For example, 6001#7 and 6001#6, when set to 1, retain local and common variables, respectively, even after system reset.
    So, it is a good practice to always initialize the variable you are going to use.

  16. #16
    Join Date
    Dec 2004
    Posts
    167
    Im a little late and see that you already have a solution, but here is another option


    :0100
    M98P0101
    M98P0102
    M98P0103
    M99


    :0099
    M98 P???0100
    M30


    In your program 100 change the M30 to M99

    Program 99 would tell it to run program 0100 ??? amount of times. and ??? has to be 3 digit...so P0010100 would run program 100 1 time and P9990100 would run program 0100 999 time. we uses it al the time on our Fanuc OT lathes.

  17. #17
    Join Date
    Feb 2006
    Posts
    1792
    You may never need this information, but ...
    For repetition count over 999, use L-method which allows up to 9999 repetitions.
    (M98 P0100 L9999 repeats O0100 sequentially, 9999 times)

    Sinha

  18. #18
    Join Date
    Dec 2006
    Posts
    116
    I know that I'm digging this thread up from the grave but I got a ? about looping a pgm and limiting the amount of times that it loops. On a HAAS control I would do this:
    O6666
    M97 P100 L20
    N100 M11
    G91 G28 Z0.
    G28 X0. Y0. B0.
    S1000 M3
    G0 G91 X-13. Y-12. Z-9. B180. S2000 M3
    X-26. Y-1. Z-18. B300. S3000 M3
    X-13. Y-12. Z-9. B180. S4000 M3
    G91 G28 Z0.
    G28 X0. Y0. B0.
    M10
    M60
    M30
    This is just a simple warm up pgm that will run the machine thru it's axies.
    I will define the M97 line as thus:
    M97 (internal skip or sub pgm run)
    P100 (start @ N100 line)
    L20 (loop 20 times)
    What I want to do is let this pgm run 20 times and stop.
    Thank you for any help.
    WANNA GO FASTER

  19. #19
    Join Date
    Aug 2011
    Posts
    2517
    M97 is not a valid M-code on a standard Fanuc control.
    if you don't want to use macro or advanced techniques like those
    above you can use a sub program to repeat it...

    O6665
    M98 P6666 L20
    M30

    O6666
    N100 M11
    G91 G28 Z0.
    G28 X0. Y0. B0.
    S1000 M3
    G0 G91 X-13. Y-12. Z-9. B180. S2000 M3
    X-26. Y-1. Z-18. B300. S3000 M3
    X-13. Y-12. Z-9. B180. S4000 M3
    G91 G28 Z0.
    G28 X0. Y0. B0.
    M10
    M60
    M99

  20. #20
    Join Date
    Dec 2006
    Posts
    116
    Thanks ill give that a try
    WANNA GO FASTER

Similar Threads

  1. Open Loop to Closed Loop Stepper Conversion
    By beamhome in forum Stepper Motors / Drives
    Replies: 11
    Last Post: 03-09-2014, 11:27 PM
  2. CNC conversion typically open loop or closed loop?
    By foobar42 in forum Benchtop Machines
    Replies: 8
    Last Post: 10-30-2009, 01:21 AM
  3. question on closed loop vs open loop (servo systems)
    By boonie in forum Servo Motors / Drives
    Replies: 20
    Last Post: 11-09-2007, 07:30 PM
  4. Closed loop vs. open loop
    By pelesl in forum Benchtop Machines
    Replies: 10
    Last Post: 04-06-2007, 10:56 PM
  5. Lathe conversion - open loop vs closed loop
    By bhowden in forum Uncategorised MetalWorking Machines
    Replies: 7
    Last Post: 03-21-2006, 10:56 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
  •