Bridgeport Anilam Crusader II CNC Mill Pgrm & Ops

Chapter 10 -- Do Loops & Subroutines

The Crusader II CNC controller allows programmers to efficiently group repeated commands together using Do Loops and/or Subroutines.

Do Loops

A Do Loop is a series of commands to be executed a stated number of times. A typical example of using a loop is to generate a set of equally-spaced drilled holes or a series of parallel slots. Due to their portable nature, almost all X and Y-axis movement commands inside loops will be incremental.

The sequence of a loop is as follows:
    a) For X, Y, &/or Z axes locations, move into position or to an appropriate offset position,
    b) As required, load canned cycle variables and activate,
    c) Activate the loop sequence,
    d) Repeat the series of commands for the desired number of times.


Example:
Beginning at the X-Y point (1-1/4,-3/8), drill an array of 10 holes along the X-axis 1/2" apart.

Anilam Format:

A loop begins by pressing DO and then a number representing the number of times the loop is to be executed followed by Event Enter.
The end of the loop is identified by pressing the End Event Enter

Sequence of events:

      EVENT   VAR   VALUE		COMMENT
    ----------------------------------------------------------------------
	42 	V20	6.2 		$ Z-stroke feedrate (IPM)
	43 	V21	.100  		$ Z clearance plane (ABS)
	44 	G81 			$ Activate canned drill cycle.
	45 	X1.25 Y0.375 Z.75 	$ X & Y location of first hole &
 					$   Z-stroke depth of all holes
	46	DO 9 			$ Set a DO-LOOP for 9 executions
	47 	X.5 INCR RAP 		$ Move over 1/2 inch & drill hole
	48 	END 			$ End of the loop
	49 	G80 			$ Cancel canned Z-cycle.

EIA-274 Format

 CNC PROGRAM CODE				COMMENT
------------------------------------------------------------------
N155 G29 LV20=6.2 V21=.1  		$ VAR: Feedrate, Z-clearance
N160 G81				$ Set drill cycle 
N165 G00 X1.25 Y0.375 Z0.75	 	$ Rapid to 1st hole & Z-depth.
N170 G29 D9 				$ Begin loop.  D9 = DO 9 times. 
N175 G91 X0.5  			$ Rapid incremental move.
N180 G29 E 				$ End of loop.
N185 G80 				$ Cancel drill cycle.

Table of Contents Top of Page

Subroutines (Macros)

A subroutine is a subsection of a program (perhaps to mill a slot) that has to be performed at several locations on the workpiece. As with Do Loops, almost all X and Y-axis movement commands inside subroutines will be incremental (G91).

Subroutines can be entered in any order; they need not be programmed or called in numerical order.

Subroutines always:

  1. Must be physically located beyond the end of the main program.
  2. Begin with a number label, for example (Anilam format) SUBRoutine Four Event Enter.
    The label number can be any number between 1 and 8,999.
  3. End with (Anilam format) END Event Enter.
  4. Are executed by issuing a CALL command, for example (Anilam format) CALL Four Event Enter, at the points in the main program where the subroutine is to be executed.

Anilam Format:

      EVENT   VAR   VALUE		COMMENT
    ----------------------------------------------------------------------
	34	CALL	4	$ Leave main program and execute  
				$ subroutine #1, then re-enter main  
				$ program at next event.
	207	CALL	4 	$ Leave main program (again) and execute  
				$ subroutine #1, then re-enter main 
				$ program at next event.
	321	CALL	4 	$ Leave main program (again) and execute 
				$ subroutine #1, then re-enter main $ program at
				$ next event.
	381 END 		$ End of main program.  
	382 SUBR 4 		$ Begin subroutine 1 definition.  
	382 \
	 to   >	 X, Y, and Z, etc., commands comprise body of subroutine	
	421 /	
	422 END 		$ Terminates subroutine definition.

EIA-274 Format:

 CNC PROGRAM CODE				COMMENT
------------------------------------------------------------------
N035	G29 C4 		$ Call subroutine #4

N205	G29 C4 		$ Call subroutine #4

N320	G29 C4 		$ Call subroutine #4

N385	G29 E 		$ End of main program.
$ -------- Subroutine #4 -------------------------------------
N700  G29 S4 		$ Begin subroutine #4 definition. 
N705 \
  to   >  X, Y, and Z, etc., commands comprise body of subroutine	
N825 /  
N830  G29 E 		$ End of subroutine #4 definition.

Table of Contents Top of Page Next Chapter

Copyright © 2003 George C. Stanton & Bill Hemphill
All Rights Reserved

Last updated on Feb. 1, 2003 by Bill Hemphill