Hello Guest it is March 28, 2024, 09:56:45 AM

Author Topic: Subroutine doesn't repeat  (Read 3508 times)

0 Members and 1 Guest are viewing this topic.

Subroutine doesn't repeat
« on: February 15, 2010, 08:02:18 PM »
I've just installed a Sherline rotary table on a Taig mill and it appears to work fine manually with jogging. Now the next task is to write G code to cut clock teeth. The basic plan is to move the cutter mounted on the spindle in toward the wheel mounted in a chuck mandrell on the vertically mounted rotary table to cut a tooth, move it out to the starting position and then rotate the table. The code includes a subroutine to do this 60 times to cut a wheel with 60 teeth. The problem is that the subroutine doesn't repeat. In addition, the movement back out from the wheel is twice the distance it moves in. I had to add an 1 to the end of the subroutine, Mach wouldn't accept just an M99 or an O1 - it gives a "return called with no sub in effect" and there is a window tha opens with "Please wait, generating path." What am I missing in the following code (disregard the completely commented lines, I just borrowed an existing bit of code). I've also had to reduce the distance the X axis travels - it seems the scale goes out of whack after adding a rotary table.

N5 (File Name = Cut teeth on wheel on Saturday, February 13, 2010)
N10 (Default Mill Post)
N15  (G91.1)
N20 (M5 M9 Stop spindle, Coolant off)
N25 (M6 T1 TOOL Change Sixteenth)
N30 (G43 H1Tool Length offset)
N35 (G0 Z0.0000 Rapid positioning Z axis)
N40 (Rotate Spindle clockwise at 400 M3 S400)
N45 (Positioning of X and Y – rapid because of previous G0)
N50 (G1 Z-0.0100 F10.00 Linear Interpolation of Z axis)
N55 M98 P1 L60 (M98 Calls a subroutine, P is the Routine and Letter O is subroutine label number, L for number of times)
N60 M5 (Program end)
N65 O1 (the subroutine)
N70 G1 X.5 F5 (move X axis for cutter to pass through wheel at feed rate 5)
N75 G1 X-.5 F5 (Move X axis back)
N80 A.016666 (rotate table clockwise 60/360 for 60 teeth in one revolution)
N85 M99 1(Return from subroutine)
Re: Subroutine doesn't repeat
« Reply #1 on: February 15, 2010, 10:06:26 PM »
Try this,
I'll mark the changes I made.

N85 M99 1(Return from subroutine)
N85 M99 (1 Return from subroutine)

N65 O1 (the subroutine)
o1 (the subroutine)

N80 A.016666 (rotate table clockwise 60/360 for 60 teeth in one revolution)
N80 G91 A.016666 (rotate table clockwise 60/360 for 60 teeth in one revolution)

N60 M5 (Program end)
N60 M5 (Program end)
M30

I think that's all.
Russ

« Last Edit: February 15, 2010, 10:12:18 PM by Overloaded »
Re: Subroutine doesn't repeat
« Reply #2 on: February 16, 2010, 07:34:50 PM »
Thanks for the help. The subroutine repeats and everything else works - almost. The X axis feed into the cutter moves, say one-half inch, the movement out from the cutter moves twice that - one inch regardless of the code. For the second pass after the rotary table turns, the X axis moves toward the cutter only one-half inch - not enough to move the wheel through the cutter.

I've not had this problem before and can't find anything in the code to explain it.
Re: Subroutine doesn't repeat
« Reply #3 on: February 16, 2010, 07:46:55 PM »
The X moves are Incremental,
Try this one (#2 below) if you want the table to move .500" each way.

If you want it to move 1" each way, you have to shift to Absolute mode.. (#3 below)

I may have told you wron at first....sorry. (maybe this time too  ::) but I hope not.

Russ
« Last Edit: February 16, 2010, 08:21:09 PM by Overloaded »
Re: Subroutine doesn't repeat
« Reply #4 on: February 17, 2010, 08:17:55 PM »
My Mach is haunted. I tried #3 to move one inch and the X axis moves in one inch and 2 inches out. Then I replaced the G90 with G91 and tried to fake it out by putting -.5 there and it worked - the axis went out 1/2 inch. Then finally I changed the -.5 to 1 and now the table moves in and out the same distance. The second G91 is probably not needed. Anyway it works. Thanks for the help. Why the code should need G90 to move toward the cutter and G91 to move away is beyond me but as I say, it works, kludgy, but it works.

N5 (File Name = Cut teeth on wheel on Saturday, February 13, 2010)
   G90
N55 M98 P1 L60 (M98 Calls a subroutine, P is the Routine and Letter O is subroutine label number, L for number of times)
N60 M5 (Program end)
   M30
o1 (the subroutine)
   G90
N70 G1 X1 F5 (move X axis for cutter to pass through wheel at feed rate 5)
N75 G91 G1 X-1 F5 (Move X axis back)
N80 G91 A.016666 (rotate table clockwise 60/360 for 60 teeth in one revolution)
N85 M99 (1 Return from subroutine)