You are on page 1of 30

CUSTOM MACRO Manual

Table Of Contents
1. Overview of Custom Macro. . . . . . . . . . . . . . . . . . . . . . 3
1.1 What is macro?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Inside the macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Key Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2. Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1 Definition and Basic Use . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Type of Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3. Operation Instruction. . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1 Four Fundamental Arithmetic Operations. . . . . . . . . . . . . . . . . 16
3.2 Numeral Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Trigonometrical function. . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 Logical Operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.5 Others. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4. Control Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.1 Branch and Iteration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2 GOTO statement (Unconditional Branch). . . . . . . . . . . . . . . . . . 18
4.3 IF Statement (Conditional Branch). . . . . . . . . . . . . . . . . . . . . 18
4.4 WHILE statement (Iteration). . . . . . . . . . . . . . . . . . . . . . . . . 20

5. Create and Call Macro. . . . . . . . . . . . . . . . . . . . . . . . 22


5.1 Create a custom macro. . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.2 Simple Call (G65). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.3 Modal Call (G65) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.4 Call a macro using G code. . . . . . . . . . . . . . . . . . . . . . . . . 26
5.5 Call a macro using M code. . . . . . . . . . . . . . . . . . . . . . . . . 26
5.6 Call a sub program using M code . . . . . . . . . . . . . . . . . . . . 27
5.7 Call a sub program using T code. . . . . . . . . . . . . . . . . . . . . 27
5.8 Difference between M98 and G65. . . . . . . . . . . . . . . . . . . . . 27
5.9 Example of Call Type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
User Manual for Custom Macro

Overview of Custom Macro 1


1. Overview of Custom Macro

1.1 What is macro?


Macro is a kind of programming language that is used for a CNC(Computerized
Numerical Controller) device. As programmer, you normally create a computer
program using programming languages of C and C++. In similarity, you can use
a so called Macro to create a desired control program for FANUC or other CNC
devices.
Typical application of the macro programming includes:
• If you want to produce a workpiece in the same shape (geometry) but in
different sizes on a regular basis
• If you plan to introduce a measuring system for machine tools, or if you want
to specify the offset of the work coordinate system, or the length or diameter of
a tool
• If you want to create a custom processing code

1.2 Inside the macro


The macro is very similar to an ordinary CNC statement. However, the great
difference lies that the macro uses additional variables or operation statements or
control statements.

CNC Statement Macro Statement


(using variables)
O0001; O0002;
G01 X20. F200; #1 = 20;
Y10.; #2 = 10;
X-20.; #3 = 200;
Y-10. G01 X#1 F#3;
M30; Y#2;
X-#1;
Y-#2;
M30;

1.3 Key Features


1) Application of variables
The variable is characterized by "#" and a number. A series of variables,
starting with "#0", are predetermined. The variables are divided in: Local,
Common, and System.
2) Operation instruction enabled
You can create a macro program containing the four arithmetic fundamental
operations, numeral processing (decimal places), trigonometrical function, logical
operation, and radix transformation.
3) Control instruction enabled (branching and iteration statements)
You can use branching statements such as IF statement, GOTO statement, or
WHILE statement (for repetitive operation) to control the flow of the program.

3
User Manual for Custom Macro
2 Variable

2. Variable

2.1 Definition and Basic Use


The variable is a kind of memory space that stores your data. The variables used
in a macro program are characterized by a unique number next to "#"such as
"#1" or "#2". You can use these variables to store (assign) your data in (to) the
memory. Then, the variables can be edited or transferred.
1) Rounding up/down: You can round up or down certain decimal places when
defining or storing the value of a variable in your macro programming.
(Ex) #1 = 123; → the value of variable "#1" is 123.00
2) Formula (four fundamental arithmetic operations) enabled: You can use a
formula to specify the number for a variable, and instruct to operate between
variables when storing the value of the variable.
(Ex) #[#1+#2-10] = 1; ← use the square brackets ‘[ ]’
#3 = #1 + #2;
3) Quote of variable: If you want to use a variable in your programming, assign
the variable to the place of a desired data next to the address. To instruct a
nested operation between variables, use the square brackets "[ ]".
(Ex) G00 X#1;
G01 X[#1+#2] F#3;
4) Rounding off to the nearest integer: the variable will be rounded off to the
minimum value of each address (axial address) automatically.
(Ex) If #1 is 12.3456 for a device whose minimum setting unit is 1/1000mm,
G01 X#1; → "G01 X12.346" will be performed actually.

2.2 Type of Variable

Variable Variable
Description
Number Type
Always
#0 Undefined variable to which you cannot assign a value.
Null
This is a variable that can be used independently in each
#1~#33 macro statement. It is mostly used to store data such as the
Local operation result. When you call a different macro, the value
(non- of the variable will be assigned to the argument which, then,
variable
protective) will be passed to the macro. If you turn off the system, the
value of the variable will be reset and invalidated.

#100~#199 The value of a common variable will be shared across all


macro statements.
(non-
protective) Common #100 through #199 will be reset and invalidated if you turn
variable off the system.
#500~#999
#500 through #999 will memorize the value and stay intact
(protective) even if you turn off the system.
Unique variable of a machine that is used to read/write
System
#1000~ various necessary data of a CNC machine such as the
variable
current position or tool offset.

4
User Manual for Custom Macro

Variable 2
• Non-protective: If a CNC device is reset or turned off, or if M30, M02 or M99
is instructed, it will lose all existing data and enter the Null (undefined) state.
• Protective: Even If a CNC device is reset or turned off, or if M30, M02 or M99
is instructed, it still keeps the existing data and will be intact.
• Range of variables: The values of the local / common variables are available
only in the following range. A variable out of the range will trigger the P/S
alarm (No.111).
(-10-47 ~ -10-29), 0 , (+102-29 ~ +1047)
1) Undefined variable (Null) : #0
A variable whose value is not specified is called "undefined variable (#0)". And
the state of the variable is referred to as "Null". You can assign <Null> to other
variable and make it null. However, "#0" can not be assigned whatsoever. An
undefined variable may have a different value depending on the context where
it is used.
① Quote as variable
If an undefined variable is used together with an address, the specified
address itself will be ignored at all.
(Ex) G00 X100. Y#0; will be recognized → G00 X100.; (Y ignored)
② Operational Expression
The value of the variable will be considered 0 in operation.
(Ex) #2 = #0 * 5; → #2 = 0
③ Conditional Expression
The conditional operators will recognize the variable as 0 except for the
operators of EQ (equal) and NE (not equal).
(Ex) #0 EQ 0 → False : #0 is equal to 0 → False
#0 GE 0 → True: #0 is equal to or greater than 0 → True
→ (GE is a relation operator and will recognize it as 0 because it is
neither EQ nor NE.)
2) Local variable: #1 ~ #33
A variable used by the user in a macro statement is called "local" variable,
which is used if you want to make each macro store and memorize a desired
datum. If you pass a value to other program for a reason of calling a specific
macro, be sure to assign it to an argument. Then, the called macro will be
assigned the argument. An argument is an additional value to pass when
calling other program. This applies only to a local variable, whose numbers
are specified as below. For instance, if you assign "A10" before passing it
over to a program, the program will assign 10 to variable "#1" corresponding to
argument A. When calling a macro, a variable with no value assigned to the
corresponding argument will be Null. So you are free to assign a value to it.
There are two types of arguments available when you call a macro. However,
you should choose only one to assign.

5
User Manual for Custom Macro
2 Variable

Local Local
Type Ⅰ Type II Variable Type Ⅰ Type II Variable
Number Number
#0 I5 #16
A #1 Q J5 #17
B #2 R K5 #18
C #3 S I6 #19
I I1 #4 T J6 #20
J J1 #5 U K6 #21
K K1 #6 V I7 #22
D I2 #7 W J7 #23
E J2 #8 X K7 #24
F K2 #9 Y I8 #25
I3 #10 Z J8 #26
H J3 #11 K8 #27
K3 #12 I9 #28
M I4 #13 ‥ ‥
J4 #14 K10 #33
K4 #15

• Address G, L, N, O and P cannot be used as argument.


• Meanwhile, I, J and K should be assigned in this order. (An argument of type II
will have a different variable number depending on the order.)
• Type I and Type II will be recognized automatically.

(Ex)
G65 P9000 X10. Y-10. I60. J70.;
⇒ #24 = 10.
#25 = -10.
#4 = 60.
#5 = 70.
ppAssign a value to X,Y,I,J before calling a program
In the called program, you can assign a value to the variable corresponding to
each argument.
If you want to use the value, do that by assigning it to a variable.
The variable will be recognized as type II automatically.

G65 P9000 X10. Y-10. I50. I60. J70.;


⇒ #24 = 10.
#25 = -10.
#4 = 50.
#7 = 60.
#8 = 70.
ppThe second I will be recognized as type II automatically.
ppRecognized as I before stored to #4
ppRecognized as I2 before stored to #7
ppRecognized as J2 before stored to #8

6
User Manual for Custom Macro

Variable 2
G65 P9000 H50. J60. J70. J80.;
⇒ #11 = 50.
#5 = 60.
#8 = 70.
#11 = 80.
ppThe second J will be recognized as type II automatically.
ppIf you use both types of arguments, the smaller value will remain valid later.
Thus, the H value (#11=50) will be overwritten with J (#11=80), and "#11" will be
assigned 80. This is why you take caution when using both types!!

3) Common variable: #100 ~ #199, #500 ~ #999


A variable used in common across all macro statements is referred to as
common variable. Unlike the defined variables (Local, System), you can assign
a value to the common variable to your preference. The common variable is
classified as below in two: protective and non-protective. However, you can
use it in the same way as the local variable.

If you turn off, reset or terminate the program (M02, M99, M30), the
#100~#199
variable will be reset to Null (non-protective).
Even if you turn off, reset or terminate the program, the variable will
#500~#999
remember the value and stay intact (protective).

4) System variable: #1000 ~


Variable to show the machine information. You can use it to retrieve the
machine-specific information from a program or write a machine setting value
to the program, which includes tool offset, work coordinate system, alarms,
messages, clock settings, modal settings and current position. Some system
variables are read-only. As the system variable cannot be checked in an
immediate and direct way, you can assign a value to a local or common
variable for checking the system variable.

① Interface Signal
There is a PMC component that instructs a CNC device to operate according
to a machine that it is supposed to control. CNC should go through PMC
before it can communicate with a machine. The communication signal is
classified in: signal X to be passed from machine to PMC, signal Y passed
from PMC to machine, signal G passed from PMC to CNC, and signal F
passed from CNC to PMC. If you press a button on the operation panel, the
button signal will be passed to PMC with signal X. Then, PMC passes signal
G through a ladder created with signal X. Signal G between G54.0 and G55
is available in a macro program, and signal F (passed from CNC to PMC)
between F54.0 and F55 is also available in the macro program. For the
availability of variables, check the variables listed in the table below.

7
User Manual for Custom Macro
2 Variable

(Interface signal across CNC, PMC, and machine)

Variable Number Description


#1000~#1015 G signal of a total of 16 bits sent from PMC to macro. The macro
(G54.0~G55.7) can read this signal. #1000 through #1015 can read each bit of the
(UI000~UI015) signal while #1032 can read the entire 16 bits of signals incoming
#1032 (16bit) to between #1000 and #1015 in batch processing.

#1100~#1115 F signal of a total of 16 bits sent from macro to PMC. The macro
(F54.0~F55.7) can write (output) this signal. #1100 through #1115 can read each
(UO000~UO015) bit of the signal while #1132 can write the entire 16 bits of signals
#1132 (16bit) to send to between #1100 and #1115 in batch processing.

#1133 (32bit) F signal of a total of 32 bits sent from macro to PMC. The
(F56.0~F59.7) macro can write (output) this signal in batch processing. However,
(UO100~UO131) beyond between -99999999 and +99999999 can not be specified.

② Tool offset
You can use the system variable to read or write the tool offset. If CNC has
set a tool offset, you can read or write it if you want to make a change
as necessary. The variable number differs depending on the memory type
of CNC and where it is of M series (milling machine) / T series (turning
center). If the offset number is less than 200, #2001 through #2400 are
available. The variable numbers according to the CNC type are listed below:

(A-1) Tool offset memory type A for M series (milling machine)

Offset System variable


number i Series 0 Series
1 #10001 #2001
‥ ‥ ‥
200 #10200 #2200
‥ ‥ ‥
400 #10400 #2400

8
User Manual for Custom Macro

Variable 2
(A-2) Tool offset memory type B for M series (milling machine)

Offset Geometry offset Wear offset


number i Series 0 Series i Series 0 Series
1 #11001 #2201 #10001 #2001
‥ ‥ ‥ ‥ ‥
200 #11200 #2400 #10200 #2200
‥ ‥ ‥ ‥ ‥
400 #11400 #2600 #10400 #2400

(A-3) Tool offset memory type C for M series (milling machine)

Offset Tool length offset (H) Tool diameter offset(D)


number Geometry offset Wear offset Geometry offset Wear offset
1 #11001(#2201) #10001(#2001) #13001 #12001
‥ ‥ ‥ ‥ ‥
200 #11200(#2400) #10201(#2200) #13200 #12200
‥ ‥ ‥ ‥ ‥
400 #11400 #10400 #13400 #12400

(B-1) Tool offset memory type 1 for T series (turning center)

TNR(Tool Nose Tool


Offset X-axis offset Z-axis offset
Radius) offset
Y-axis offset
nose T
number
Wear Geom Wear Geom Wear Geom position Wear Geom
1 #2001 #2701 #2101 #2801 #2201 #2901 #2301 #2401 #2451
‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥
49 ‥ #2749 ‥ #2849 ‥ ‥ ‥ #2449 #2499
‥ ‥ ‥ ‥ ‥ ‥
64 #2064 #2164 #2264 #2964 #2364

(B-2) Tool offset memory type 2 for T series (turning center)

TNR(Tool Virtual
Offset X-axis offset Z-axis offset Nose Radius) tool Y-axis offset
number offset nose T
Wear Geom Wear Geom Wear Geom position Wear Geom
1 #10001 #15001 #11001 #16001 #12001 #17001 #13001 #14001 #19001
‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥
64
#10064 #15064 #11064 #16064 #12064 #17064 #13064 #14064 #19064
(0iSeries)
‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥ ‥
99
#10099 #15099 #11099 #16099 #12099 #17099 #13099 #14099 #19099
(16/18iSeries)

Ex) If you want to enter a X-axis geometry offset for offset number 1 of
T-series tool offset type 1, you can use a macro program such as
"#2701 = 123".

9
User Manual for Custom Macro
2 Variable

③ Work coordinate system (Work reference point) / Shift distance


You can use the work reference-point offset or the work shift distance for T
series (turning center) as variable for the read/write operations. Further, you
can use the system variables below to retrieve (read) the work coordinate
system/ work shift distance and write a desired value on it.
(A-1) Common Work Coordinate System Offset (i Series)

Function (i Series)
Variable Variable
M series (milling machine) T series (turning center)
Number Number
External work ref point for External work ref point for
#5201 #5201
the first axis the first axis
‥ ‥ ‥ ‥
External work ref point for External work ref point for
#5204 #5204
the fourth axis the fourth axis
G54 work ref point for the G54 work ref point for the
#5221 #5221
first axis first axis
‥ ‥ ‥ ‥
G54 work ref point for the G54 work ref point for the
#5224 #5224
fourth axis fourth axis
G55 work ref point for the G55 work ref point for the
#5241 #5241
first axis first axis
‥ ‥ ‥ ‥
G55 work ref point for the G55 work ref point for the
#5244 #5244
fourth axis fourth axis
G56 work ref point for the G56 work ref point for the
#5261 #5261
first axis first axis
‥ ‥ ‥ ‥
G56 work ref point for the G56 work ref point for the
#5264 #5264
fourth axis fourth axis
G57 work ref point for the G57 work ref point for the
#5281 #5281
first axis first axis
‥ ‥ ‥ ‥
G57 work ref point for the G57 work ref point for the
#5284 #5284
fourth axis fourth axis
G58 work ref point for the G58 work ref point for the
#5301 #5301
first axis first axis
‥ ‥ ‥ ‥
G58 work ref point for the G58 work ref point for the
#5304 #5304
fourth axis fourth axis
G59 work ref point for the G59 work ref point for the
#5321 #5321
first axis first axis
‥ ‥ ‥ ‥
G59 work ref point for the G59 work ref point for the
#5324 #5324
fourth axis fourth axis

10
User Manual for Custom Macro

Variable 2
Function (i Series)
Variable Variable
M series (milling machine) T series (turning center)
Number Number
Additional work ref point for
#7001
the first axis
‥ (G54.1 P1) ‥
Additional work ref point for
#7004
the fourth axis
Additional work ref point for
#7021
the first axis
‥ (G54.1 P2) ‥ ‥ ‥
Additional work ref point for
#7024
the fourth axis
‥ ‥
Additional work ref point for
#7941
the first axis
‥ (G54.1 P48) ‥
Additional work ref point for
#7944
the fourth axis

(A-2) Common Work Coordinate System (0 Series)

Variable
Function (0 Series) - M series (milling) Axis
Number
#2500 External work reference point
#2501 G54 work reference point
#2502 G55 work reference point
#2503 G56 work reference point X axis
#2504 G57 work reference point
#2505 G58 work reference point
#2506 G59 work reference point
#2600 External work reference point
#2601 G54 work reference point
#2602 G55 work reference point
#2603 G56 work reference point Y axis
#2604 G57 work reference point
#2605 G58 work reference point
#2606 G59 work reference point

11
User Manual for Custom Macro
2 Variable

Variable
Function (0 Series) - M series (milling) Axis
Number
#2700 External work reference point
#2701 G54 work reference point
#2702 G55 work reference point
#2703 G56 work reference point Z axis
#2704 G57 work reference point
#2705 G58 work reference point
#2706 G59 work reference point
#2800 External work reference point
#2801 G54 work reference point
#2802 G55 work reference point
#2803 G56 work reference point The fourth axis
#2804 G57 work reference point
#2805 G58 work reference point
#2806 G59 work reference point

(B) Shift Distance of T-series (turning center) Work Coordinate System

Control axis Shift distance of Work coordinate system


X axis #2501
Z axis #2601

④ Information of the current position


You can retrieve the current position of a tool using the system variable.
However, writing on it is not enabled.
1 through 4 of the last digit is an axial number. (If there are three axes
available: X,Y, and Z, X will be used as ~1, Y as ~2, and Z as ~3.)
The tool offset is not an immediately previous one but the current one. The
signal position of Skip will be the point when the skip signal is turned on at
block G31(Skip). If the signal is not turned on, the signal position will be the
end point of the specified block.

Variable Position Read on


Coordinate System Tool Offset
Number Information the move
Terminal point Work coordinate
#5001~#5008 Not included Enabled
of block system
Current Machine Coordinate
#5021~#5028
Position System
N/A
Current Work coordinate
#5041~#5048 Included
Position system
Position of the
#5061~#5068 Enabled
Skip signal
Tool Length
#5081~#5088
Offset
N/A
Servo position
#5101~#5108
difference

12
User Manual for Custom Macro

Variable 2
⑤ Modal information
You can use the system variables listed below to read/write the modal
information instructed until right before.

Variable Description
Number M series (milling machine) T series (turning center)
#4001 G00,G01,G02,G03,G33 (Group 01) G00,G01,G02,G03,G33,G34 (Group 01)
#4002 G17,G18,G19 (Group 02) G96,G97 (Group 02)
#4003 G90,G91 (Group 03) (Group 03)
#4004 (Group 04) G68,G69 (Group 04)
#4005 G94,G95 (Group 05) G98,G99 (Group 05)
#4006 G20,G21 (Group 06) G20,G21 (Group 06)
#4007 G40,G41,G42 (Group 07) G40,G41,G42 (Group 07)
#4008 G43,G44,G49 (Group 08) G25,G26 (Group 08)
#4009 G73,G74,G76,G80~G89 (Group 09) G22,G23 (Group 09)
#4010 G98,G99 (Group 10) G80~G89 (Group 10)
#4011 G50,G51 (Group 11) (Group 11)
#4012 G65,G66,G67 (Group 12) G66,G67 (Group 12)
#4013 G96,G97 (Group 13) (Group 13)
#4014 G54~G59 (Group 14) G54~G59 (Group 14)
#4015 G61~G64 (Group 15) (Group 15)
#4016 G68~G69 (Group 16) G17,G18,G19 (Group 16)
‥ ‥ ‥ ‥ ‥
#4022 (Group 22) (Group 22)
#4102 B code
#4107 D code
#4109 F code F code
#4111 H code
#4113 M code M code
#4114 Sequence number Sequence number
#4115 Program number Program number
#4119 S code S code
#4120 T code T code
P code (a number in the current
#4130
additional work coordinate system)

13
User Manual for Custom Macro
2 Variable

⑥ Display of macro alarms/messages


The macro can be also used to display an alarm or message. If an alarm
is tripped, "ALM" is displayed on the screen and CNC will be disabled. A
message is displayed in red in the bottom of CNC screen.

Variable
Description
Number
If you assign “0~200” to the variable #3000, CNC will enter the
alarm state and stop the automatic operation. Provide a description of
#3000 the alarm in less than 26 characters using “()” next to the value of
(alarm) the variable, .the alarm number (a value calculated by adding 3000
to the value of #3000) with the description will be displayed on the
alarm screen.

#3006 Instruct this in a macro statement so that it will be performed up until


the previous block and then stopped. Provide a message in less than
(message) 26 characters, which will be displayed in the bottom of the screen.

(Ex) #3000 = 21 (Tool Not Found);


→ displayed “3021 Tool Not Found” on the alarm screen.
#3006 = 1(Control Out);
→ displayed a message of “Control Out” in the bottom of the screen.
⑦ Clock information
You can use the internal timer of CNC to read/write the counting time
settings.

Variable
Description
Number
This variable stores the currently counting value by the unit of 1 msec
#3001 at all times. It will be reset to 0 when you turn on the machine. And
it returns to 0 in 2,147,483,648 msec.
This variable stores the counting value of the duration that the Cycle
#3002 Start indicator stays flashed. Event if you turn off the machine, it will
remember the value. It returns to 0 in 9544.371767 msec.
This variable can read the time information of the current year, month
#3011 and day.
(Ex) “20030701” → July the first, 2003
This variable can read the current time.
#3012
(Ex) “153456” → 15 o'clock 34 min 56 sec

14
User Manual for Custom Macro

Variable 2
5) Related parameters
• Reset a variable
No.6001 #7 = 0 : When reset, it will invalidate the local variable (#1~#33) to Null.
(LOCC) = 1 : Do not invalidate it to Null.
= 0 : When reset, it will invalidate the common variable (#100~#199) to
No.6001 #6
Null.
(COMC) = 1 : Do not invalidate it to Null.

※ For i series, No.6001 is used; for 0 series, No.40 #7(CLV) and #6(CCV) are available.
• Processing in a single block

No.6000 #5 = 0 : invalidate the macro statement in a single block


= 1 : validate the macro statement in a single block

• Automatic argument identification

= 0 : automatically identify the argument type. (both argument types I


No.6008 #7
and II are available)
= 1 : use only argument type Ⅰ.

• Handling the square brackets [ ]

No.3204 #0 = 0 : for a mini keyboard, use "[‘, ’]" as it is ([‘, ’]).


= 1 : Use and consider "[‘, ’]" as "(‘, ’)".

15
User Manual for Custom Macro
3 Operation Instruction

3. Operation Instruction
You can perform a rational operation across variables. In a statement of “#a =
[b]”, value b shall be assigned to value a. You can instruct up to a quintuple
operation inside the square brackets "[ ]". Inside the round brackets, provide a
comment.

3.1 Four Fundamental Arithmetic Operations

Operation Type Operator Expression


Addition + #1 = #2 + #3;
Subtraction - #1 = #2 - #3;
Multiplication * #1 = #2 * #3;
Division / #1 = #2 / #3;

3.2 Numeral Processing

Operation Type Operator Expression


Round down decimal FIX #1 = FIX[#2];
numbers
Round up decimal FUP #1 = FUP[#2];
numbers
Round ROUND #1 = ROUND[#2];
Absolute Value ABS #1 = ABS[#2];

1) The functions of FIX, FUP, and ROUND will be processed by the integer unit,
and by the specified unit in a CNC statement.
(Ex) #1 = 1.2345; #2 = RO[#1]; #3 = X[RO[#1]];
→ #2 = 1 (operation result) #3 = 1.235 (result processed in a CNC
statement)
2) When using a function in a program, you can use only the first two characters
and omit the rest.
(Ex) ROUND → RO , FIX → FI
3) For an operation instruction or conditional statement, the functions will round up
the first decimal place.
(Ex) In the expression of "#1=Round[#2]"; if #2 is 1.2345, then #1 will come up
with 1.0.
4) The CNC statement will round up the minimum specified unit of each address if
using one. Note that the result will differ depending where it performs addition
after rounding up, or it performs rounding up after addition.
(Ex) If #1 is 1.2345, and #2 is 2.3456,
G00 G91 X#1 ; move by 1.235mm
G01 X#2 ; move by 2.346mm
If instruting "G00 X-[#1+#2];", the axis will move by 3.580mm and could not
return to the original position. To return to the original position, you should
instruct
"G00 X-[ROUND[#1]+ROUND[#2]];" so that the expression will perform
addition after rounding up.

16
User Manual for Custom Macro

Operation Instruction 3
3.3 Trigonometrical function
You can use a trigonometrical function to obtain a desired angle or length value.
The unit of angle is a degree (˚).

Operation Type Expression Result


SIN #1 = SIN[Θ] c/a
COS #1 = COS[Θ] b/a
TAN #1 = TAN[Θ] c/b
ASIN #1 = ASIN[Θ]
ACOS #1 = ACOS[Θ] Θ
ATAN #1 = ATAN[Θ]

3.4 Logical Operation


This is an operation instruction that uses the logical operators (OR, AND, XOR) to
determine True or False (0, 1).
The inclusive OR is used if you want to assign 1 to a specific bit while the
exclusive OR (XOR) is used to reverse (NOT) a specific bit. AND is used to assign
0 to a specific bit.

Input Inclusive OR Exclusive OR AND


#1 #2 #1 OR #2 #1 XOR #2 #1 ANC #2
0 0 0 0 0
0 1 1 1 0
1 0 1 1 0
1 1 1 0 1

3.5 Others
As the binary or decimal conversion is involved in communicating with PMC, both
BCD and BIN are used for this purpose.

Purpose Type Expression


Convert Decimal (BCD) to Binary (BIN) BIN #1 = BIN[#2]
Convert Binary (BIN) to Decimal (BCD) BCD #1 = BCD[#2]
Square Root SQRT #1 = SQRT[#2]

17
User Manual for Custom Macro
4 Control Instructions

4. Control Instructions

4.1 Branch and Iteration


You can use a control instruction to take control of the flow of your programming.
1) GOTO statement (unconditional branch)
2) IF statement (conditional branch)
3) WHILE statement (repetition)

4.2 GOTO statement (Unconditional Branch)


The operation of the GOTO statement will move to the instructed sequence number
(n) unconditionally. The sequence number can be instructed in an expression.

GOTO n; where n is a sequence


number (1~99999)

1) GOTO 1; move to N1 unconditionally


N1;
2) GOTO #1;
N1; performed if #1 is 1
GOTO10 ;
N2; performed if #1 is 2
GOTO10 ;
N10 M30;

4.3 IF Statement (Conditional Branch)


Use this statement if you want to make a branch under a certain condition.
If the conditional statement is established (valid), it moves to the sequence number
(n); otherwise, it will move to the next block.
1) IF[ ] GOTO n
IF [conditional statement ] GOTO n; if the conditional
statement is true, branch to n

If the condition is IF [#1 GT 10] GOTO 2; If the condition


not established (process) is established
N2 G00 G91 X10.0;

2) IF[ ] THEN

IF[ conditional expression ] THEN____; if true, perform ___

Ex) IF[ #1 EQ #2 ] THEN#3=0;


→ If #1 is equal to #2, 0 will be assigned to #3.

18
User Manual for Custom Macro

Control Instructions 4
3) Conditional Expression
You can use a comparison operator to determine the result of calculation as
True or False depending on a given condition.
To create a condition, use a comparison operator between variables or between
variable and integer, and put them as a whole into the square brackets ([ ]).
You can also write an expression so that the variable varies. However, the
inequality sign is not available whatsoever.

Comparison
Meaning
Operator
EQ Equal (=)
NE Not equal (≠)
GT Greater than (>)
GE Greater than or equal to (≥)
LT Less than (<)
LE Less than or equal to (≤)

4) Example
① Sum from 1 to 10

O9500
#1 = 0;` ................................................................................... Default value of the answer
#2 = 1; ....................................................................... Default value of the number to add
N1 IF[#2 GT 10] GOTO 2; ...................... If the number to add exceeds 10, branch to N2
#1 = #1 + #2; .................................................................................... Calculate the answer
#2 = #2 + 1; ................................................................................ The next number to add
GOTO 1; ............................................................................................................ Branch to N1
N2 M30; ........................................................................................... Terminate the program

② Let's create a statement so that you can check the results of 10ⅹ1, 10ⅹ2 …
10ⅹ10, starting with #500.

O9501;
#1 = 1; ........................................................................................ Default value of the count
N1 IF[#2 GT 10] GOTO 2; ....................... If the iteration count exceeds 10, branch to N3
N2 #[499 + #1] = #1 * 10; ........... Assign the value of count 10* to from #500 in order
#1 = #1 + 1; .......................................................................................... Calculate the count
GOTO 1; ............................................................................................................ Branch to N1
N3 M30; ........................................................................................... Terminate the program

19
User Manual for Custom Macro
4 Control Instructions

4.4 WHILE statement (Iteration)


Use the WHILE statement if you want to make a loop of a part of the statement.
If the condition is established, the statement will perform "DO~END"; if not, it will
move to the next block.
1) WHILE statement

If the condition is WHILE [ conditional statement ] DO m; (m=1,2,3) If the condition


not established (processing) is established
END m;

① You can use 1,2,3 for a numeric (m) next to DO or END as an identifier to
specify the operation range.
② Other than these (1,2,3) will be of P/S alarm (No.126).
③ The identifiers (1~3) can be used multiple times.
④ However, it is not available in a program containing multiple loop statements.
2) Example of programming

WHILE [ ] DO 1; If the conditional expression inside "[ ]"


(processing) ① is established, ① process the programs
② END 1; of DO1 through END1, and if not
M30; established, ② skip it over.

① DO 1; If you omit WHILE statement and use


IF [ ] GOTO 1; only DO and END statements, ① this
(processing) will create an infinite loop. However, you
② can use IF statement to ② prevent from
END 1;
entering the infinite loop.
N1 M30;

WHILE [ ] DO 1; You can use a sub WHILE statement


WHILE [ ] DO 2; within WHILE statement. However, cross-
(processing) referencing WHILE statements is not
END 2; available.
END 1;

20
User Manual for Custom Macro

Control Instructions 4
3) Multiplication

① Identifier can be duplicate ③ A max of triplication is supported


WHILE [ ] DO 1; WHILE [ ] DO 1;
(processing) WHILE [ ] DO 2;
END 1; WHILE [ ] DO 3;
WHILE [ ] DO 1; (processing)
(processing) END 3;
END 1; END 2;
END 1;

② Crossing the range is not possible ④ Can not branch to amid a loop
WHILE [ ] DO 1; IF [ ] GOTO n;
(processing) WHILE [ ] DO 1;
WHILE [ ] DO 2; Nn;
END 1; END 1;
(processing)
END 2;

4) Comparison between IF statement and WHILE statement


You can use any of IF statement and WHILE statement to create an iteration
statement. However, a program containing IF statement retrieves sequence
number so it takes more processing time in comparison with WHILE statement.
In most macro programs, iteration will be performed by WHILE statement, and
skipping a part of program will be done by IF statement.
5) Example
Try to sum 1 through 10 using WHILE statement.

O0001;
#1 = 0; default value of the answer
#2 = 1; ....................................................................................... Default value of the count
WHILE [#2 LE 10] DO 1; .............. If the count is less than or equal to 10, perform DO1
#1 = #1 + #2; ....................... Assign the sum of count and answer back to the answer
#2 = #2 + 1; ......................................................................................... Calculate the count
END 1; ................................................................................................ End of DO1 operation
M30; ................................................................................................. Terminate the program

21
User Manual for Custom Macro
5 Create and Call Macro

5. Create and Call Macro


If you want to pass a value as argument to a macro, or if adding it as a specific
code for later use, you can call a macro statement to perform a desired action.
Call a macro program in one of the following ways:

• Call a macro
-- Simple Call (G65)
-- Modal Call (G66, G67)
-- Call a macro using G code
-- Call a sub program using M code
-- Call a sub program using T code

5.1 Create a custom macro

O□□□□; program number


Instruct; (variable, operation instruction, and
control instruction enabled)
M99;

You can refer to the program identification number when creating a program.
The variable can be also used in your programming.
Both operation instruction and control instruction are also available. You can
specify an argument corresponding to a variable by calling the applicable macro.
O0001 ~ O7999 programs that you are free to add, erase or edit
Programs that cannot be added, erased or edited unless you change
O8000 ~ O8999
the setting
O9000 ~ O9019 Macro of a special call type
Programs that cannot be added, erased or edited unless you set
O9020 ~ O9899
the parameter
O9900 ~ O9999 Robot-manipulating program

5.2 Simple Call (G65)


1) Call
If you instruct G65 in the main program, this will call a macro program specified
as P. In this process, you can specify an argument before passing a value of
the argument to the macro. All arguments are valid only within the specified
block.

G65 Pp Ll <assign argument>


P : caller program
L : iteration count (if omitted, perform
once)
Argument : Data handed over to a macro

① Instruct G65 before specifying any argument.


② You can specify an argument before assigning the value to a local variable.
Argument specification type I and II will be identified automatically by CNC. If
both types of specifications are instructed, the later one will prevail.
③ The unit of argument will be the minimum setting unit for each address.

22
User Manual for Custom Macro

Create and Call Macro 5


④ The arguments can be quadrupled including G65 and G66.
If an iteration is necessary, specify the argument between 1 and 9999 next
to L. If you skip L, the argument will be called only once.
2) Example
Create a macro program for cutting a circle whose radius is known.

Call type
G65 P9999 Xx Yy Rr Ff;
X : X coordinates of the center of a circle
(#24)
Y : Y coordinates of the center of a circle
(#25)
R : Radius (#18)
F : Cutting feed rate (#9)
Main program Macro program
O0001; O9999;
G92 X0 Y0; #3 = #18 / 2; → 1/2 of the radius of the
G65 P9999 X100. Y50. R45. F300; target circle
(Call the O9999 macro while passing the G00 G90 X#24 Y#25;
follow-up argument) G91 G01 X#3 Y#3 F#9;
G00 G90 X0 Y0; G02 X#3 Y-#3 R#3;
M30; I-#18;
X-#3 Y-#3 R#3;
G90 X#24 Y#25;
M99;

5.3 Modal Call (G65)


1) Call
If you instruct G65 in the main program, this will call a macro program specified
as P. In this process, you can specify an argument before passing a value
of the argument to the macro, or you can call the macro continuously by
switching the argument value as the macro stays in modal state until the calling
is canceled by G67.

G66 Pp Ll <assign argument>


P : caller program
L : iteration count (if omitted, perform once)
Argument : Data handed over to a macro

① Instruct G66 and cancel it by G67.


② Specify the start point in the next block to G66 instruction.
③ One G67 is instructed, the macro will not be called any more from the next
block.
④ In a block where no axial movement is instructed, no macro will be called
whatsoever.
⑤ The argument can be specified only in G66 block. (not automatically
specified each time it is called)
Specify the start point in the next block to G66 instruction.

23
User Manual for Custom Macro
5 Create and Call Macro

2) Example
See the figure below and create a macro program for processing holes as
instructed.
Call type
G66 Pp Xx Yy Zz Rr Ff Ll;
X, Y, Z : X, Y, Z coordinates of a hole (#24,
#25, #26)
R : Coordinates of the R point (#18)
F : cutting feed rate (#9)
L : iteration count
Main program Macro program
O0001; O9110;
G28 G91 X0 Y0 Z0; #1 = #4001;
G92 X0 Y0 Z50.; #3 = #4003;
G00 G90 X100. Y50.; #4 = #4109;
G66 P9110 Z-20. R5. F500; #5 = #5003;
G90 X20. Y20.; G00 G90 Z#18;
X70. Y80.; G01 Z#26 F#9;
G67; IF[#4010 EQ 98] GOTO 1;
M30; G00 Z#18;
GOTO 2;
N1 G00 Z#5;
N2 G#1 G#3 F#4;
M99;

24
User Manual for Custom Macro

Create and Call Macro 5

Main program Macro program


O0002; O9000;
G92 X0 Y0 Z0; #27 = #5003;
G66 P9000 R3. Z-21. Q-5. D1. F200; G00 G90 Z#18;
G00 G90 G99 X30. Y20.; #1 = #18;
X60. Y50.; WHILE[#1 GT #26]GOTO 1;
G98 X100. Y20.; #1 = #1 + #17;
G67; IF[#1 LE #26] GOTO 1;
G00 X0 Y0; #1 = #26;
M30; N1 G01 Z#1 F#9;
IF[#1 LE #26] GOTO 2;
G00 Z[#1 + #17];
END 1;
N2 IF[#4010 EQ 99] GOTO 8;
G00 Z#27;
GOTO 9;
N8 G00 Z#18;
N9 M99;

25
User Manual for Custom Macro
5 Create and Call Macro

5.4 Call a macro using G code


You can call a macro program using a G code by assigning it to a parameter
(No.6050~6059) in advance. Once you assign a G code to the corresponding
parameter, you can call the macro simply using the G code. When calling the
macro, you can specify an argument (data) before passing the value of the
argument, which is valid only within the instructed block.

Parameter number
Program number
0i Series 0 Series
O9010 6050 220
O9011 6051 221
O9012 6052 222
O9013 6053 223
O9014 6054 224
O9015 6055 225
O9016 6056 226
O9017 6057 227
O9018 6058 228
O9019 6059 229

Ex) If No.6054=200, the macro will be called by G200 <Argument> but, actually,
G65 P9014 <Argument> will be performed.

5.5 Call a macro using M code


You can call a macro program using a M code by assigning it to a parameter
(No.6080~6089) in advance. Once you assign a M code to the corresponding
parameter, you can call the macro simply using the M code. When calling the
macro, you can specify an argument before passing the value of the argument.
Parameter number
Program number
0i Series 0 Series
O9020 6080 230
O9021 6081 231
O9022 6082 232
O9023 6083 233
O9024 6084 234
O9025 6085 235
O9026 6086 236
O9027 6087 237
O9028 6088 238
O9029 6089 239

26
User Manual for Custom Macro

Create and Call Macro 5


5.6 Call a sub program using M code
You can call a macro program using a M code by assigning it to a parameter
(No.6080~6089) in advance. Once you assign a M code to the corresponding
parameter, you can call the macro simply using the M code but no argument can
be specified at all.
Parameter number
Program number
0i Series 0 Series
O9001 6071 240
O9002 6072 241
O9003 6073 242
O9004 6074
O9005 6075
O9006 6076
O9007 6077
O9008 6078
O9009 6079

5.7 Call a sub program using T code


You can call a macro program using a T code by assigning it to a parameter
(No.6071~6079) in advance. If you assign 1 to the TCS parameter (No.6001#5 =
1) and instruct the T code, this will call O9000. The T code will be assigned to
parameter #149. However, you cannot specify the argument whatsoever.

5.8 Difference between calling a sub program (M98) and calling a macro program
(G65)
• G65 enables you to specify the argument while M98 does not.
• The M98 block will be called after the CNC instruction is performed, where
the G65 block will be ignored.
• The M98 instruction will stop on a single block while G65 does not.
• #1 before instructing G65 has nothing to do with, and is separate from #1
after the instruction.

27
User Manual for Custom Macro
5 Create and Call Macro

5.9 Example of Call Type


Create a circle cutting program in two types: rough cut and finishing cut.
* Call type
G65 P9999 Rr Uu Dd Ff Ee;
R : radius (#18)
U : Finishing allowance (#21)
D : tool offset number (#7)
F : cutting feed rate in rough
grinding (#9)
E : cutting feed rate in finishing
(#8)

* Normal call of a macro * Used for multiple calling


O0001; O0001;
G92 X0 Y0 Z10.; G92 X0 Y0 Z10.;
G00 G90 X50. Y50.; G00 G90 X50. Y50.;
Z5.; Z5.;
G01 Z-20. F300; G01 Z-20. F300;
G65 P9100 R44. Q10. D1 F300; G65 P9001 R45. U1. Q10. D1 F300 E200;
G65 P9200 R45. D1 F100; G00 Z30.;
G0 Z30.; X0 Y0;
M30; M30;

O9001;
G65 P9100 R[#18 - #32] Q#17 D#7 F#9;
G65 P9200 R#18 D#7 F#8;
M99;

28
Revision History
CUSTOM MACRO Manual
Version Year/Month Revision history Created by

New Release Cha, Sukyeong


01 2011.09
(CUSTOM MACRO Manual) Hyun, Jaram

02

03

04

04

05

06

07

08

09

10

You might also like