Professional Documents
Culture Documents
Custom Macro Manual (EN) ) 111025
Custom Macro Manual (EN) ) 111025
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
3
User Manual for Custom Macro
2 Variable
2. 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.
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
(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.
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!!
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).
① 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
#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:
8
User Manual for Custom Macro
Variable 2
(A-2) Tool offset memory type B for M series (milling machine)
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
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
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
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
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.
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
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.
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 (˚).
3.5 Others
As the binary or decimal conversion is involved in communicating with PMC, both
BCD and BIN are used for this purpose.
17
User Manual for Custom Macro
4 Control Instructions
4. Control Instructions
2) IF[ ] THEN
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
① 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
20
User Manual for Custom Macro
Control Instructions 4
3) Multiplication
② 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;
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
• 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
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
22
User Manual for Custom Macro
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;
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
25
User Manual for Custom Macro
5 Create and Call Macro
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.
26
User Manual for Custom Macro
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
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
02
03
04
04
05
06
07
08
09
10