Machsupport Forum

G-Code, CAD, and CAM => G-Code, CAD, and CAM discussions => Topic started by: JoeMickley on December 17, 2016, 04:37:39 PM

Title: Using an M98 sub call as a GOTO
Post by: JoeMickley on December 17, 2016, 04:37:39 PM
G-code does not have a "GOTO" function but I believe that I could use an M98 (Subroutine call) to cause the branch and then just never use the M99 (Return).   That will allow me to branch around sections of code.  I can later "NO-OP" the call and have the original code back.  The program will run until it encounters the M30 (Or manual STOP and REWIND), skipping over some portions, then hit the M30 and stop/rewind.

My concern is that I am leaving the call stack (or whatever implementation Mach3 uses) unbalanced.  There are some number of subroutine CALLs with no RETURNS.  The question is "Does Mach clean up the stack on the M30 or manual STOP/REWIND?"  I would assume that it does because I use subroutines and can manually STOP and REWIND a program in the middle of a sub even if nested several levels deep, but I don't know that it will still work if the program is repeated enough times.

Also, what is the stack depth for CALLS?  That would be useful info for general information.

Any other suggestions on how to implement a GOTO welcome.
Title: Re: Using an M98 sub call as a GOTO
Post by: Graham Waterworth on December 23, 2016, 06:06:28 PM
You could write the g-code into a VB M code macro and use the VB side to to the jumps.
Title: Re: Using an M98 sub call as a GOTO
Post by: JoeMickley on December 23, 2016, 08:09:36 PM
I'm not familiar enough with VB macros to know how to do that.  Maybe something I should learn. (Life is a learning experience.)

In the meantime I tried it on a real job and it worked well BUT ...
I still don't know if it's safe from the standpoint of repeatedly executing the same NC program for multiple parts without having Mach come unglued at some point with an unbalanced stack.  When I used it I then exited Mach and re-started it.  That way I know the stack was re-initialized and everything was clean.

I think I'll set up a test case with many of my "GOTOs' and many iterations of running the same program without re-starting Mach.  (If you can't analyze it any other way then set it up and pound on it until you are satisfied or tired.)

Title: Re: Using an M98 sub call as a GOTO
Post by: Snowboy on September 05, 2017, 03:23:19 AM
Hi there i'm using bobcam-cad V28 set to plasma to Mach 3 on a laptop. My drawing is simulated OK, but as soon as I post to mach3, that runs in plasma mode the units jump from mm to inches everytime. Both cad and mach is set to mm .Could it be my post processor (mill plasma) that is set to inches? Or have I missed something.   Thanx Luan
Title: Re: Using an M98 sub call as a GOTO
Post by: Tweakie.CNC on September 05, 2017, 03:34:11 AM
Quote
Could it be my post processor (mill plasma) that is set to inches?

Check your generated Gcode - does it contain a G20 or a G21 ?

Tweakie.
Title: Re: Using an M98 sub call as a GOTO
Post by: Snowboy on September 05, 2017, 04:14:09 AM
I have looked in the G codes could not find G20 or G21
Title: Re: Using an M98 sub call as a GOTO
Post by: Tweakie.CNC on September 05, 2017, 04:26:56 AM
If your machine (Mach3 set-up) is set to operate in Metric units and your CAD/CAM working is in Metric units then your Post Processor should add a G21 towards the beginning of the Gcode file it produces.

Check that you do indeed have BobCam set to operate in Metric units.

Try adding a G21 to the beginning of your Gcode file.

Tweakie.
Title: Re: Using an M98 sub call as a GOTO
Post by: Snowboy on September 05, 2017, 04:32:06 AM
Thanx Tweakie will give it a try