Introduction to Custom
Macro Programming
An Overview of Macro Variable
Programming Function
and Practices for CNC Machines
Table Of Contents
Introduction to Macro Programming 3
Types of Macro Variables 4
Local Variables 4
Common Variables 6
Some example uses of Common Variables 7
Referencing Variables 9
System Variables 10
System variables for tool compensation 11
System Variables for Alarms 12
System Variables for Time 12
Other System Variables 12
Message Variable 13
Modal Variables 14
Current Position Variables 15
Arithmetic and Logical Operation 16
Priority of Operations 17
Control Operation Statements 18
Modal Macro Call 20
Macro Call by G-code or M-code 21
Macro Program Examples 22
IMPORTANT:
The information used within this manual is used for the purpose of instruction in
the practical use and basic understanding of Macro Programming. It is
necessary that you consult your specific machine’s documentation to have a
thorough understanding of the system of operation. As some systems differ, not
all of the applications used herein will be applicable. Different machine control
options and/or systems used by the machine tool builder may affect the use of
this information on your machine.
2
Introduction to Macro Programming
A macro program is a program which contains both NC language and a form of computer
language. A macro program can be created to perform various functions, such as Customized
Canned Cycles, Auto Centering and Measuring, and many other special needs of each machine
user. One universal program can be created to accommodate a variety of part sizes and shapes,
or specific functions can be included within an NC program to be executed only when read.
Macro programs are extremely versatile, yet can also be very complicated. The defining
difference is the amount and types of variables used within the macro program.
In order to utilize Macro programming, the machine control must have the Macro option turned
on. You will need to verify this with the machine builder in advance. If your machine control
does not have the Macro option, most likely you will receive an error at the time of program
execution. Additionally, there are varying levels of macro availability depending on options
available and the make/model of the machine tool control.
Macro programs are traditionally called using the G65 P__ statement. It is also possible to
execute macro programs using G codes, M codes, and also the M98 P__ statement. Macro
variables can exist within any main program at any time and be edited by assignment in the
program, or by an operator on a designated input screen of the control.
All macros are specified by the “#” sign in front of the variable number. Only numerical
characters may follow the “#” sign.
Example: #1, #101, #520
Macros may also be specified within or as an expression. In such a case, the expression must be
enclosed in brackets.
Example: #[#1+#2-12]
X[#7+[#3*2]]
A Macro variable having no value is said to be null or vacant. The variable assignment #0 is the
only null variable and cannot be assigned. Some controls will designate a null or vacant variable
by specifying “DATA EMPTY”. To ‘empty’ a variable, it must be assigned to equal the null
variable, #0:
#510=#0 <vacant>
#510=0 <value of zero, not vacant>
Macros have varying uses as a substitutional variable, although there are some restrictions.
Variables cannot be specified in any of the following ways:
O#1 (as program number)
/#2 G0 X1. (as stand alone variable)
N#3 (as block or sequence number)
3
Types of Macro Variables
There are three basic types of macro variables:
1. Local Variables #1 through #33
2. Common Variables #100 through #149; and #500 through #531 (#199; #999 opt)
3. System Variables #1000 ~ (4 digit references)
Local Variables
Local variables are generally used in a program to read a value into a register, from a macro call
statement.
There are 33 Local Variables available to use. Local variables are specified as either Argument I
or Argument II, and depend on the nature of specification in the macro execution call. At the
time of assignment in the Macro Call (G65 Pxxxx, etc.), the system automatically determines
which specification is used based on the addresses which are assigned.
In the Argument I specification, only 21 variables can be specified in a macro call line.
ARGUMENT I SPECIFICATION:
Address Variable Address Variable Address Variable
A #1 I #4 T #20
B #2 J #5 U #21
C #3 K #6 V #22
D #7 M #13 W #23
E #8 Q #17 X #24
F #9 R #18 Y #25
H #11 S #19 Z #26
Example: G65 P1000 A4. S2. D0.125 – Argument specification I is used
In this call statement, the macro program 1000 is used and the values of #1, #19, and #7 are
set to the values of 4.0, 2.0, and 0.125 respectively by alpha-numeric assignment. These values
would then be used within the macro program to perform the necessary order of operations, or
substitutions as needed.
Use this type of macro specification when you are writing a program and you want to use related
or common letter assignments to represent familiar values. (i.e. – F=feed, D=diameter/distance)
4
In the Argument II specification, all 33 variables can be specified in a macro call line. The
difference here is that each specification must be assigned in alphabetical and sequential order.
ARGUMENT II SPECIFICATION:
Address Variable Address Variable Address Variable
A #1 K3 #12 J7 #23
B #2 I4 #13 K7 #24
C #3 J4 #14 I8 #25
I1 #4 K4 #15 J8 #26
J1 #5 I5 #16 K8 #27
K1 #6 J5 #17 I9 #28
I2 #7 K5 #18 J9 #29
J2 #8 I6 #19 K9 #30
K2 #9 J6 #20 I10 #31
I3 #10 K6 #21 J10 #32
J3 #11 I7 #22 K10 #33
Example: G65 P1000 A4. I7.0 I-3.0 – Argument II specification is used
In this call statement, the macro program 1000 is used and the values of #1, #4, and #7 are set
to the values of 4.0, 7.0, and –3.0 respectively. These values would then be used within the
macro program to perform the necessary order of operations.
It is important to note that when values are assigned to the same variable by way of different
letter address specification, the latter value will be valid, and the previous value is over written.
Example: G65 P1000 A4. B2. I-3.0 I4.0 D5.0
In this call statement, the values for I1 and D both are represented by #7, therefore after
execution of this block #7 would equal 5.0000.
5
Common Variables
#100 - #149 (#199) and #500 - #531 (#999)
Common variables can be shared among different macro programs. When the power is turned
off, variables #100 - #149 are initialized to null. Variables #500 - #531 will continue to hold
data even after power off.
Mostly these variables are used in macro programs or as direct variables in a main program.
Data cannot be directly input into these variables by the macro call line (G65 P__). Data is input
into these registers only by direct assignment in the program, or through the Macro access page
on the machine control.
Variables #500 - #531 typically are used to store permanent data for probes, robots, or other
auxiliary equipment. Be sure to document the usage of these variables as unexpected changes
can be damaging to the machines or accompanying equipment. Random selection of a current,
in-use variable can have unexpected consequences.
In the case of power-off, these variables (#500 – up) retain their values and can only be cleared
by assigning or declaring them vacant or null. This is useful when data stored needs to be used
by multiple programs or machine functions.
As an option, additional macro variables may be added up to #199 and up to #999. This option
varies by control model and amount of memory available.
6
Some example uses of Common Variables
Common variables can be used for multiple operations and common uses within any existing CNC
program. Listed below are some examples:
>> Quick feedrate adjustment; by changing the variable, the control will calculate and adjust
feed changes as needed without editing multiple lines:
#100=10.0;
G1 Z-.03 F162.38
X3.8675 F#100
G2 X-3.4675 Y0 I-3.6675 J0 F[#100/5] (feedrate changed to 20% = 2)
X3.0675 Y0 I3.2675 J0
X-2.6675 Y0 I-2.8675 J0 F[#100/2] (feedrate changed to 50% = 5)
X2.2675 Y0 I2.4675 J0
X-1.8675 Y0 I-2.0675 J0 F#100 (feedrate changed to 100% = 10)
X1.4675 Y0 I1.6675 J0
X1.4675 Y0 I-1.4675 J0
G1 X-3.2675
Z.22 F162.38
>> Part counter for operations or other function that can later be indexed or checked to perform
additional operations (i.e. – bar pull, bar change, operator message, etc.):
#500 = [#500+1] (increments up by one each time)
There are countless uses for macro variables within a CNC program. It is important to bear in
mind that using expressions, or assignments just for the sake of using them, will only complicate
execution and understanding of programming for those who are not familiar with macro. When
there is an opportunity to use macro to simplify repetitive tasks or implement flexibility for part
production, it can be a tremendous help and empower machine operators to get their job done.
Over utilization of macro in CNC programming is of no value to the programmer, the operator, or
the company, therefore use with caution and plan carefully. Since macro expressions may
determine a variety of outcomes when used, each specific possibility should be tested to verify
use and accuracy of each macro variable (i.e. – endless loops, over-travel, machine damage).
7
Macro Usage of Decimal Point
Understanding the proper use of decimals when programming and/or assigning macro variables
is critical to proper operation of the macro program. There are two basic rules that clearly define
the relationship:
1. When a variable value is defined in a program, the decimal point can be omitted.
2. When a variable value is defined in a macro call statement, the decimal point must be used.
Use of the decimal point is important when assigning variables. For example, if you assign the
value A4 in a macro call statement, then the value of 0.0004 is input into the #1 register.
G65 P1110 A4 = #1 = 0.0004
G65 P1110 A4. = #1 = 4.0000
Example:
When #1=123 is defined, the actual value for variable #1 is 123.0000. However, if the variable
#1 is defined within the macro call statement (see argument 1 specification) as in G65 P___
A123, the actual value for variable #1 would be 0.0123.
It is always best to use the decimal point in every case to avoid having to search for, and find
errors caused by improper usage.
Look at the example expressions below. Write the correct output that will seen by the machine
tool based on the macro expression for each variable assignment:
Expression: Result:
#21 = 1.0762 #21 = ___________________________
#19 = 0135 #19 = ___________________________
G65 P1004 A23 S2. D14 P2000 #1 = ___________________________
(*look at Arg I spec*)
#19 = ___________________________
#7 = ___________________________
#1 = 0.000 #1 = ___________________________
#600 = 5 #600 = __________________________
8
Referencing Variables
To reference the value of a variable in a program, specify a word address followed by the
variable number. When an expression is used to specify a variable, enclose the expression in
brackets.
Example: G0 X#1 Z#2 F#3
G0 Z[#2+0.1]
When an undefined variable is referenced, the variable is ignored up to an address word. For
example, if #1=0, and #2=<vacant>, then execution of G00 X#1 Z#2 actually results in G00 X0.
When #1 is <vacant> When #1 = 0
G00 G90 X10. Y#1 G00 G90 X10. Y#1
ACTUAL = G00 G90 X10. ACTUAL = G00 G90 X10. Y0.
It is important to understand the difference between ‘vacant’ and ‘zero’. Since ‘vacant’ means
literally there is not any assignment, the value of a vacant variable is “EMPTY”. When a variable
has “0.000” value, it still has an assignment value, and is not vacant.
Sometimes it is necessary to declare or assign a macro variable to ‘null’ or ‘vacant’ so that there
is no compounding of calculations, or mis-assignment within an expression.
9
System Variables
System variables can be used to read and write internal NC data such as tool compensation
values and/or current position data. Note, however, that some system variables are read-only.
System variables are essential for automation and general-purpose program development.
In addition to System variables, there are also System constants that can be utilized within macro
programming structures. Unlike variables however, constants are unchanging.
A system constant is specified by its variable number, but it may also be specified by its
predetermined system name. A system constant name will always begin with an underscore
character ( _ ), followed by up to seven uppercase letters, numbers, or underscores.
Example: [#_DATE] – system date ([Link])
[#_PI] – numerical constant for PI; 3.1415922~
[#_OFSW(n)] – tool compensation wear value
In some systems use of variable names are interchangeable with system numbers. System
names can even be assigned if necessary. In instances where this level of macro programming is
necessary, always refer to the control manuals provided with your machine in order to develop a
thorough understanding of proper uses, declarations, and assignments.
Some variables can by used to exchange interface signals between the NC and external or other
devices.
#1000 - #1015; Used to send a 16-bit signal from the PMC to a custom macro. These
variables are used to read a signal bit by bit.
#1032 Used to read all 16 bits of a signal at one time
#1100 - #1115; Used to send a 16-bit signal from the custom macro to the PMC. These
variables are used to read a signal bit by bit.
#1132 Used to send/write all 16 bits of a signal at one time.
In order to use these variables, a thorough understanding of the connections of your external
equipment is required. Always consult the manufacturer prior to connection so as to avoid any
damage or unplanned modifications to your machine and/or external devices.
10
System variables for tool compensation
On various CNC control platforms, and depending on specific settings, there may be some
differences in these values from machine to machine. Typically, tool compensation memory is
controlled by an NC parameter setting, and is determined by the amount of memory and format
of tool offsets used.
Some older systems use a different offset table value for tool length than was used for tool
diameter values. In these systems you would have H1, D41 etc. Other systems use the same
table offset value for tool length as is used for diameter; H1, D1 etc. Always test the result
values of use relating to tool offsets prior to using in execution of programs. Your machine
control manuals will list the type of tool compensation memory used, or specify the correct
parameter where you can determine prior to use. (FANUC #6000.3 – typically 1, 2, or 0)
There are varying differences from machine platform that also must be considered when using
macro values to update/edit tool offsets. Lathe tooling orientation is vastly different from Milling
platforms (i.e. – corner rad, corner position/virtual tip position, etc.).
#2001 - #2200; Used for tool compensation wear values (up to 200 offsets)
#2201 - #2400; Used for tool compensation H-code values (geometry)
#12001 - #12999 Used for tool compensation D-code values (wear)
#13001 - #13999 Used for tool compensation D-code values (geometry)
11
System Variables for Alarms
When a value from 0 to 200 is assigned to variable #3000, the CNC stops with an alarm. After
an expression an alarm message no longer than 26 characters can be described. The CRT screen
will display alarm numbers by adding 3000 to the value in #3000 along with an alarm message.
Example: #3000=9 (Tool number not specified) will display “3009 Tool number
not specified” on the CRT.
System Variables for Time
#3001 This read/write variable functions as a timer that counts in milliseconds increments at all
times. When the power is turned off, the value of this variable is reset to 0.
#3002 This read/write variable functions as a timer that counts in 1-hour increments only when
the cycle start lamp is on. This timer preserves its value even when the power is turned
off.
#3011 This read-only variable can be used to read the current date (year/month/day).
Information is converted into an apparent decimal number. For example, March, 28,
2013 is represented as 20130328.
#3012 This read-only variable can be used to read the current time (hours/minutes/seconds).
This information is converted to an apparent decimal number, using 24 hour clock
specification. For example, 34:56 after 3pm is represented as 153456.
Other System Variables
#3901 This read/write variable can be used to read the total number of parts
#3902 This read/write variable can be used to read the number of required parts when specified
12
Message Variable
#3006 This variable allows a message of up to 26 characters, which is enclosed by parenthesis,
to be displayed on the external operator message screen. At execution, the program
stops and the corresponding message is displayed on the operator message screen.
Example #3006=1 (Gauge part I.D.) Displays “(Gauge part I.D.)”
#3006=2 (Move Clamps) Displays “(Move Clamps)
When this variable is read the machine is placed into a “feed hold” mode, and normal program
execution can be resumed by pressing the cycle start button. Use this option whenever you need
to provide information to the operator. There is, however, no way to ensure that the machine is
not re-started when only placed in message state.
In order for the operator to have interactive operation with the machine, be sure that all safety
conditions are met concerning your machine tool for door open, reaching into the machine, etc.,
prior to continuation of automatic operation.
13
Modal Variables
System variables in the #4000 range are used to specify current modal information. Each
variable represents values which correspond to those modal commands in their specific group.
See table below.
Variable Function
#4001 Group (01)
#4002 Group (02)
#4003 Group (03)
#4004 Group (04)
#4005 Group (05)
#4006 Group (06)
#4007 Group (07)
#4008 Group (08)
#4009 Group (09)
#4010 Group (10)
#4011 Group (11)
#4012 Group (12)
#4014 Group (14)
#4015 Group (15)
#4016 Group (16)
#4022 Group (22)
#4109 F code
#4113 M code
#4114 Sequence Number
#4115 Program Number
#4119 S code
#4120 T code
When a modal information variable is read corresponding to a G code which cannot be used, an
alarm is issued. Status of the value of the assignment variable will correspond to the value of the
active code in that group. For example, Group 1 G-codes typically are G01, G02, G03, or G04.
Example: #500=#4001; In G01 mode #500 = 1
14
Current Position Variables
Current position values are available to be read but cannot be written. These system variables
contain position information with respect to the number of axes of the machine. For example,
for a lathe, the first axis would be X, the second axis would be Z. For a Vertical Mill, the first axis
would be X, the second axis would by Y.
Variable Position Information Coordinate Tool Read operation
System Compensation during movement
Value
#5001 - #5008 Block End Point Workpiece Not Included Enabled
Coordinate System
#5021 - #5028 Current Position Machine Coordinate Included Disabled
System
#5041 - #5048 Current Position Workpiece Included
Coordinate System
#5061 - #5068 Skip Signal Position WCS Included Enabled
#5081 - #5082 Tool Offset Value Disabled
#5101 - #5108 Deviated Servo Position
Variable Function
#5201 First-axis external workpiece zero point offset value
:
#5208 Eighth-axis external workpiece zero point offset value
#5221 First-axis G54 workpiece zero point offset value
:
#5228 Eighth-axis G54 workpiece zero point offset value
#5241 First-axis G55 workpiece zero point offset value
:
#5248 Eighth-axis G55 workpiece zero point offset value
#5261 First-axis G56 workpiece zero point offset value
:
#5268 Eighth-axis G56 workpiece zero point offset value
#5281 First-axis G57 workpiece zero point offset value
:
#5288 Eighth-axis G57 workpiece zero point offset value
#5301 First-axis G58 workpiece zero point offset value
:
#5308 Eighth-axis G58 workpiece zero point offset value
#5321 First-axis G59 workpiece zero point offset value
:
#5328 Eighth-axis G59 workpiece zero point offset value
15
Arithmetic and Logical Operation
The operations listed below can be performed with 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.
Angles are expressed in units of degrees. For example, 90 degrees 30 minutes would be
represented as 90.5 degrees.
Function Format Remarks
Definition #i = #j
Sum #i = #j + #k
Difference #i = #j - #k
Product #i = #j * #k
Quotient #i = #j / #k
Sine #i = SIN[#j] An angle is specified in
degrees. 90 degrees and 30
Arc sine #i = ASIN[#j] minutes is represented as 90.5
degrees.
Cosine #i = COS[#j]
Arc cosine #i = ACOS[#j]
Tangent #i = TAN[#j]
Arc tangent #i = ATAN[#j]
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]
OR #i = #j OR #k A logical operation is
performed on binary numbers
XOR #i = #j XOR #k bit by bit.
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]
16
Priority of Operations
In macro programming expressions which are not included within brackets […] are executed
under the following rule of operations:
1. Functions
2. Multiplication or Division
3. Addition or Subtraction
Example: #1=#2+#3*SIN[#4]
Operation priority =SIN[#4]
=#3 * [result]
=#2 + [result]
To control and/or change the normal priority of operations within a macro expression, use
brackets. Brackets can be used to a depth of 5 levels including the brackets used to enclose a
function. When a depth of 5 levels is exceeded, an alarm occurs.
Example #1=SIN[[[#2+#3]*#4+#5]*#6]
Operation priority =#2+#3
=(result)*#4
=(result)+#5
=(result)*#6
=SIN(result)
It is always a good idea to test your results in a spreadsheet or with a calculator off-line so that
you will be able to understand how you machine control is calculating. By testing the different
answers or results, you will be better prepared to adjust your math formula for the desired result.
17
Control Operation Statements
In a program, the flow of control can be changed using control statements. These instructions
help dictate the actions of the macro program. There are several control commands, which are
available for use within macro programs:
GOTO This command is an unconditional branch statement. It is specified by GOTOn
where “n” is a specified sequence number in the program.
IF This command is a conditional branch statement which must be tested in order
to determine proper execution.
WHILE This statement is a repetition statement.
GOTO is expressed within a program whenever the program needs to skip or jump to another
section. Since it is unconditional, each time it is used within a program, it is executed.
IF allows the same function, however, a certain condition must be satisfied in order to be
executed. Once the condition or expression is tested, the result is based on the following control
instruction.
Example: IF[#1EQ0.0]GOTO99 IF[#1EQ#2]THEN #3=0.0
In order to test certain conditions, the following conditional expressions can be used:
EQ Equal to (=)
NE Not equal to
GT Greater than (>)
GE Greater than or equal to
LT Less than (<)
LE Less than or equal to
Repetition is controlled by the WHILE statement. Whenever the WHILE statement is issued, an
action or set of actions can continually occur until that condition is met. The actions are specified
in between the DO and END statements. During operation of the WHILE statement, the
conditional expression is continually tested until satisfied. After each successive test, the
operations between DO and END are executed, until the conditional expression tests true.
Example: WHILE[#1LT10]DO1 (condition of #1 tested)
<processing>
#1=#1+1
END1
When using the WHILE statement, the identification numbers after DO and END statements are
for specifying the range of execution. The numbers 1, 2, and 3 can be used. When a number
other than 1, 2, and 3 is used, and alarm will occur.
18
Multiple use of the WHILE_DO statements is called nesting. The following information
demonstrates the limitations imposed.
1. The identification numbers (1 to 3) can 3. DO loops can be nested to a maximum
be used as many times as required. depth of three levels.
WHILE […] DO1; WHILE […] DO1;
<processing> :
END1; WHILE […] DO2;
: :
WHILE […] DO1; WHILE […] DO3;
<processing> <processing>
END1; END3;
:
2. DO ranges cannot overlap. END2;
WHILE […] DO1; :
<processing> END1;
WHILE[…] DO2;
: 4. Control can be transferred to the
END1; outside of a loop.
<processing> WHILE […] DO1;
END2; IF […] GOTOn;
END1;
Nn
Be careful to avoid endless or infinite loops. When DO is specified without specifying the WHILE
test condition statement, and infinite loop ranging from DO to END is produced. The program
will never stop running.
External Output Commands
The following macro commands are available and are referred to as external output commands.
They are provided to output variable values and characters through the input/output interface.
POPEN = Specifies data output connection; establishes a connection to an external device
BPRINT = Outputs data values in binary
DPRINT = Outputs characters and each digit in the value of a variable
PCLOS = Closes the data output connection; ends communication to external device
Once a POPEN is commanded, it remains active until PCLOS is read. These commands require
special formatting for correct output. BPRINT/DPRINT commands must be enclosed in square
brackets.
DPRINT [X#2 [53] Y#5 [53]] (character, variable, nmb integer digits, nmb decimal digits )
“X” , “#2” , “5 before decimal”, “3 after decimal”
#2= 128.47398 - would output 128.474;
#5= 91.2 - would output as 91.200;
19
Modal Macro Call
In some instances it is necessary for a simple macro to be executed repeatedly and at different
locations along a work piece. In these cases, the macro call command would be G66 Pxxxx.
Once G66 is issued the modal macro call, that macro will be called after each block specifying
movement along the machine axes. This will continue until the cancel command G67 is issued.
Whenever a number of repetitions of the macro is required, specify the number of repetitions (1
to 9999) with the address L. Nesting is also allowed up to a depth of 4 levels, not including sub
program calls.
The G67 Cancel command must be issued in a block by itself.
Whenever using the Modal Macro Call function, there are some restrictions that effect the usage
of this modal command:
1. In a G66 block, no macro variables can be called (#100), only argument addresses
2. G66 must be specified before any arguments
3. No macros can be called in a block which contains a code such as M-functions which do not
involve movement along an axis
4. Local variables only can be set in G66 block.
5. Local variables are not set each time a modal call is performed.
Examples for the use of the Modal macro call include Thread milling, custom drill/ream/bore
cycles, etc.
Program Example – Lathe;
O0003; G00 X12.0 Z1.5 M5;
G00 G55 X10. Z1.0; G28 U0 W0.;
G97 S1000 M03; M30;
G66 P9910 U5. F0.006;
G00 Z0.8; Macro Program;
Z0.6; O9910;
Z0.2; G01 U-#21 F#9;
Z0.0; G00 U#21;
G67; M99;
Macro Call by G-code or M-code
Repetitive functions or custom macro programs can be called by using a specified G-code or M-
code designation. When conditions exist where some specific operations or movements would
need to be performed, a quick way to ensure this repetition is to connect the commands to an
existing G-code or M-code that is often used. It is best not to use pre-existing commands for this
unless very specific detail is given to application and purpose.
Example: Tool change macro program
Command: M06
Operation: When M06 or M6 is designated within the CNC program, the macro
program is called and executes each time.
O9020 (TOOL CHG MACRO)
#14=#4114(REC SEQ NO)
#15=#4001(REC G1 G0)
#16=#4003(REC G90 G91)
IF[#1000EQ1]GOTO50(HEAD=T)
IF[#3010EQ-1]GOTO50(SIMULATION SKIP)
IF[#1007EQ1]GOTO40
N10G80G40
N30G91G30Z0.M233M19
N40M06
N50
N#14G#15G#16
M99
Macro calls by G or M-code are enabled by specifying the correct program call for a designated
G-code or M-code word inside the NC parameters.
G-code calls:
Parameter: Program number:
6050~6059 9010~9019 respectively
M-code calls:
Parameter: Program number:
6080~6089 9020~9029 respectively
Macro Program Examples
Look at the lathe drilling-cycle sample macro program. Which argument specification is defined
in the macro call?
Calling format:
G65 P9100 Zz (Ww) Kk Ff;
Z: Hole depth
W: Hole depth (incremental specification)
K: Cutting amount per cycle
F: Cutting feedrate
Macro program:
O9100
#1=0;....................................................Clear the data for the depth of the current hole
#2=0;................................................Clear the data for the depth of the preceding hole
IF[#23NE#0]GOTO1;........................................If incremental programming, jump to N1
IF[#26EQ#0]GOTO8;..............................If neither Z nor W is programmed, error occurs
#23=#5042-#26;.............................................................Calculates the depth of a hole
N1;
#1=#1+#6;......................................................Calculates the depth of the current hole
IF[#1LE#23]GOTO2;
#1=#23;...........................................................Clamps at the depth of the current hole
N2;
G00 W-#2;...........................................................Moves tool to depth of preceding hole
G01 W-[#1-#2] F#9;................................................................................Drills the hole
G00 W#1;.....................................................................Moves tool to drilling start point
IF[#1GE#23]GOTO9;................................................Checks to see if drilling is complete
#2=#1;..............................................................................Stores depth of current hole
GOTO1;
N9 M99;
N8 #3000=1 (NOT Z OR U COMMAND); ................................................Alarm command
To run this macro within a program, position the tool above the hole to be drilled in X and Z
axes. Specify Z or W for the depth of a hole, K for the depth of cut, and F for the feedrate to
drill the hole. The macro will then process that information and drill the hole to the appropriate
depth, and return back to the main program.
Exercises:
1. Demonstrate how the drilling macro would be called from a program.
2. Demonstrate how the drilling macro would be called as a modal macro in a program
3. Re-write the above macro using WHILE/DO statements
When preparing to write a macro, try to break your processing down into smaller steps.
Flowcharts are very helpful to demonstrate on paper how your macro program will process the
information you need, and will also make troubleshooting much easier. Try to write a flowchart
for the drilling macro above.
Macro Program Examples:
Below are two simple macro programs. Evaluate the following for each program:
1. Determine macro definition and description of variables used;
2. List on each block line what macro program does
3. How can these programs be utilized on a CNC machine?
4. Explain the function of each program, and give an example of the result
O1020;
#3002=0;
M03;
M99;
O1021;
#[500+FIX[#4120]] = #3002+#[500+FIX[#4120]];
M05;
M99;
This is a sample macro program used to capture measured data from within a robotic cell. In
this instance the robot would remove the machined part and place on a gauge device. The
gauge device would then output the values to a specific interface connection. We then used the
values from the gauge device to adjust the finish tool wear compensation amount, in order to
control part size for lights-out production.
O99(PLC DEVICE-READ SUB)
(GAUGE DATA TO R9486.7)
#100100=6(DEV TYPE)
#100101=9486(DEV NO)
#100102=101(NO OF READ BYTES)
#100103=7(READ BIT DESIGNATION)
#101=#100110(READ PLC DATA)
G4
(CONVERT TO DECIMAL AMT)
#100=[[#101]*.0001]
G4
(FIN TL COMPENSATE)
#2008=#2008+#100
G4X.1
M30
Could you utilize this same concept/layout on a machining center, to automatically compensate
for tool wear in a standard program? For practice, determine the following:
1. Program flow – what happens when, and why
2. Basic macro data you will need, and the corresponding variable specification
3. Write the macro program line by line
4. How to test the results
Practice Page
ELLISON TECHNOLOGIES TECHNICAL
TRAINING QUESTIONNAIRE
Please take a moment to help us evaluate our performance in this seminar.
WE NEED YOUR FEEDBACK!!! PLEASE BE SPECIFIC!!
Rate the following items on a quality scale of 0(poor) to 100(excellent).
Instructor’s knowledge of subject(s) _______
Instructor’s professionalism or presentation _______
Subject matter or contents of training _______
Materials (books, hand-outs, etc.) _______
Visual aids _______
Facility _______
Your overall impression of the training _______
Did this training meet your expectations? If not, why?
____________________________________________________________________________________
____________________________________________________________________________________
Was anything presented that you felt was unnecessary?
____________________________________________________________________________________
____________________________________________________________________________________
Did we omit something that you wish had been presented?
____________________________________________________________________________________
____________________________________________________________________________________
Were you bored at any time? If so, any suggestions to prevent it?
____________________________________________________________________________________
____________________________________________________________________________________
Any other comments or suggestions to improve future seminars or classes?
____________________________________________________________________________________
____________________________________________________________________________________
Please list any topics that you would like us to address in a future seminar or class.
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
Thank you for attending, and THANKS FOR YOUR FEEDBACK!