Sub routines

A place to discuss and ask questions about all things Machining for Mills, Lathes, Laser, and Routers

Moderator: cnckeith

cmickey
Posts: 15
Joined: Thu Jan 21, 2021 6:25 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Sub routines

Post by cmickey »

Description: Cutting a slot .100 deep X 5 inches long in a piece of .375 X 7".And to demonstrate a sub routine
to achieve a total depth of .100
Ignore feed and speed rate as I know they are incorrect.

I would appreciate the help. I think I'm close but I'm also new at this.

0001 go g1 g20 g90 g80

0005 m06 m03 (tool select, spindle on CW)

00010 x0 y0 z.01 (SENDS Z AXIS TO .01 ABOVE MATERIAL)

00015 m98 p1000 L6 (sub call for a repeat action 6 times)



n1000 g91 z-.03 f.1 (SENDS Z AXIS TO .02 BELOW ZERO AT A FEED RATE OF .1)

n1010 x-5 f.5 (MOVES THE X AXIX 5 INCHES IN THE MINUS DIRECTION AT A FEED OF .5)

n1012 z-.02 f.1 (moves z -.02 at a speed of .1)

n0013 x5 f.5 (move x 5 inches in te positive direction)

n1015 G91 Z-.02 F.1 (CHANGES THE IMCREMENTAL, MOVES Z AXIS -.02 AT FEED OF .1)

n1020 X5 F.5 (MOVES X BACK TO STARTING POINT)

m99 (send back to N1000 to start cycle 2)
%
suntravel
Posts: 1967
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: Sub routines

Post by suntravel »

The subprogramm# must be in the range O9100 - O9999.cnc to be called with M98

13.27 in the Mill Manual.

Uwe
cmickey
Posts: 15
Joined: Thu Jan 21, 2021 6:25 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Sub routines

Post by cmickey »

Thanks, got he manual in front of me.
cmickey
Posts: 15
Joined: Thu Jan 21, 2021 6:25 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Sub routines

Post by cmickey »

Thanks, here is my edit.
m98 p9100 L6 (sub call for a repeat action 6 times)



o9100 g91 z-.5 f.5 (SENDS Z AXIS TO .5 BELOW ZERO AT A FEED RATE OF .5)

o9102 x-5 f.5 (MOVES THE X AXIX 5 INCHES IN THE MINUS DIRECTION AT A FEED OF .5)

o9104 z-.05 f.1 (moves z -.5 at a speed of .5)

o9106 x5 f.5 (move x 5 inches in te positive direction)

o9108 G91 Z-.5 F.1 (CHANGES THE IMCREMENTAL, MOVES Z AXIS -.02 AT FEED OF .1)

o9110 X5 F.5 (MOVES X BACK TO STARTING POINT)

m99 (send back to N1000 to start cycle 2)
%
cncsnw
Posts: 3763
Joined: Wed Mar 24, 2010 5:48 pm

Re: Sub routines

Post by cncsnw »

You seem to be using program numbers ("Onnnn") as if they were block numbers ("Nnnnn"). You want just one program number, at the start of the subprogram, paired with one M99 that marks the end of that subprogram.

Also, the subprogram should be defined at the top of the program (before it is called).

When CNC12 encounters "M98 P9876", it goes and looks for a subprogram file named "O9876.cnc" and runs the codes in it.

When CNC12 encounters "O9876", it extracts that line, and all lines through to the matching "M99", and saves them into a file named "O9876.cnc".

So, it may appear to work even if you put the subprogram definition at the bottom of the file, but any time you make an edit to the subprogram contents, then the first time you run (or graph) the job after editing, you will be using the old extracted file and not the new content.
cmickey
Posts: 15
Joined: Thu Jan 21, 2021 6:25 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Sub routines

Post by cmickey »

LOL I am a little confused. So I need to create the code for the sub routine and save it to the .cnc directory.
suntravel
Posts: 1967
Joined: Thu Sep 23, 2021 3:49 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: 6433DB0446C1-08115074
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No
Location: Germany

Re: Sub routines

Post by suntravel »

I prefer to write macros and call them with G65.

Example is here:

https://centroidcncforum.com/viewtopic.php?f=66&t=7870

Uwe
cmickey
Posts: 15
Joined: Thu Jan 21, 2021 6:25 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Sub routines

Post by cmickey »

Thanks to all. I have a lot to absorb.
cncsnw
Posts: 3763
Joined: Wed Mar 24, 2010 5:48 pm

Re: Sub routines

Post by cncsnw »

I am a little confused. So I need to create the code for the sub routine and save it to the .cnc directory.
No, not necessarily.

As long as you introduce the subprogram using a program number (O number) between O9100 and O9999, then CNC12 will copy the subprogram codes out into a separate file for you.

If you want to create and call a subprogram with a number that is not between 9100 and 9999, then you need to put it in a suitably-named file in the ncfiles subdirectory (e.g. if you have created a file "O5678.cnc", then you can call it with M98 P5678, or with G65 P5678).
cmickey
Posts: 15
Joined: Thu Jan 21, 2021 6:25 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Sub routines

Post by cmickey »

That helps to clear up my head. Thanks
Post Reply