Macro Programming

MACRO

The macro language is a programming language that gives the CNC programmer the ability to write very flexible programs. This is done through the use of variables, mathematical expressions and program flow control statements. The macro language combined with standard G-code programming can create reusable programs much like canned cycles. These programs can do many useful things like custom pocketing or automatic tool measurement.

Macro variables

Variables are designated with the “#” symbol and are followed by a number or expression that designates the variable number. Variables can used as the value following any letter address except “N”.
Variables are classified into four different types.

Variable numberType of variableFunction
#0 Always null This variable is always null. No value can be assigned to this variable. It is not a value, it is nothing/empty/null.
#1 – #33 Local variables Local variables can only be used within a macro to hold data such as the results of operations. When the power is turned off, local variables are initialized to null. When a macro is called, arguments are assigned to local variables. These should only be used to pass values, not for calculations
#100 – #149 (#199) #500 – #531 (#999) Common VariablesCommon variables can be shared among different macro programs. When the power is turned off, variables #100 to #149 are initialized to null. Variables #500 to #531 hold data even when the power is turned off. As an option, common variables #150 to #199 and #532 to #999 are also available.
#1000 + System variables System variables are used to read and write a variety of NC data items such as the current position and tool compensation values.

Macro operations

The operations listed in the table below can be performed on variables. The expression to the right of the operator can contain constants and/or variables combined by a function or operator. Variables #j and #K in an expression can be replaced with a constant. Variables on the left can also be replaced with an expression.

operationFormatRemarks
Definition #i=#j  
Sum #i=#j+#k;  
Difference #i=#j–#k; 
Multiply#i=#j*#k; 
Divide#i=#j/#k; 
OR#i=#j OR #k; A logical operation is performed on binary numbers bit by bit. 
XOR#i=#j XOR #k; 
AND#i=#j AND #k; 
Conversion from BCD to BIN #i=BIN[#j]; Used for signal exchange to and from the PMC 
Conversion from BIN to BCD #i=BCD[#j]; 

Operation Descriptions

Definition – #i=#j

This is what’s used to transfer data from one variable to another. The left variable is where the result is.
So if #1=10 and #2=12
#1=#2
Both variables now equal 12.

Sum – #i=#j+#k

This is what’s used to add variables, or values on their own together.
So if #2=12 #1=#2+10
The value of #1 is now 22.

Difference – #i=#j-#k

This is what’s used to subtract variables, or values on their own together.
So if #2=12
#1=#2-10
The value of #1 is now 2.

Multiply – #i=#j*#k

This is what’s used to multiply variables, or values on their own together.
So if #2=12
#1=#2*10
The value of #1 is now 120.

Divide – #i=#j/#k

This is what’s used to divide variables, or values on their own together.
So if #2=20
#1=#2/10
The value of #1 is now 2.
All of the above can be put together using brackets to perform larger calculations. So if #1=2 and #2=5
#100=#1*[#2-3]
The value of #100 is now 4, because 2 x (5 – 3) = 4

Macro functions

functionFormatRemarks
Sine #i=SIN[#j]; An angle is specified in degrees. 90 degrees and 30 minutes is represented as 90.5 degrees. 
Arcsine #i=ASIN[#j]; 
Cosine #i=COS[#j]; 
Arccosine #i=ACOS[#j]; 
Tangent #i=TAN[#j]; 
Arctangent #i=ATAN[#j]/[#k]; 
Square root #i=SQRT[#j];  
Absolute value #i=ABS[#j]; 
Rounding off #i=ROUND[#j]; 
Rounding down #i=FIX[#j]; 
Rounding up #i=FUP[#j]; 
Natural logarithm #i=LN[#j]; 
Exponential function #i=EXP[#j]; 

Macro Statements

In addition to variables and expressions, the macro language uses a few macro statements that can control the flow of the program.
Here is a list of the macro statements:

  • IF – GOTO
  • IF – THEN
  • GOTO
  • WHILE – DO
  • DO- END
 You'll notice that a few of the statements are grouped together.  This is because the statements work together to determine the exact function performed. 

Leave a Reply