CNC Subprograms Basics for CNC Machinists

CNC programmers and machinists have to daily deal with different kind of component with variety of machining operation.
So to keep up with the pace they implement different techniques.

What is Sub Programming?

One of such and mostly used technique is Sub-programming.
Sub-programming is easy to use and understand with just simple commands like M98, M99 you can achieve greater flexibility.

Subprograms are normal cnc programs which are called from a program (normally called main-program) to add some kind of repeatable machining operation.

CNC Subprogram Examples


CNC Sub Programming Basics

CNC Sub Programming Basics

For Sub Programming No Extra Skill Required

You (cnc machinist/ cnc programmer) not have to learn a new G-code or programming style, all you use is the knowledge of cnc programming which you already have.
Subprograms are like normal programs which we daily add, write, alter and delete.

CNC Subprograms End with M99

One important distinction among a main-program and a subprogram is that
main-programs end with M30 but
subprograms end with M99

CNC Subprograms Naming

Subprogram are normal cnc programs, so are named (numbered) similar way like O0001, O0005 etc.
How to Insert a CNC Subprogram?
Subprograms are inserted the same way in cnc machine controls, as other cnc programs are made.

CNC Subprogram Call

Subprograms can be called from main-program multiple times at multiple locations.
Even subprograms can call other subprograms.
Normally subprogram can be nested up-to four levels.
How to call a subprogram read Fanuc Sub Programming

CNC Subprogram End

When a sub-program ends with M99 the control is given back to the calling program (main-program), and program execution starts from that point onward.

If a main-program (O0001) calls a subprogram  (O0002) and that subprogram calls another subprogram (O0003).
So when O0003 after completion of its machining will end with M99 the control will be returned to O0002 and machining will continue until that sub-program ends with M99, at that call the control will be back to O0001 and that will continue to execute until it reaches M30, which will end the program.