D01 END1 Macro How does it work?
Category : Macro
D01 END1 How does it work?
Someone said to me the other day to “why don’t you just do one”. In fact people often say this to me, even complete strangers. I was forced in the end to google it.
Anyway having researched it at length I can safely say it’s not a term of endearment. It actually means “fuck off”.
Now in macro programming it all takes on a different meaning. If you ever programmed computers back in the 1980’s then you’ll remember BASIC
(Beginner’s All-Purpose Symbolic Instruction Code)
This was a computer language very similar to Macro programming. Mmmmm not come far have we?
Anyway that’s where this language originates. Often known a Spaghetti programming. A pejorative phase to describe this type of programming used mainly because you can be hop skipping and jumping all over the program with GOTO statements and all sorts of confusing shit.
You have to be very disciplined with this type of programming and add loads of explanations. You must space the code out in neat chunks.
Although crude, macro programming has some great uses.
Oh and it adds real functionality to CNC programming.
D01 END1 What is it then?
This is a kind of loop and is best explained in an example. My example is a macro that will drill a grid of holes. The user states the spacing in X and the spacing in Y. Also the number of holes in each direction.
Now I know the smart arses are saying “fuck me, doesn’t he know there are cycles that already do this, yawn yawn”
Well actually I do.
I also know that the wheel was invented 3500 B.C. but the wheel can be used for demonstration which is what I’m about to do.
Demonstrate grids that is not wheels.
First of all this is just drilling one line of holes I’ll then go on to complicate the shit out of it by doing a grid.
First of all I drill one hole at X0 Y0, or whatever I want as my first position. The G202 has two parameters W and X.
W is the number of holes along the X axis.
X is the width between holes.
So this will give me 6 holes 10mm apart along the X axis.
I have aliased G202 to program O09011 which is my macro. Here’s how you do it in case you forgot.
This is program O9011
The line WHILE [#23 GT 1] DO1
Tells the control that as long as #23 is greater than 1 to go around the loop.
It’s now looking for END1 which corresponds to D01 and it whizzes around the loop.
You can have loads of these.
The END must match the D0.
It could be D02 & End2 the choice is yours. The D02 is just the name it’s nothing to do with how many times you go around the loop.
Just make sure you don’t get mixed up else you will have a nightmare trying to sort them out.
Each time it goes around the loop it checks the condition in the statement.
The next line moves X incrementally (G91) by the amount stored in #24 (this was the X value you put in the G202). It drills a hole because the G81, stated in the main program, is still active.
The control is then put back into G90 (Absolute) as a safety measure.
Now Lets Complicate Things
OK so you understood that?
Good now lets completely fuck it up.
D01 END1, This is the complete program.
First of all I drill one hole at X0 Y0, my first position same as above.
The G202 now has four parameters D,W and X, Y
D is the number of rows in Y.
W is the number of holes in X.
X is the width between holes along the X axis.
Y is the depth between holes along the Y axis.
So this should give me 6 holes 10mm apart in the X axis and 6 rows of holes 10mm apart in Y.
(A grid of holes)
More D0’s and Ends
Now we have D01 END1 inside D02 END2.
So……… the D01 END1 is the rows of holes across (X Axis).
The D02 END2 s the number of rows (Y Axis).
Now lets break it all down.
O09012 (Drill Grid of Holes)
G103 P1 (NO BLOCK LOOK AHEAD)
#100= #23 (Store W Value)
The line above puts #23 which was the W value into #100. This is because we are going to need it again when we go round the D01 END1 again. This loop reduces it down each time it goes around, so it needs to be restored.
WHILE [ #7 GT 0 ] DO2 (DO LOOP)
The line above is the condition that allows it to keep going around the loop as long as #7 is greater than zero.
WHILE [ #23 GT 1 ] DO1 (DO LOOP)
#23= #23 – 1 (COUNTER DECREASES BY ONE)
G91 X#24 (Drill a Hole)
The D01 END 1 above is one row of holes once the condition is satisfied it escapes the loop.
#23= #100 (Restore W Value)
Remember we saved #24 in #100. you need to set this back to it’s original value because the loop above reduced it down to zero.
#24= – #24 (Reverse X)
This is to make the X move in the opposite way to make the path zig-zag. This will make it toggle between plus and minus.
#7= #7 – 1 (COUNTER DECREASES BY ONE)
The above is the counter for the rows. Number of rows was in D (#7) so wee need to reduce this number as we go.
IF [ #7 EQ 0 ] GOTO1
This little bit of code above is for when we get to the last row of holes we don’t want the Y move as we have completed the grid.
G103 P0 (RESTORE BLOCK LOOK AHEAD)
It looks like this.
So there you have it. I hope you now have an understanding of how these loops work.
This kind of programming is notoriously difficult to get your head around. Once the penny drops it gets easier.
The problem is our brains are not too good at thinking about two things at the same time.
It’s called spaghetti programming for a reason.
My advice with all programming is to break the program down into small manageable chunks. Make simple little programs of each part and prove them till they work. You can the piece your program back together.
I hope you have enjoyed reading this article.
Thanks for watching and reading
If you have been affected by any of the issues in this post or need CNC Counselling then contact me.
Or call us
If you want to learn to program CNC Milling Machines
Look no further Contact CNC Training Centre