## macro for rectangular array of holes

For training purpose, I have written a program to illustrate the use of a nested WHILE statement. Since I do not have a machining center (I do have a turning centre, but without live tools), will somebody be kind enough to test this program on 0iM control, and point out the mistakes, if any, before these are pointed out by my students!

This program (I am not calling it a macro because it is developed as a main program) can be used to make holes in a rectangular array. Any number of holes along X and Y directions can be specified. Pitch of the holes is fixed, but can be easily changed.

I know that there are better ways of doing the same thing, but here the purpose is to explain nesting.

O8013 (HOLE ARRAY USING A NESTED WHILE);
(#1 @ COUNTER1, HOLE COUNTER ALONG X);
(#2 @ COUNTER2, HOLE COUNTER ALONG Y);
(#3 @ TOTAL NUMBER OF HOLES ALONG X);
(#4 @ TOTAL NUMBER OF HOLES ALONG Y);
(#5 @ DEPTH OF HOLE);
;
#3 = 4;(Four holes along X-axis to be made)
#4 = 3;(Three holes along Y-axis to be made)
#5 = 5;(Depth of hole)
;
G21 G94 G90 G54;(Initial settings)
M06 T1;(Tool number 1 placed in the spindle)
M03 S1000;(Clockwise rpm 1000 starts)
G43 H01;(Tool length compensation invoked)
G00 X0 Y0 Z100;(Tool placed 100 mm above hole 1)
#1 = 1;
WHILE [#1 LE #3] DO 1;(The outer loop starts. It is executed once for every column of holes)
G90 G81 G99 Z-[ABS [#5]] R2 F30;(The use of ABS function makes the program work even if a negative value is specified for the depth of the hole)
#1 = #1 + 1;
#2 = 1;
WHILE [#2 LE [#4 – 1]] DO 2;(The inner loop starts. It makes the required number of holes in each column)
G91 G00 Y50;
G90 G81 G99 Z-[ABS [#5]] R2 F30;
#2 = #2 + 1;
DO 2;(The inner loop ends)
IF [#1 GT #3] GOTO 10;(Shift to the base of the next column of holes is not needed after the last column)
G91 G00 X20 Y-50;
N10;
DO 1;(The outer loop ends)
G80;(Canned cycle cancelled)
M05;(Spindle stops)
G90 G00 Z100;(Tool retracted to Z =100 mm)
M30;(Program end and control reset)