Table of Contents
IntroductionManual Operation & Start-up Procedures
Programming in the ISO (EIA-274-d or G-code) Format
Canned Cycles
Back to Heidenhain Pgrm and Op Instr home page
Subroutine Syntax:  Please look up and over to your right
Loop Syntax
Location of Lables
Example Program
Console Editing
Setting Tool Length Offsets (TLOs)
Running Programs
Data Transfer PC<---> CNC
Demonstration Program
Credits and Copyright Information

Bridgeport Heidenhain CNC Mill
Programming & Operating Instructions

Chapter 5
Lables:  Subroutines (Macros) and Loops

Subroutine Syntax

Subroutine "Label" definitions begin with

     G98 Ln 

and end with

     G98 L0

where "n" = the label (subroutine) number.

  • A call statement is used in the main program—or it can be "nested" within another subroutine "label"—to execute a subroutine label.
    It consists simply of  Ln where "n" = the label (subroutine) number (without the G98).

Back to the top of this page

Loop Syntax

Loops (also called labels) begin with a

    G98 Ln 

and end with

    Ln.r  (again, no G98) 

where the "n" = the label number and the "r" = the number of repeats, not executions.

  • The "r" is usually set at one less than the total executions because the loop "r" counter is not read until the cycle has been initially executed once. Then the "r" counter, located at the end of the loop, is read. The loop is exited when the "r" counter reads zero.

Back to the top of this page

Location of Lables

Labels used as subroutines or as loops should be defined beyond the end of the program—after the M30 so that it is never encountered except as the result of a label call statement.

Back to the top of this page

Example Problem

:Drill an array of six 1/4" dia. holes thru 1/2" thick material, 1/2" apart on X axis.
Z clearance = 0.100".
Z-stroke = 0.775" = (.3*.25") point length + 0.1" top clearance + 0.5" part thickness + 0.1" bottom clearance Z-stroke

Note:
The loop is in boldface type.
Comments following the '$' character must be removed prior to uploading program.

%560 G70			$ PROGRAM NO. INCH
N10 G99 T7 L-1.0 R+0.		$ DEFINE TOOL #7; TLO = 1.0"
N20 T7 G17			$ ACTIVATE T7's TLO
N30 L5.0			$ CALL LABEL (SUBROUTINE) #5
N40 M30				$ REWIND MEMORY; END OF PROGRAM 
N50 G98 L5			$ BEGIN SUBROUTINE #5 DEFIN.
N60 G00 G90 X+2 Y-3		$ POSITION X-Y TO 1ST HOLE LOCN.
N70 Z+.1			$ DRILL = 0.100" ABOVE WORKPIECE 
N80 M03				$ SPINDLE ON 
N90 G83 P01 0 P02 -0.775 P03 -0.775 P04 0 P05 200
				$ DEFINE CANNED DRILL CYCLE.
N100 G79			$ DRILL 1ST HOLE
N100 G98 L6			$ LABEL (LOOP) START 
N120 G00 G91 X+0.5		$ MOVE INCR. X+ 1/2" 
N130 G79			$ DRILL 2ND HOLE 
N140 L6.4			$ DRILL 3RD - 6TH HOLES; LOOP END 
N150 G00 G90 X+0.0 Y+0.0 M25	$ RET. TO ORIGIN, QUILL UP
N160 G98 L0			$ END SUBR.; BACK TO MAIN PROGRAM

N9999 %560 G70			$ END OF FILE

Back to the top of this page

Last updated on Friday, January 14, 2005 by Bill Hemphill