586,221 active members*
3,606 visitors online*
Register for free
Login
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2005
    Posts
    214

    how to write a subroutine

    I'm using Wincnc and am attempting to write some simple subroutines. I've got the actual gcode figured out and how to write it in Wincnc, the problem is, I can't figure out when you call it, where you're calling it from. Where would the subroutine be filed? There's no folder for subs in Wincnc, although there's one for macros. I tried putting it in the main Wincnc folder and also the folder I normally run programs from without success.

    I've searched for info and there's plenty on calling subroutines but never where they live. I got a feeling it's really simple so it's never mentioned......
    www.harryhamilldesigns.com
    CAD sculpting and services

  2. #2
    Join Date
    Mar 2003
    Posts
    4826
    From a casual read of the manual, it looks like they use M98 "Filename" to call the subprogram and M99 to return from the sub.

    The main program will contain the M98 Filename command on the exact line where you want to leave the main program. Obviously, you put either the name of your file in place of Filename, or else, standard practice would dictate that you use a program number to describe the program, but instead of using the big O for the filename, you would use P or sometimes another letter. So if the subprogram is a file called O12345,
    M98 P12345
    would be a typical subcall.

    Now perhaps they've got this setup so that you can use a DOS type 8 character filename, but I'd try it simple first, to get it working.

    At the end of your subprogram, you'll need a simple M99 and the controller should then return to the main program.

    As for paths, one would think that if you kept both the main and the sub programs in the same folder, that the control should be able to find it.
    First you get good, then you get fast. Then grouchiness sets in.

    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  3. #3
    Join Date
    Mar 2005
    Posts
    214
    Thanks,

    I'll try a different naming format, I just tried a standard text name without any luck. As you saw, they don't specify how to name the sub but the manual tends written for those who already know what they are doing, not for those who don't.
    www.harryhamilldesigns.com
    CAD sculpting and services

  4. #4
    Join Date
    Jun 2008
    Posts
    1511
    HuFlung is correct with calling a sub program. Here is an example of a typical sub call.

    O0001(Main Program)
    G0G90G54
    X0Y0Z0
    M98P1234------------This will leave program 1 and start running 1234
    G0G80
    M30

    O1234(Sub Program)
    ...
    ...
    ...
    M99-------------------This is were program 1234 will end and go back to program 1. It will go back to program 1 were it left from so it will start with the G0G80 line and continue.

    A macro Call works the exact same way except you would use G65P1234 and the assign variables to carry over with it. A, B, H, D, R etc. This would all be in the same line and you would say A=5 for number of holes B=81 for drilling cycle H=20 for part height etc. This would call to program 1234 then when it reads M99 will come back to here but start at the M30 program end. This however uses your local variable assignments #1 #2 #3 etc. So your sub would be using something like G0Z#3.

    G65P1234A5.B81H20.
    M30

    Stevo

  5. #5
    Join Date
    Mar 2005
    Posts
    214
    Hmmm, I tried what you guys suggested and it's still not working. When I run a simple test program and it calls the sub, I get an error "Can't find sub123" or whatever I name it. I've tried placing it in different locations, although putting it in the folder I use for my usual programs seems the most logical.
    www.harryhamilldesigns.com
    CAD sculpting and services

  6. #6
    Join Date
    Jun 2008
    Posts
    1511
    Your not running this on the control? You are running from a PC? I am not sure how the folders are suppose to be set up when running from the PC. When the M98P123 is seen by the control it is looking for program 123 in the machine directory. If it is not registered in the directory it will give you and alarm "program not found".

    If you are doing it via PC is there a reason that you want sub programs?

    The other way to make it work would be to write your sub program and register it in the control as program O0123. Then when the control sees M98P123 in the main program it will run it from memory.

    Stevo

  7. #7
    Join Date
    Jul 2003
    Posts
    263
    if you are using your control to call the sub from a PC you need to use M198Pxxxx not M98 Pxxxx

    there is a parameter you have to set so the control is looking for a prog and not a file, not sure what it is on your control.
    If you can ENVISION it I can make it

  8. #8
    Join Date
    Jun 2008
    Posts
    1511
    I have never called sub programs from PC we run everything from the control. The king is right about the M198Pxxxx according to the book. I do not know what kind of control you are on but for the 15B series control it appears to be parameter #2404 bit 5. If =1 specify file, if =0 specify program. Then on the 18i series controls it appears to be parameter #3404 bit 2. If =1specify program, if =0 specify file.

    Stevo

  9. #9
    Join Date
    Mar 2005
    Posts
    214
    If you are doing it via PC is there a reason that you want sub programs?
    I'm customizing my screen and I want to set up a button to pull up Z, go to XY coordinates, then lower Z. Wincnc doesn't allow that much code in it's screen file, only a single line and thought a sub would be better. I thought it would be a decent thing to learn too, might come in handy.


    Your not running this on the control? You are running from a PC?
    I'm using Wincnc on a PC, it drives steppers with built in control boards via a PCI card. It's a desktop mill, there's no "built in" controller if that's what you're referring to. I'm not a machinist, so forgive my ignorance in how larger commercial machines are set up.


    if you are using your control to call the sub from a PC you need to use M198Pxxxx not M98 Pxxxx
    I'll try that and see
    www.harryhamilldesigns.com
    CAD sculpting and services

  10. #10
    Join Date
    Mar 2005
    Posts
    214
    I've gotten it figured out, thanks for all the help.

    I actually got help from a support person at Wincnc, it's a rare event, but I hear they have different management these days so hopefully it will be more common.

    You have to set up your subs as a macro and the file has to have a .MAC extension and be in their main folder. You can name it what you want and M98 "name" will work.
    www.harryhamilldesigns.com
    CAD sculpting and services

  11. #11
    Join Date
    May 2007
    Posts
    1003
    Although I am not familiar with your system, I want to thank you for getting back to us with the proper solution.

    I wish everyone would.

  12. #12
    Join Date
    Mar 2005
    Posts
    214
    It was the least I could do..... <bow>
    www.harryhamilldesigns.com
    CAD sculpting and services

Similar Threads

  1. M97, M98 subroutine call. How to use
    By bob1112 in forum Haas Mills
    Replies: 11
    Last Post: 03-13-2008, 01:41 AM
  2. Example of a Subroutine?
    By donl517 in forum Fadal
    Replies: 14
    Last Post: 06-27-2007, 04:05 PM
  3. Help with calling a subroutine
    By hindocarina in forum Mach Mill
    Replies: 2
    Last Post: 02-12-2007, 04:32 AM
  4. trying to call a subroutine
    By hindocarina in forum G-Code Programing
    Replies: 4
    Last Post: 02-12-2007, 03:01 AM
  5. Need help with subroutine
    By 2_jammer in forum Uncategorised CAM Discussion
    Replies: 1
    Last Post: 01-18-2005, 05:46 AM

Posting Permissions

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