What's new
What's new

Macro Programming Fundamentals

Attached .PDF is a scan from an Meldas 50M operation manual regarding the "hidden" macros that are executed as canned cycles. The following are the macros.....

Code:
%
O120(CIRCLE-CUTTING    )
#42=#40-#41
G#39X#42Y0I#42/2
X0Y0I-#42
X-#42Y0I-#42/2
M99

O340(BOLT-HOLE-CIRCLE  )
#45=0
WHILE[#45LT[ABS[#43]]]DO1
#46=360*#45/#43+#42
#47=RND[#41*COS[#46]]#48=RND[#41*SIN[#46]]
X#39+#47Y#40+#48
#39=-#47#40=-#48#45=#45+1
END1
M99

O350(LINE-AT-ANGLE     )
#45=0
WHILE[#45LT#43]DO1
#46=#45*#41
#47=RND[#46*COS[#42]]#48=RND[#46*SIN[#42]]
X#39+#47Y#40+#48
#39=-#47#40=-#48#45=#45+1
END1
M99

O360(ARC               )
#45=0
WHILE[#45LT#43]DO1
#46=#45*#44+#42
#47=RND[#41*COS[#46]]#48=RND[#41*SIN[#46]]
X#39+#47Y#40+#48
#39=-#47#40=-#48#45=#45+1
END1
M99

O370(AUTO-TLM          )
G31Z#5F#3
IF[ROUND[ABS[#2-[##10*#11-#12]]]GT#8]GOTO1
IF[ROUND[##10*#11-#12]EQ#4]GOTO1
##9=##10-#12/#11-#2/#11+##9
#3003=#1
N2
M99
N1#3901=126

O379(GRID              )
#45=0#47=#39#48=#40
WHILE[#45LT#43]DO1
#46=1
X#47Y#48
WHILE[#46LT#44]DO2
X#41
#46=#46+1
END2
#47=0#48=#42#41=-#41#45=#45+1
END1
M99

O810(DRILL             )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
#3003=#8
G0Z-#3-#2,I#23
N1M99

O820(COUNTER-BORING    )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
G4P#4
#3003=#8
G0Z-#3-#2,I#23
N1M99

O830(DEEP-DRILL        )
G.1
IF[#30]GOTO2
#29=#11#28=0
Z#2G#6H#7
#2=##5#3003=#8OR1
DO1
#28=#28-#11#26=-#28-#29
Z#26
IF[ABS[#28]GE[ABS[#3]]]GOTO1
G1Z#29
G0Z#28
#29=#11+#14
END1
N1G1Z#3-#26
#3003=#8
G0Z-#3-#2,I#23
N2M99

O831(STEP-CYCLE        )
G.1
IF[#30]GOTO2
#29=0#28=#11
Z#2G#6H#7
#2=##5#3003=#8OR1
DO1
#29=#29+#11
IF[ABS[#29]GE[ABS[#3]]]GOTO1
G1Z#28
G4P#4
G0Z-#14
#28=#11+#14
END1
N1G1Z#3-#29+#28
G4P#4
#3003=#8
G0Z-#3-#2,I#23
N2M99

O840(TAP-CYCLE         )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1#3004=#9OR3
G1Z#3
G4P#4
M4
#3900=1
G1Z-#3
#3004=#9
G4P#4
M3
#3003=#8
G0Z-#2,I#23
N1M99

O841(COUNTER-TAP-CYCLE )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1#3004=#9OR3
G1Z#3
G4P#4
M3
#3900=1
Z-#3
#3004=#9
G4P#4
M4
#3003=#8
G0Z-#2,I#23
N1M99

O850(BORING-1          )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
#3003=#8
Z-#3
G0Z-#2,I#23
N1M99

O860(BORING-2          )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
G4P#4
M5
G0Z-#3-#2
#3003=#8
M3
N1M99

O861(FINE-BORING       )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
M19
X#12Y#13
G0Z-#3-#2
#3003=#8
X-#12Y-#13
M3
N1M99

O870(BACK-BORING       )
G.1
IF[#30]GOTO1
#3003=#8OR1
M19
X#12Y#13
#3003=#8
Z#2G#6H#7
#3003=#8OR1
G1X-#12Y-#13
#3003=#8
M3
#3003=#8OR1
Z#3
M19
G0X#12Y#13
Z-#2-#3
#3003=#8
X-#12Y-#13
M3
N1M99

O880(BORING-3          )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
G4P#4
#3003=#8
M5
#3003=#8OR1
G0Z-#3-#2
#3003=#8
M3
N1M99

O890(BORING-4          )
G.1
IF[#30]GOTO1
Z#2G#6H#7
#2=##5#3003=#8OR1
G1Z#3
G4P#4
#3003=#8
Z-#3
G0Z-#2,I#23
N1M99
%

There is some hidden information that links these programs to the corresponding G codes that activate them. None of the "standard" parameters for calling a macro by G code reference these numbers. Additionally, the program numbers assigned to these macros are not reserved by the system and are available for user CNC programs. Notice the format of the macro instructions appears as if there is some form of "shorthand" being used. I suspect G.1 is used to invoke a modal macro execution mode similar to G66.

I've never modified any of these as they work fine for my needs. Per the instructions in the attachment, one could edit these if a slightly different behavior was desired. Should test that sometime.
 

Attachments

  • Meldas M50 fixed cycles.pdf
    135.7 KB · Views: 5
Last edited:
I have started writing a macro for the chip break threading thing, I went to town with some bells and whistles and it will have about 15 possible arguments as a result of that (most of them have a default value and are only optionally used). Last night I had a short power outage and my laptop battery was dead so I lost about 1-2h of work because I didn't save frequently enough. I will probably get it tested tonight.

The chip breaking itself will be simpler than Sandvik has but it will have a lot of other stuff to make it somewhat more foolproof and easy to program.

Talking about cutting a complete thread with chip breaking, optionally also finish cutting the crest with the threading tool and coming back to clean the burr from cutting the crest, all with a single line of code, needing absolutely minimal input and no need to manually calculate or check the finish depth either.

Failure is also still an option at this point of course as this is only my second macro I'm practicing on.
 
Last edited:
My first macro was a polygon turning macro for a 2 axis lathe (with no C-axis either), I could share it as well if someone's interested.
Here it's in action

The shape of those polygons is not accurate, although it could be made a little bit more accurate by putting more G32 segments with a different feed I'm not doing it at this point.
 
Macro B does not accept two consecutive ##. It has to be in the format #[#9]
This is why I said it appears that this is some kind of “shorthand” form of macro language. Possibly unique to the Meldas canned cycle functionality.
This also may not work.
Macro B does not consider TRUE and FALSE equivalent to 1 and 0, respectively, as erroneously mentioned in some books on Macro B.
Not sure if you understood that these are as downloaded from the control after enabling the parameter that unlocks the canned cycle macros. I assure you that they work.
 
I just tested the chip break threading macro, it needs a few tweaks but it worked already. Once it's ready I will probably post a new thread here for everyone to dump their macro programs on that they're willing to share. I have a few lathe macros to do still, all using G32 threading for some different creative uses lol

And I need my memory chips to arrive, the macro already took like 1/3 to 1/2 of the stock memory of a Fanuc 10T :D
 
It might take a few days until I have time to finish it. There are just some small math issues I need to look at as the finish cut was too deep when I tested it. I post it when it's ready.

Next one after this will probably be an eccentric turning macro, also with G32 threading of course. Then one to make a circular profile thread with a round insert tool smaller than the thread profile, and so on. That one is something I actually need.
 
Starting to look pretty good, still need to fine tune some of the formulas soon. It does a wawy cut and a straight cut always the same way, otherwise the macro would get way too long and complicated. It does reduced infeed with single side cut as the only infeed method and the thread finishing depth is calculated by the macro from nominal diameter, pitch, TNR, thread angle and so on. So that you wouldn't even need to break out the charts and calculators at all to make a thread...

I will probably not use this even myself much but I will make another macro that calculates the values similarly for G76 from the nominal diameter and pitch and everything and that one will be used for sure.



 
this may have been mentioned already in this thread but i think it bears repeating if it has.
As someone who has worked with some very basic macros I have found myself being asked on a few occasions to edit a macro created by a co worker or a former co worker. Every macro should include as much man readable code in it as reasonable to help decipher what is going on. If it is an extensive macro a text file also helps.
If I were the owner of a shop where macros are used I would require that documentation for every macro......no documentation?....no macro
 
this may have been mentioned already in this thread but i think it bears repeating if it has.
As someone who has worked with some very basic macros I have found myself being asked on a few occasions to edit a macro created by a co worker or a former co worker. Every macro should include as much man readable code in it as reasonable to help decipher what is going on. If it is an extensive macro a text file also helps.
If I were the owner of a shop where macros are used I would require that documentation for every macro......no documentation?....no macro
And, the documentation should include the algorithm also. Still better if it is in the form of a flow chart.
 
I have a bad habit of just making the stuff up as I go. Which of course then results that I probably don't understand even myself what I did if enough time passes. Good point. I tend to utilize flow charts and such only once the stuff becomes so complicated that it's impossible for me to comprehend without using those tools.
 
If you are writing a tool-change macro, no algorithm/flow chart needed.
But, for example, if you are writing a macro for pocket machining, the logic must be very clear. This would need a algorithm/flow chart which are never vague.
 
I only now realized the threading cycle itself needs to be as universal as possible and the possible additional functions need to be their own macro which then calls the cycle. I will redo it completely but I don't need to start from scratch.

The memory upgrade for my lathe is now up and running, 24 times more memory than there was originally so the macros won't be filling it now. Cost about 20€ to buy the chips from China vs. Memex 700€.
 
Would it be possible to remove 2 first digits off 4 digit H codes as they are called (using macro b) if I want to use a 4 digit code for tools? Some CAM software doesn't allow a different offset number than the tool number.

It should be like for example T9028 and H28. The first digit determines tool size, 0 is small, 1-8 medium and 9 are large. Small and large tools can go next to each other but medium stays 1 pot away from the large ones.

It's needed only for this tool size discrimination in the turret, I have now one big face mill that can only have very small tools next to it. I can put a different number for tool and offset in Confusion 360 but if I want to use a software that can't do it there would be an issue.

I haven't tried but I think extending the T code would be much easier if that kind of function can be even made. Just add 1000 or 9000 to the tool number called but it would require a separate list of small and big tools, medium could be default
 
Last edited:
Probably more elegant methods but a few IF statements ought to do it…..

IF[#20GE9001]GOTO9000
Another test….

N9000 #20=[#20-9000]

Then your code can use H#20

I’ve not plugged this into a machine but seems like it’s doable.
 
Would it be possible to remove 2 first digits off 4 digit H codes as they are called (using macro b) if I want to use a 4 digit code for tools? Some CAM software doesn't allow a different offset number than the tool number.

Kevin's solution would be the simplest when you already know what the two most significant numbers in the 4 digit string are. For example, in T9028, 90 would be and therefore, the number to use in the comparison will be 9001 and 9000 used to subtract from your initial number.

However, when none of the numbers are known but its always the case that you need to obtain the two least significant numbers from any number of digits greater than a two digit string, the following will work: It works also when there are are only two digits in the string, but in that case, no calculation is required to extract the two digits.

If you have a dedicated Tool Change Macro, you could incorporate the following in that.
Method 1
#1 = #20 (or #4120), which in this example is 9028

#2 = #1 / 100
#3 = FIX[#2]
#4 =FIX[[ #2 - #3] * 100] (#4 = 28)

Another very simple way if the initial number is always going to be 4 digits is as follows:
Method 2
#1 = #20 (or #4120), which in this example is 9028
#1 = #1 MOD 1000 (#1 = 28)
or
#1 = #20 MOD 1000 (#1 = 28)

In the two above Method examples, the first will extract the two least significant numbers from any string of 2 digits and greater. The second example will extract all right most numbers from 0 to 999 from a four digit string. Accordingly, if the three right most numbers may be greater than 099, but you only wanted the two right most numbers, then a second step would be required as in the following example where the initial number is 9128.
(#20 (or #4120) = 9128)
#1 = #20 MOD 1000 (#1 = 128)
#1 = #1 MOD 100 (#1 = 28)

Regards,

Bill
 
Last edited:








 
Back
Top