Machsupport Forum

G-Code, CAD, and CAM => G-Code, CAD, and CAM discussions => Topic started by: KNS Supply on March 21, 2008, 01:26:48 PM

Title: HELP WITH A M98 SUBROUTINE
Post by: KNS Supply on March 21, 2008, 01:26:48 PM
I NEVER HAD A USE FOR A SUBROUTINE. OR "M98"
IN MACH 3 MILL HOW IS ONE CALLED AND SET UP
CAN ANYONE GIVE ME AN EXAMPLE?
THANKS,
BRIAN
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Graham Waterworth on March 21, 2008, 03:20:20 PM

%
O0001 (MAIN PROGRAM)
G00 G90 G43
etc..
M98 P0002 L1
M30

O0002 (SUB PROGRAM)
(SOME CODE)
M99
%

Graham.
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: KNS Supply on March 21, 2008, 04:54:53 PM
OK UHH OK
I'M LOST
THE MAIN PROGRAM WILL RUN BUT WHEN I GET TO THE SUB IT JUST STOPS AND REWINDS

Title: Re: HELP WITH A M98 SUBROUTINE
Post by: KNS Supply on March 21, 2008, 04:57:49 PM
HERE IS THE PROGRAM
JUST FOR GRINNS


%
O0001 (Nec g code 1.TAP)
G00 G90 G43


N5 (File Name = Nec g code March 20, 2008)
N10 (.750 ENDMILL)
N15  G91.1
N20 M5 M9

N25
N30
N35 G0  Z0
N40 M3
N42 
N45 X6.4651  Y0.4259
N50
N55 G0  Z-1.050   
N60  G1 X6.4119   F30.00
N65  G1 X0.3308   
N70 G2  X5.6035  Y0.0033  I2.7544  J1.2625
N75 G0  Z-1.05000
N80 G0 X6.4578  Y0.4384
N85  Z-1.05
N90 G1  Z-1.05000
N92  F30
N95 G1 X0.3581

N100 G2  X5.5710  Y0.0088  I2.7272  J1.2500
N105 G1 X5.5650  Y0.0000  I-2.4858  J1.6796
N110 G0  Z0

( TOP FLATS)

N115  G0 X0.3368  Y2.8909
N120 
N125 G0  Z-0.2700   
N130 G1 X1.1077   F30.00
N135 G1 Y3.9444   
N140 G1 X1.4077  Y4.1756   
N145 G1 Y2.5909   
N150 G1 X0.2242   
N155 G1 X0.1464  Y2.2909   
N160 G1 X1.7077   
N165 G1 Y4.3535   
N170 G1 X2.0077  Y4.4882   
N175 G1 Y1.9909   
N180 G1 X0.0000   
N185 G0  Z0
N190 G0 X1.8402  Y2.6434
N195 G0  Z-.20

(PLUNGE POCKETS L SIDE)

N199 G1 Z-.5  F3
N200 G0 Z-.200
N201 G0 Z-.45
N202 G1 Z-.750  F3
N203 G0 Z-.200
N204 G0 Z-.7
N205 G1  Z-1.050  F3


N207 G1 Y2.6761   F10.00
N210 G1 Y3.1384   
N215 G1 X1.7302   
N220 G1 Y2.1484   
N225 G1 X1.9502   
N230 G1 Y3.1384
N232 G1 X1.740
N235 G0  Z0
N240 G0 X6.0699  Y1.9909
N245   
N250 G0  Z-.270
N255 G1 X4.1627   F20.00
N260 G1 Y4.4882   
N265 G1 X4.4627  Y4.3535   
N270 G1 Y2.2909   
N275 G1 X6.0241   
N280 G1 X5.9462  Y2.5909   
N285 G1 X4.7627   
N290 G1 Y4.1756   
N295 G1 X5.0627  Y3.9444   
N300 G1 Y2.8909   
N305 G1 X5.8337   
N310 G0 Z-.2
N315 G0 X4.3302  Y2.6434
 
 

(PLUNGE POCKETS R SIDE)

N316 G1 Z-.5  F3
N317 G0 Z-.200
N318 G0 Z-.45
N319 G1 Z-.750  F3
N320 G0 Z-.200
N321 G0 Z-.7
N322 G1  Z-1.050  F3




F10.00
N335 G1 Y3.1384   
N340 G1 X4.4402   
N345 G1 Y2.1484   
N350 G1 X4.2202   
N355 G1 Y3.1384   
N336 G1 X4.42




N360 G0  Z0
N365  X1.3452  Y2.0134
N370  Z0

(.375 BALL MILL)
(POCKETS)








M98 P0002 L1
M30

O0002 ( POCKETS.TAP)
(SOME CODE)
M99
%
 
 
N480 G0  Z1.0000
N485 M5
N490 M30

Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Graham Waterworth on March 21, 2008, 06:51:22 PM
OK, if you had to centre, drill and tap 4 hole you could use a sub for the hole positions like this.

%
O0001 (MAIN PROGRAM)

G21 G40

N1 (CENTRE DRILL)
T1 M6
G54 G00 G90 G43 X0 Y0 Z25. H1 S1000 M3
G81 Z-2. R1. F100. M8
M98 P0002 L1
G80
G91 G28 Z0 M6
M1

N2 (DRILL 5.00 DIA)
T2 M6
G54 G00 G90 G43 X0 Y0 Z25. H2 S1000 M3
G81 Z-20. R1. F100. M8
M98 P0002 L1
G80
G91 G28 Z0
M1

N3 (TAP M6*1)
T3 M6
G54 G00 G90 G43 X0 Y0 Z25. H3 S100 M3
G84 Z-12. R3. F100. M8
M98 P0002 L1
G80
G91 G28 Z0 M6
M30

O0002(HOLES SUB)
X-25.
Y-25.
X0
M99
%


Graham.
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: KNS Supply on March 21, 2008, 07:05:59 PM
COOL THANKS
1 MORE ? AND I'LL LEAVE YOU BE..
IN THE G CODE PROGRAM, ALL THE LINES ARE NUMBERED.
IF I WANTED TO PUT IN A BLOCK OF CODE (30 LINES) IN THE MIDDLE OF THE
PROGRAM, IS THERE ANY WAY OF DOING THAT WHERE I WON'T HAVE TO RENUMBER ALL THE LINES?

THANKS FOR ALL THE HELP GRAHAM,
BRIAN
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Sam on March 21, 2008, 08:30:32 PM
The line numbers serve no purpose, other than a visual aid to help you find something quickly. So just paste or type your code right in there.
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Mountainman on April 24, 2013, 04:41:56 PM
Ok, I wrote this program to tune my Z axis with and have had no luck with teh M98.  Basically what happens is that after an M99 instead of going on with teh program, it rewinds to N10.  I want it to first do N10-20 and then do N50-60 five times and then go on to N100-130  five times and then go on to N150-180.  W/ out a M30 it doesn't loop on the subroutines, but with it, after the first subroutine is done 5X's then it just goes to N10. 
(Z axis tuning program)
( no tool)
N10  G20 G17 G91 F30
N20  G0 z-.75
N30  M98 P1234 L5
N40  M30
   O1234
N50  G1 Z-.5  F5
N60     Z.5
N70  M99
N80  M98 P1235 L5
N90  M30
   O1235
N100 G1 Z-.25 F10
N110    Z-.75
N120    Z.75
N130    Z.25
N140 M99
N150 G90
N160 G1 Z-2
N170 G0 Z0
N180 M30
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Sam on April 24, 2013, 05:21:45 PM
N10  G20 G17 G91 F30
N20  G0 z-.75

N30  M98 P1234 L5
N80  M98 P1235 L5

N150 G90
N160 G1 Z-2
N170 G0 Z0
N180 M30

O1234
N50  G1 Z-.5  F5
N60     Z.5
N70  M99

O1235
N100 G1 Z-.25 F10
N110    Z-.75
N120    Z.75
N130    Z.25
N140 M99
%
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Mountainman on April 24, 2013, 05:26:41 PM
Thank you so very much. 
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Sam on April 24, 2013, 05:47:20 PM
Your welcome.
M30 should only be used once, at the end of the program. If not used at the end of the program, the program will indeed end, and rewind, ignoring all that comes after it.
It is also better to lay out your programs for a smooth flow. Notice the sub calls are together, the subs are at the tail end, and the rest of the code is back up above the subs with the M30 ending the program. With a quick glance, you can tell that the program consist of a Z move at the beginning, then runs two subs, then makes a couple more moves, then ends (as indicated by the M30). This keeps you from scouring through a big long file, looking for an error(s) when things don't go as expected.
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Mountainman on April 26, 2013, 12:51:17 PM
OK I tried using what you did and writing another program, no luck.

(Tool #810 8T brazed carbide keyseat)
(Work piece 1.5X.720X.648")
N10   G20 G17 G90  G54 S500 F5.3
N20   G0  X1.891 Y.9983
N30       Z-.490   M3 M8
N40   G1  X-1.866 Y-.9623

N50   M98 P1234 L11

N100  G90 G1  X1.561 Y.521
N110  G0  X1.926 Y1.034 
N120  G91 G1 Z.032

N130  M98 P1235 L1

N180  G1 Z-.064

N190  M98 P1235 L1

N200  G90 G0 Z0 M5 M9
N210  X0 Y2 M30


     O1234
N70  G91 G91.1
N80  G2 X-.0037 Y.0208 R.015
N80  G1  X-.0219 Y-.0578
N90  M99

     O1235
N150 G91 G1 X-.366 Y-.513 F6.5
N160 G0 X.366 Y.513 
N170 M99
%
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Sam on April 26, 2013, 01:53:25 PM
Take out all the extra spaces in the file. The spaces before the "O1234" is actually what was causing the problem, but take out all the other ones too just to be tidy and avoid a potential problem. Some controls may not care if you have spaces, some do. Every control software has its quirks, and what works with one may not work with another. The best thing to do is just make every file as tidy as can be, and then errors are much easier to diagnose.

Other than that, the file looked fine and the subs ran perfect.

Also, you may need to change the G91.1 to G91.0
I have no idea what your actually wanting, so it may be correct as-is, but changing it just made it "look" more appropriate.



(Tool #810 8T brazed carbide keyseat)
(Work piece 1.5X.720X.648")
N10   G20 G17 G90 G54 S500 F5.3
N20   G0  X1.891 Y.9983
N30   Z-.490   M3 M8
N40   G1  X-1.866 Y-.9623

N50   M98 P1234 L11

N100  G90 G1  X1.561 Y.521
N110  G0  X1.926 Y1.034
N120  G91 G1 Z.032

N130  M98 P1235 L1

N180  G1 Z-.064

N190  M98 P1235 L1

N200  G90 G0 Z0 M5 M9
N210  X0 Y2 M30

O1234
N70  G91 G91.1
N80  G2 X-.0037 Y.0208 R.015
N80  G1  X-.0219 Y-.0578
N90  M99

O1235
N150 G91 G1 X-.366 Y-.513 F6.5
N160 G0 X.366 Y.513
N170 M99
%
Title: Re: HELP WITH A M98 SUBROUTINE
Post by: Mountainman on April 26, 2013, 03:05:54 PM
I finally got all the bugs out. 

(Tool #810 8T brazed carbide keyseat)
(Work piece 1.5X.720X.648")
N10   G20 G17 G90  G54 S500 F5.3
N20   G0  X1.891 Y.9983
N30       Z-.490   M3 M8
N40   G1  X1.866 Y.9623
N50   M98 P1234 L11
N100  G90 G1  X1.561 Y.521
N110  G0  X1.926 Y1.034 
N120  G91 G1 Z.032
N130  M98 P1235 L1
N180  G1 Z-.064
N190  M98 P1235 L1
N200  G90 G0 Z0 M5 M9
N210  X0 Y2 M30

O1234
N70  G91
N80  G2 X-.0037 Y.0208 R.015
N80  G1  X-.0219 Y-.0578
N90  M99

O1235
N150 G91 G1 X-.366 Y-.513 F6.5
N160 G0 X.366 Y.513 
N170 M99
 
Again thank you Oh so verry much.  You will make a programmer out of me yet.