Macro Call Functions in CNC Programming
Macro Call Functions in CNC Programming
………. ……….
M30 M99
MEP164
Detailed description
When command G66 is entered, the designated user macro subprogram willbe called every
time after execution of the move commands within a block until G67 (cancellation) is entered.
Command codes G66 and G67 must reside in the same programm in pairs.
Note: In order that it may function correctly, do not give a command of macro call in one block
together with any one of the following commands (described in this chapter):
Hole machining pattern cycle
Fixed cycle
Subprogram control
13-64
PROGRAM SUPPORT FUNCTIONS 13
13-12-2 Macro call instructions
Two types of macro call instructions are provided: single-call instructions used to call only at the
designated block, and modal call instructions used to call at each block within a macro call mode.
Modal call instructions are further divided into type A and type B.
1. Single call
O01
to subprogram
G65P01L1 <argument>
M99
to main program
Format:
G65 <__> L__ <argument>
Repeat times
Repeat times
<Argument>
When argument is to be delivered to the user macro subprogram as a local variable, designate
the required data with the respective addresses. (Argument designation is not available for a
user macro subprogram written in MAZATROL language.)
In such a case, the argument can have a sign and a decimal point, irrespective of the address.
Arguments can be specified using method I or II, as shown below.
13-65
13 PROGRAM SUPPORT FUNCTIONS
A. Argument specification I
Format: A_B_C_ X_Y_Z_
Detailed description
- An argument can be specified using all addresses, except G, L, N, O, and P.
- Except for I, J, and K, addresses does not need be specified in an alphabetical order.
- Addresses I, J, and K must be specified in an alphabetical order.
I_J_K_ ... Correct
J_I_K_ ... Wrong
- Addresses whose specification is not required can be omitted.
- The relationship between addresses that can be specified using argument specification I, and
variables numbers in a user macro unit, is shown in the following table:
Relationship between address and variables number Call commands and usable addresses
Address specified using Variable in macro-
G65, G66 G66.1
method I program
A #1
B #2
C #3
D #7
E #8
F #9
G #10 × ×*
H #11
I #4
J #5
K #6
L #12 × ×*
M #13
N #14 × ×*
O #15 × ×
P #16 × ×*
Q #17
R #18
S #19
T #20
U #21
V #22
W #23
X #24
Y #25
Z #26
: Usable ×: Unusable *: Usable in G66.1 modal
13-66
PROGRAM SUPPORT FUNCTIONS 13
B. Argument specification II
Format: A_B_C_I_J_K_I_J_K_
Detailed description
- Up to a maximum of 10 sets of arguments that each consist of addresses I, J, and K, as well as
A, B, and C, can be specified.
- If identical addresses overlap, specify them in the required order.
- Addresses whose specification is not required can be omitted.
- The relationship between addresses that can be specified using argument specification II, and
variables numbers in a user macro unit, is shown in the following table:
Note: In the table above, the numerals 1 through 10 have been added to addresses I, J, and
J just to denote the order of arrangement of the designated sets of arguments: these
numerals are not included in actual instructions.
13-67
13 PROGRAM SUPPORT FUNCTIONS
Subprogram
Main program
O01
to subprogram
G66P01L1 <argument>
M99
to main program
G67
to subprogram
For a block that has a move command code between G66 and G67, the designated user macro
subprogram is executed after that move command has been executed. The subprogram is
executed an 1 number of times for the first call, or once for subsequent calls.
For modal call of type A, the methods of specifying <argument> are the same as used for single
call.
Format:
G66 <__> L__ <argument>
Repeat times
Program name
Alternatively,
Repeat times
Program No.
Detailed description
- When command G66 is entered, the designated user macro subprogram will be called every
time after execution of the move commands within a block until command G67 (cancellation) is
entered.
- Command codes G66 and G67 must reside in the same program in pairs.
Entry of a G67 command without a G66 command results in an alarm 857 INCORRECT USER
MACRO G67 PROG.
13-68
PROGRAM SUPPORT FUNCTIONS 13
Example: Drilling cycle
Main program
Y
Argument F
Z-axis movement
To subprogram
Note 1: The designated subprogram is executed after the axis commands in the main program
have been executed.
Note 2: No subprograms are executed for the G67 block and its successors.
Format:
G66.1 <__> L__ <argument>
Repeat times
Program name
Alternatively,
Repeat times
Program No.
Detailed description
- During the G66.1 mode, only the codes O, N, and G in each of the read command blocks are
executed. No other codes in those blocks are executed; codes other than O, N, and G are
handled as arguments. However, only the last G-code and the N-codes following a code other
than O or N become arguments.
13-69
13 PROGRAM SUPPORT FUNCTIONS
- All significant blocks in the G66.1 mode are regarded as preceded by the command G65P_.
For example, the block of
N100G01G90X100. Y200. F400R1000
in the G66.1P1000 mode is handled as equivalent to
N100G65P1000G01G90X100. Y200. F400R1000.
Note: Call is executed even for the G66.1 command block of the G66.1 mode, with the
relationship between the addresses of the arguments and the variables numbers
being the same as for G65 (single call).
- The data range of the G, L, P, and N commands that you can set as new variables using the
G66.1 mode is the same as the data range of usual NC commands.
- Sequence number N, modal G-codes, and O are all updated as modal information.
Format:
G×× <argument>
Detailed description
- The instruction shown above performs the same function as those of the instructions listed
below. Which of these listed instructions will apply is determined by the parameter data to be
set for each G-code.
M98P
G65P <argument>
G66P <argument>
G66.1P <argument>
- Use parameters to set the relationship between G ×× (macro call G-code) and P (program
number of the macro to be called).
- Of G00 through G255, up to a maximum of 10 command codes can be used with this
instruction unless the uses of these codes are clearly predefined by EIA/ISO Standards, such
as G00, G01, G02, etc.
- The command code cannot be included in user macro subprograms that have been called
using G-codes.
13-70
PROGRAM SUPPORT FUNCTIONS 13
5. Auxiliary command macro call (M-, S-, T-, or B-code macro call)
The user macro subprograms of the required program number can be called just by setting M-,
S-, T-, or B-codes.
Format:
Mm (or Ss, Tt and Bb)
Detailed description (The following description also applies to S-, T-, and B-codes.)
- The instruction shown above performs the same function as those of the instructions listed
below. Which of these listed instructions will apply is determined by the parameter data to be
set for each M-code.
M98P
G65PMm
G66PMm
G66.1PMm
- Use parameter to set the relationship between Mm (macro call M-code) and P (program
number of the macro to be called).
Up to a maximum of 10 M-codes, ranging from M00 to M95, can be registered. Do not register
the M-codes that are fundamentally required for your machine, nor M0, M1, M2, M30, and M96
through M99.
- If registered auxiliary command codes are set in the user macro subprograms that have been
called using M-codes, macro calls will not occur since those special auxiliary command codes
will be handled as usual ones (M-, S-, T-, or B-codes).
13-71
13 PROGRAM SUPPORT FUNCTIONS
G66Pp2
Macro p1
(p2 call-out)
Zz2 x1 w1 x2 M99
After z2 execution
G67
(p2 cancel)
Macro p2 Macro p2 Macro p2
Macro p1
(p1 call-out)
Zz3 x1 w1 x2 M99
After z3 execution
G67
(p1 cancel)
Zz4
Zz5
13-72
PROGRAM SUPPORT FUNCTIONS 13
8. User macro call based on interruption
Outline
Prior creation of special user macros for interrupt processing allows the user macros to be
executed during automatic operation when a user macro interrupt signal is input. After the user
macro has been executed, the program can also be returned to the interrupted program block
and then started from this block.
Detailed description
Format for selecting the user macro branching destination
M96<_>L_ (or M96P_L_) (Branching mode on)
When user macroprogram interruption signal is input
during this space, the branch into the specified user
M97 (Branching mode off) macroprogram will be applied.
It depends upon the specifications of the machine whether user macro interrupt signal is
available or not.
If a user macro interrupt signal is input during execution of an axis movement block, the user
macroprogram will be executed immediately by interrupting the movement without holding
(storing) the remaining motion amount.
User macro interrupts can be processed even when the number of levels of macro call
multiplexity during the occurrence of an interrupt is four. The local variables’ level of the user
macros used for interruption is the same as the level of the user macros existing during the
occurrence of an interrupt.
Interruption branch
Interruption return
M97
M99 M99 M99
(Level 3) (Level 4)
13-73
13 PROGRAM SUPPORT FUNCTIONS
13-12-3 Variables
Of all types of variables available for the NC unit, only local variables, common variables, and
part of system variables are retained even after power-off.
1. Multiplexing of variables
Under user macro specifications, variables can have their identifiers (identification numbers)
either transformed into variables, which is referred to as multiplexing, or replaced with
<expression>.
For <expression>, only one arithmetic expression (for either multiplication, division, addition, or
subtraction) can be used.
Example 1: Multiplexing variables
#1=10 #10=20 #20=30 From #1 = 10, #[#[#1]] = #[#10] will result.
#5=#[#[#1]] From #10 = 20, #[#10] = #20 will result. Therefore #5 = #20, i.e. #5
= 30 will result.
#1=10 #10=20 #20=30 From #1 = 10, #[#[#1]] = #[#10] will result.
#5=1000 From #10 = 20, #[#10] = #20 will result. Therefore #20 = #5, i.e.
#[#[#1]]=#5 #20 = 1000 will result.
Example 2: Replacing variables identifiers with <expression>
#10=5
#[#10+1]=1000 #6 = 1000 will result.
#[#10–1]=–1000 #4 = –1000 will result.
#[#103]=100 #15 = 100 will result.
#[#10/2]=100 #2 = –100 will result.
2. Undefined variables
Under user macro specifications, variables remaining unused after power-on or local variables
that are not argument-specified by G65, G66, or G66.1 can be used as <empty>. Also, variables
can be forcibly made into <empty>.
Variable #0 is always used as <empty> one, and this variable cannot be defined on the left side
of the expression.
A. Arithmetic expression
#1=#0................. #1 = <empty>
#2=#0+1 ............ #2 = 1
#3=1+#0 ............ #3 = 1
#4=#010 .......... #4 = 0
#5=#0+#0 .......... #5 = 0
Note: Be careful that <empty> is handled the same as 0 during processing of expressions.
<empty> + <empty> = 0
<empty> + <constant> = constant
<constant> + <empty> = constant
B. Applying variables
Application of an undefined variable alone causes even the address to be ignored.
If #1 = <empty>
G0X#1Y1000 is equivalent to G0Y1000, and
G0X[#1+10]Y1000 is equivalent to G0X10Y1000.
13-74
PROGRAM SUPPORT FUNCTIONS 13
C. Conditional expression
Only for EQ and NE, does <empty> differ from 0 in meaning.
Right side EQ NE GT LT GE LE
Left side Empty Constant Empty Constant Empty Constant Empty Constant Empty Constant Empty Constant
Empty H H H H H
Constant H H H
13-75
13 PROGRAM SUPPORT FUNCTIONS
G65Pp1L1 <argument>
Argument addresses marked as × in the table above cannot be used. Only during the G66.1
mode, however, can argument addresses marked with an asterisk (*) in this table be additionally
used. Also, the dash sign (–) indicates that no address is crosskeyed to the local variables
number.
13-76
PROGRAM SUPPORT FUNCTIONS 13
1. Local variables for a subprogram can be defined by specifying <argument> when calling a
macro.
To subprogram #5=#4010
G65P9900A60.S100.F800 G91G01 X[#19COS[#1]]
Y[#19SIN[#1]]F#9
M02 M99
F (#9)=800
Local variable
data table S (#19)=100.000
#30=FUP[#2/#5/2]
To subprogram
#5=#2/#30/2
M98H100L#30
G65P1A100.B50.J10.F500
X#1
M99
N100G1X#1F#9
Y#5
X–#1
Example of face milling X#5
M99
A (#1) 100.000
B (#2) 50.000
J
F (#9) 500
Local variable
J (#5) 10.000 8.333
data table
A (#30) 3.
In the sample program for face-milling that is shown above, although the argument J has initially
been programmed as a machining pitch of 10 mm, it has been changed into 8.333 mm to ensure
equal-pitched machining.
Also, local variable #30 contains the calculated data about the number of times of reciprocal
machining.
13-77
13 PROGRAM SUPPORT FUNCTIONS
3. Local variables can be used for each of the four levels of macro call separately. For the
main program (macro level 0), separate local variables are also provided. The local
variables of level 0, however, cannot be designated with arguments.
Main (Level 0) O1 (Macro level 1) O10 (Macro level 2) O100 (Macro level 3)
#1=0.1#2=0.2#3=0.3
Local variable (0) Local variable (1) Local variable (2) Local variable (3)
#1 0.100 A(#1) 1.000 A(#1) 10.000 A(#1) 100.000
#2 0.200 B(#2) 2.000 B(#2) 20.000 B(#2) 200.000
#3 0.300 C(#3) 3.000 C(#3) 30.000 C(#3)
D(#7) D(#7)
How the local variables are currently being used is displayed on the screen.
13-78
PROGRAM SUPPORT FUNCTIONS 13
3. Macro interface input system variables (#1000 to #1035)
You can check the status of an interface input signal by reading the value of the appropriate
variables number (#1000 to #1035).
The read value of the variables number is either 1 (contact closed) or 0 (contact open). You can
also check the status of all input signals of the variables from #1000 to #1031 by reading the
value of variables number 1032. Variables from #1000 to #1035 can only be read; they cannot
be placed on the left side of an arithmetic expression.
System variable Points Interface input signal System variable Points Interface input signal
#1000 1 Register R72, bit 0 #1016 1 Register R73, bit 0
#1001 1 Register R72, bit 1 #1017 1 Register R73, bit 1
#1002 1 Register R72, bit 2 #1018 1 Register R73, bit 2
#1003 1 Register R72, bit 3 #1019 1 Register R73, bit 3
#1004 1 Register R72, bit 4 #1020 1 Register R73, bit 4
#1005 1 Register R72, bit 5 #1021 1 Register R73, bit 5
#1006 1 Register R72, bit 6 #1022 1 Register R73, bit 6
#1007 1 Register R72, bit 7 #1023 1 Register R73, bit 7
#1008 1 Register R72, bit 8 #1024 1 Register R73, bit 8
#1009 1 Register R72, bit 9 #1025 1 Register R73, bit 9
#1010 1 Register R72, bit 10 #1026 1 Register R73, bit 10
#1011 1 Register R72, bit 11 #1027 1 Register R73, bit 11
#1012 1 Register R72, bit 12 #1028 1 Register R73, bit 12
#1013 1 Register R72, bit 13 #1029 1 Register R73, bit 13
#1014 1 Register R72, bit 14 #1030 1 Register R73, bit 14
#1015 1 Register R72, bit 15 #1031 1 Register R73, bit 15
Note: The following interface input signals are used exclusively in the NC system operation
(cannot be used for other purposes).
13-79
13 PROGRAM SUPPORT FUNCTIONS
System variable Points Interface output signal System variable Points Interface output signal
#1100 1 Register R172, bit 0 #1116 1 Register R173, bit 0
#1101 1 Register R172, bit 1 #1117 1 Register R173, bit 1
#1102 1 Register R172, bit 2 #1118 1 Register R173, bit 2
#1103 1 Register R172, bit 3 #1119 1 Register R173, bit 3
#1104 1 Register R172, bit 4 #1120 1 Register R173, bit 4
#1105 1 Register R172, bit 5 #1121 1 Register R173, bit 5
#1106 1 Register R172, bit 6 #1122 1 Register R173, bit 6
#1107 1 Register R172, bit 7 #1123 1 Register R173, bit 7
#1108 1 Register R172, bit 8 #1124 1 Register R173, bit 8
#1109 1 Register R172, bit 9 #1125 1 Register R173, bit 9
#1110 1 Register R172, bit 10 #1126 1 Register R173, bit 10
#1111 1 Register R172, bit 11 #1127 1 Register R173, bit 11
#1112 1 Register R172, bit 12 #1128 1 Register R173, bit 12
#1113 1 Register R172, bit 13 #1129 1 Register R173, bit 13
#1114 1 Register R172, bit 14 #1130 1 Register R173, bit 14
#1115 1 Register R172, bit 15 #1131 1 Register R173, bit 15
Note 1: Data of the system variables from #1100 to #1135 is saved according to the logical
level (1 or 0) of the signal that has been lastly sent. The saved data is cleared by
power-on/off automatically.
Note 2: The following applies if a data other than 1 or 0 is assigned to the variables from #1100
to #1131:
<empty> is regarded as equal to 0.
Data other than 0 and <empty> is regarded as equal to 1.
Data less than 0.00000001, however, is regarded as undefined.
13-80
PROGRAM SUPPORT FUNCTIONS 13
#1001 #1101
#1002 #1102
Read Read
#1003 #1103
only and write
#1028 #1128
#1029 #1129
Macro- #1130
#1030
instruction
#1031 #1131
5. Tool offset
: Available × : Unavailable
Range of variable Nos. Type A Type B Type C
#100001 - #10001 - Length Geom. Geom. offset
#100000+n #10000+n #2001 - #2000+n offset Z
#110001 - #11001 - Length Wear Wear comp.
#110000+n #11000+n #2201 - #2200+n × comp. Z
#160001 - #16001 -
#160000+n #16000+n Dia. Geom. Geom. offset
#2401 - #2400+n × offset ACT-
*(#120001 - *(#12001 -
#120000+n) #12000+n)
#170001 - #17001 -
#170000+n #17000+n Dia. Wear Wear comp.
#2601 - #2600+n × comp. ACT-
*(#130001 - *(#13001 -
#130000+n) #13000+n)
#120001 - #12001 - Geom. offset
× ×
#120000+n #12000+n X
#130001 - #13001 - Wear comp.
× ×
#130000+n #13000+n X
#140001 - #14001 - Geom. offset
× ×
#140000+n #14000+n Y
#150001 - #15001 - Wear comp.
× ×
#150000+n #15000+n Y
Note : Set bit 0 of parameter F96 to “0” to use the TOOL OFFSET type C data.
13-81
13 PROGRAM SUPPORT FUNCTIONS
Using variables numbers, you can read tool data or assign data.
Usable variables numbers are of the order of either #10000 or #2000. For the order of #2000,
however, only up to 200 sets of tool offsets can be used.
The last three digits of a variables number denote a tool offset number.
As with other variables, tool offset data is to contain the decimal point. The decimal point must
therefore be included if you want to set data that has decimal digits.
Sensor
Note : The example shown above does not allow for any skip sensor signal delay. Also,
#5003 denotes the position of the starting point of the Z-axis, and #5063 denotes the
skip coordinate of the Z-axis, that is, the position at which a skip signal was input during
execution of G31.
13-82
PROGRAM SUPPORT FUNCTIONS 13
(Example 1) N1
M
N1 G28X0Y0Z0 –90.
N2 #5221=–20.#5222=–20.
N3
N3 G90G00G54X0Y0 –10.
W1 N11 –20.
W1
N10 #5221=–90.#5222=–10. Workpiece coordinate
system of G54 specified
N11 G90G00G54X0Y0
by N10
Workpiece coordinate system of
G54 specified by N2
M02
(Example 2)
Fundamental machine coordinate system
Coordinate shift
M
Coordinate
system G55
before G54
change
W2 (G55)
N100 #5221=#5221+#5201 W1 (G54)
#5222=#5222+#5202
#5241=#5241+#5201
#5242=#5242+#5202
#5201=0 #5202=0 Fundamental machine coordinate system
Coordinate M
system after G55
G54
change
W2 (G55)
W1 (G54)
MEP166
The example 2 shown above applies only when coordinate shift data is to be added to the offset
data of a workpiece coordinate system (G54 or G55) without changing the position of the
workpiece coordinate system.
[Additional workpiece coordinate system offset]
Variables numbered 70001 to 75996 can be used to read or assign additional workpiece
coordinate system offsetting dimensions. The variable number for the k-th axis origin of the “Pn”
coordinate system can be calculated as follows:
70000 + (n – 1) × 20 + k
Note: The total number of controllable axes depends on the machine specifications.
13-83
13 PROGRAM SUPPORT FUNCTIONS
Alternatively, variables numbered 7001 to 7956 can be used to read or assign additional work-
piece coordinate system offsetting dimensions. The variable number for the k-th axis origin of the
“Pn” coordinate system can be calculated as follows:
7000 + (n – 1) × 20 + k
Note: The total number of controllable axes depends on the machine specifications.
7. NC alarm (#3000)
The NC unit can be forced into an alarm status using variables number 3000.
#3000 = 70 (CALL#PROGRAMMER#TEL#530)
*1 Refers to alarm Nos. 980 to 999 whose messages are preset as indicated in Alarm List.
*2 Display of a message as it is set in the macro statement.
IF[#1NE0]GOTO100 980 MACRO USER ALARM 1
Operation stop by
#3000=1
NC alarm
N100
IF[#2NE0]GOTO200 Operation stop
3021#ORIGINAL#ALARM#1
#3000=21(#ORIGINAL#ALARM#1) by NC alarm
N200
13-84
PROGRAM SUPPORT FUNCTIONS 13
8. Integrated time
Using variables #3001 and #3002, you can read the integrated time existing during automatic
operation or assign data.
11
The integrated time is cleared to 0 after having reached about 3.6 × 10 ms.
O9010
To subprogram #3001=0
WHILE[#3001LE#20]DO1
G65P9010T (Allowable time [ms])
END1
M99
Using variables #3040 to #3044, moreover, it is possible to read various types of cumulative time
data displayed in the ACCUMULATED TIME window. TOTAL TIME denotes the cumulative time
for which the power has been turned on.
Variable Data at
Item Unit Initialization Counting
No. power-on
POWER ON 3040 Power being turned on
AUTO OPE. 3041 Automatic operation (from start to end)
Same as at Automatic operation (with the start button lamp
AUTO CUT. 3042 ms —
power-off lighting)
TOTAL CUT. 3043 Execution of G1, G2 or G3 commands
TOTAL TIME 3044 Power being turned on
Note 1: Variable #3001 can be used to replace POWER ON item in the ACCUMULATED TIME
window with the desired value, on condition that bit 7 of parameter F151 is set to 0.
According to the parameter setting, variable #3001 is processed as shown below in
relation to POWER ON item.
Effect of writing data into #3001 on
F151 bit 7 Value of #3001 at power-on
POWER ON item
0 Replacement by the written value Same as at power-off
1 No effect Reset to zero (0)
Note 2: Variable #3002 can be used to replace the AUTO CUT. item in the ACCUMULATED
TIME window with the desired value.
Note 3: #3040, #3041, #3042, #3043 and #3044 are read-only variables.
13-85
13 PROGRAM SUPPORT FUNCTIONS
Format:
#3006 = 1 (CHECK OPERAT)
Additional setting of a character string (in 31 characters at maximum) in parentheses allows the
required stop message to be displayed on the monitor.
It depends upon the setting of bit 3 of parameter F37 when the stop message is cleared from the
screen.
F37 bit 3 = 0: The message does not disappear till completion of automatic operation.
F37 bit 3 = 1: The message disappears when the execution of the next block is started.
Note 1: Always set “1” on the right-hand side of equation; otherwise (e.g. #3006 = 2) the oper-
ation will not be stopped, nor the message displayed.
13-86
PROGRAM SUPPORT FUNCTIONS 13
Note 2: A block of #3006 does not cause the operation to be stopped, nor the message to be
displayed when the program is executed on the TOOL PATH CHECK display. As for
running on the VIRTUAL MACHINING display, operation is stopped at a block of
#3006, but the message does not appear.
Note 3: Only use one-byte characters to specify the message in parentheses; otherwise the
message may not be displayed exactly as specified.
13-87
13 PROGRAM SUPPORT FUNCTIONS
Note 1: Use the variable #4315 from the second block of the program. If it is used in the first
block, the reading of the program number is not successful.
Note 2: The variables #4115 and #4315 are only effective for programs whose ID-number or
name consists of numerals only. During execution of a program whose name contains
even one single character other than numerals, the reading in question remains zero
(0).
Note 3: Do not use #4501 to #4530 elsewhere than in an interruption macroprogram; otherwise
an alarm will be caused (846 DESIGNATED NUMBER NOT FOUND).
Example : Given below is an example to show the difference between variables #4113 and
#4313 (for checking modal information about M-codes) in the information that is
obtained in the parallel flow of actual execution and internal pre-reading (analysis) for
automatic operation.
Previous block (#4113) Block being executed (#4313)
: :
N001 M3 N001 M3
N002 In execution N002 In execution
N003 N003
: :
N006 M200 N006 M200
N007 #100=#4113 In analysis N007 #100=#4313 In analysis
N008 N008
Reading the information about M-codes Reading the information about M-codes
(M200) at the block previous to the cur- (M3) at the block being executed.
rently analyzed one.
13-88
PROGRAM SUPPORT FUNCTIONS 13
15. Position information
Using variables numbers from #5001 to #5116, you can check the ending-point coordinates of
the previous block, machine coordinates, workpiece coordinates, skip coordinates, tool position
offset coordinates, and servo deviations.
1. The ending-point coordinates and skip coordinates read will be those related to the
workpiece coordinate system.
2. Ending-point coordinates, skip coordinates, and servo deviations can be checked even
during movement. Machine coordinates, workpiece coordinates, and tool position offset
coordinates must be checked only after movement has stopped.
G00
G01
Read
command
End point
coordinates
W Workpiece
coordinate system
Workpiece
coordinates
Machine
coordinate system
Machine M
coordinates
MEP167
13-89
13 PROGRAM SUPPORT FUNCTIONS
3. Skip coordinates denote the position at which a skip signal has turned on at the block of
G31. If the skip signal has not turned on, skip coordinates will denote the corresponding
ending-point position.
Read
command
Gauge, etc.
MEP168
4. The ending-point position denotes the tool tip position which does not allow for any tool
offsets, whereas machine coordinates, workpiece coordinates, and skip coordinates denote
the tool reference-point position which allows for tool offsets.
Skip signal
F (Speed)
W
Workpiece
coordinate system
Workpiece
Skip signal input coordinates
coordinates Machine
M coordinate system
Machine coordinates
Mark : Read after confirmation of stop.
Mark : Can be read during move. MEP169
The input coordinates of a skip signal denote the position within the workpiece coordinate
system. The coordinates stored in variables from #5061 to #5066 are those existing when
skip signals were input during movement of the machine. These coordinates can therefore
be read at any time after that.
13-90
PROGRAM SUPPORT FUNCTIONS 13
Example 1: Workpiece position measurement:
The following shows an example of measuring the distance from a reference
measurement point to the workpiece end:
13-91
13 PROGRAM SUPPORT FUNCTIONS
N1 G91G28X0Y0
N2 G90G00X0Y0 –50
N3 X0Y–100.
N4 G31X–150.Y–50.F80 –75
N5 #111=#5061 #112=#5062
N6 G00Y0 –100
N7 G31X0
N8 #121=#5061 #122=#5062
N9 M02 –Y
Skip signal
MEP171
Variable #122 denotes the skip signal input coordinate of N4 since N7 does not have a Y-
command code.
16. TNo. (#51999) and Number of index (#3020) of the spindle tool
Variables numbered 51999 and 3020 can be used to read the tool number, and the number of
tool data index, of the tool mounted in the spindle. The number of index can be used, instead of
TNo., in reading the tool data of a particular tool with the aid of macro variables.
13-92
PROGRAM SUPPORT FUNCTIONS 13
Example:
TNo. #3022 setting Reading in #3023
1 A 1.01 21
2 B 2.02 24
3 C 3.03 40
4 A 4.61 31
5 B 5.62 34
6 C 6.63 35
7 H 7.08 15
8 V 8.22 18
9 Z 9.26 19
: : : :
: : : :
Failure – 0
Note: The number of tool data index undergoes changes by an exchange of data sets using
the [TOOL DATA MOVE] menu function on the TOOL DATA display. It is necessary,
therefore, to obtain the number of tool data index in order to correctly fetch a tool’s
information item from the TOOL DATA display with the aid of system variables.
Note 1: During tool path check, tool data can be read but cannot be written.
Note 2: Tool life flags (variables numbers of the order of #62000 or #620000) and tool damage
flags (likewise, the order of #63000 or #630000) can take either 1 or 0 as their logical
states (1 for ON, 0 for OFF).
Note 3: Tool life flags (variables numbers of the order of #62000 or #620000) only refer to tool
life management according to the tool’s application time.
13-93
13 PROGRAM SUPPORT FUNCTIONS
Note 1: During tool path check, tool data can be read but cannot be written.
Note 2: Tool life flags (variables numbers of the order of #42000 or #420000) and tool damage
flags (likewise, the order of #43000 or #430000) can take either 1 or 0 as their logical
states (1 for ON, 0 for OFF).
Note 3: The identification between number and amount of tool length offset or radius compen-
sation is made by referring to the tool data flag.
Example: If the date is December 15, 1995 and the time is 16:45:10, data is set as follows in
the corresponding system variables:
#3011 = 951215
#3012 = 164510.
13-94
PROGRAM SUPPORT FUNCTIONS 13
21. Total number of machined parts and the number of parts required
Variables numbered 3901 and 3902 can be used to read or assign the total number of machined
parts and the number of parts required.
Variable Nos. Description
#3901 Total number of machined parts
#3902 Number of parts required
Format:
SETVNn [NAME1, NAME2, .....]
Starting number of the variable to be named
Name of #n (Variables name)
Name of #n + 1 (Varaibles name)
Example: #3200 = 1;
Designation of the first significant axis setting (normally: X) within the system.
Variable Nos. S parameter
#3212 S12
13-95
13 PROGRAM SUPPORT FUNCTIONS
Use #5800 to read the number (1 to 7) of the currently selected data set for workpiece setup
error correction.
Note: An attempt to overwrite the system variable #5800 will only lead to an alarm (1821
UNWRITABLE SYSTEM VARIABLE).
13-96
PROGRAM SUPPORT FUNCTIONS 13
26. Work number of the main program (#4000)
Use variable #4000 to read the work number of the main program. The reading can also occur in
the same manner during execution on the TOOL PATH CHECK display.
O0010; O1000;
M99;
M30
Note 1: Only 8-digit natural numbers (1 to 99999999) can be read as they are. The reading is
always “–1” if there is any character other than arabic numerals (0 to 9) in the work
number.
Note 2: The reading cannot be done appropriately (is always “–1”) in the mode of tape
operation and MDI.
Note 3: This system variable is a read-only one.
Note 4: In the case of program chain (by M998) the work number of the main program chained
can be read as appropriate.
O0010; O0020;
O2000;
M30 “20” is read out as the
#100=#4000
work No. of the main
program.
M99;
13-97
13 PROGRAM SUPPORT FUNCTIONS
[1] Definition/replacement of
#i=#j Definition/replacement
variables
[2] Additional-type operations #i=#j+#k Addition
#i=#j–#k Subtraction
#i=#jOR#k Logical additon (For each of 32 bits)
#i=#jXOR#k Exclusive OR (For each of 32 bits)
[3] Multiplicative-type #i=#j#k Multiplication
operations #i=#j/#k Division
#i=#jMOD#k Surplus
#i=#jAND#k Logical product (For each of 32 bits)
[4] Functions #i=SIN[#k] Sine
#i=COS[#k] Cosine
#i=TAN[#k] Tangent (tanq is used as sinq/cosq.)
#i=ATAN[#j] Arc-tangent (Either ATAN or ATN can be used.)
#i=ACOS[#j] Arc-cosine
#i=SQRT[#k] Square root (Either SQRT or SQR is available.)
#i=ABS[#k] Absolute value
#i=BIN[#k] BINARY conversion from BCD
#i=BCD[#k] BCD conversion from BINARY
#i=ROUND[#k] Rounding to the nearest whole number (Either ROUND or
RND is available.)
#i=FIX[#k] Cutting away any decimal digits
#i=FUP[#k] Counting any decimal digits as 1s
#i=LN[#k] Natural logarithm
#i=EXP[#k] Exponent with the base of e (= 2.718 ...)
Note 1: In principle, data without a decimal point is handled as data that has a decimal point.
(Example: 1 = 1.000)
Note 2: Offsets from variable #10001, workpiece coordinate system offsets from variable
#5201, and other data become data that has a decimal point. If data without a decimal
point is defined using these variables numbers, therefore, a decimal point will also be
assigned to the data.
Example:
Common variable
#101=1000
#101 1000
#10001=#101 Execution #102 1.000
#102=#10001
1. Operation priority
Higher priority is given to functions, multiplicative operations, and additive operations, in that
order.
#101=#111+#112SIN[#113]
[1] Function
[2] Multiplicative
[3] Additional
13-98
PROGRAM SUPPORT FUNCTIONS 13
2. Specifying an operational priority level
The part to which the first level of operation priority is to be given can be enclosed in brackets
([ ]). Up to five sets of brackets, including those of functions, can be used for one expression.
#101=SQRT[[[#111–#112]SIN[#113]+#114]#15]
One fold
Two fold
Three fold
13-99
13 PROGRAM SUPPORT FUNCTIONS
13-100
PROGRAM SUPPORT FUNCTIONS 13
4. Operation accuracy
The errors listed in the table below are generated by one arithmetic operation, and the error rate
increases each time an operation is performed.
a=b+c
2.33 × 10–10 5.32 × 10–10 Min. ,
a=b–c c b
a=bc 1.55 × 10–10 4.66 × 10–10
a = b/c 4.66 × 10–10 1.86 × 10–9
Relative error
a
a= b 1.24 × 10–9 3.73 × 10–9
a = sin b
5.0 × 10–9 1.0 × 10–8
a = cos b Absolute error degree
a = tan–1 b/c 1.8 × 10–6 3.6 × 10–6
A. Addition/subtraction
As for additional-type operations, if an absolute value is subtracted from the other, the relative
–8
error cannot be reduced below 10 .
For example, when the true values (such values, by the way, cannot be substitued directly) of
#10 and #20 are as follows:
#10 = 2345678988888.888
#20 = 2345678901234.567
then #10 – #20 = 87654.321 would not result from calculation of #10 – #20. This is because,
since the effective number of digits of the variable is eight (decimal), the approximate values of
#10 and #20 are:
#10 = 2345679000000.000
#20 = 2345678900000.000
More strictly, internal binary values slightly differ from these values. Actually therefore, a
significant error results as follows:
#10 – #20 = 100000.000.
B. Logical relationship
As for EQ, NE, GT, LT, GE and LE, the processing is executed in a similar manner to addition
and substraction, so be careful to errors. For example, to judge whether #10 is equal to #20 of
the above example, the conditional expression
IF [#10EQ#20]
is not appropriate due to the errors. In such a case, therefore, give a macro-instruction as shown
below to allow for an acceptable tolerance in the judgement on the equality of two values.
IF [ABS[#10 – #20] LT200000]
C. Trigonometric functions
For trigonometric functions, although the absolute error is guaranteed, the relative error is not
–8
below 10 . Be careful, therefore, when carrying out multiplication, or division after trigonometric
function operations.
13-101
13 PROGRAM SUPPORT FUNCTIONS
1. Branching
Format: IF [conditional expression] GOTO n
where n is a sequence number in the same program.
The branching will occur to the block headed by sequence number ‘n’ if the condition holds, or if
the condition does not hold, the next block will be executed.
An independent setting of GOTO statement without IF [conditional expression] will perform
unconditional branching to the specified block.
For GOTO n, n must be a sequence number within the same program. If the sequence number
does not exist in that program, an alarm 843 DESIGNATED SNo. NOT FOUND will occur. An
expression or a variable can be used instead of #i, #j, or n.
Sequence number designation Nn must be set at the beginning of the destination block.
Otherwise, an alarm 843 DESIGNATED SNo. NOT FOUND will result. If, however, the block
begins with “/” and Nn follows, the program can be branched into that sequence number.
Note: During search for the branching destination sequence number, if the area from the
block after “IF ...” to the program end (% code) is searched (forward search) in vain,
then the area from the head down to the block before “IF ...” will be searched next
(backward search). It will therefore take more time to execute backward search
(searching in the opposite direction to the flow of the program) than to execute forward
search.
13-102
PROGRAM SUPPORT FUNCTIONS 13
2. Looping
Format:
WHILE [Condition expression] DOm (m = 1, 2, 3 127)
ENDm
The area from the next block to the ENDm block loops while the conditional expression holds. If
the conditional expression does not hold, control will be tansferred to the block after ENDm. In
the format shown above, DOm can precede WHILE.
You must always use WHILE [conditional expression] DOm and ENDm in pairs. If you omit
WHILE [conditional expression], the area from DOm to ENDm will endlessly loop. In DOm, m (1
to 127) identifies the number of looping. (DO1, DO2, DO3, and so on up to DO127)
The maximum available number of degrees of multiplicity is 27.
[1] Same identifying No. can be used repeatedly. [2] The identifying No. of WHILE DOm is arbitrary.
END1
Usable
END3
Usable
WHILE DO1 WHILE DO2
END2
Usable
END1
[3] Up to 27 levels of WHILE DOm can be used. [4] The total number of levels of WHILE DOm must not
m can be 1 to 127, independent of the depth of nesting. exceed 27.
WHILE DO1
WHILE DO1 DO1
WHILE DO2
WHILE DO2 DO2
WHILE DO27
WHILE DO27 DO27 WHILE DO28
Usable
END28 Unusable
END27
END27
END2
END2
END1
END1
13-103
13 PROGRAM SUPPORT FUNCTIONS
[5] WHILE DOm must precede ENDm. [6] WHILE DOm must correspond to ENDm one-to-one in the
same program.
WHILE DO1
END1
[7] WHILE DOm must not overlap. [8] Outward branching from the range of WHILE DOm is
possible.
WHILE DO1
WHILE DO1
END1
Usable END1
END2
Nn
[9] Branching into WHILE DOm is not allowed. [10] Subprogram can be called using M98, G65, G66, etc. from
the midway of WHILE DOm.
WHILE DO1
IF GOTOn Main program Subprogram
Unusable
IF GOTOn
WHILE DO1 WHILE DO2
WHILE DO1 END1
Unusable
G65 P100
Usable END2
WHILE DO1 To sub-
Nn program
END1
Nn M99
M02
END1
END1
[11] The looping can be independently programmed in a [12] If WHILE and END are not included in pairs in subprogram
subprogram which is called using G65/G66 from the (including macro subprogram), an alarm will result at M99.
midway of WHILE DOm. Up to 27 levels of nesting for
Main program Subprogram
both programs can be done.
M02 M99
G65 P100
Usable END1
To sub-
END1 program
Alarm 868 DO-END MIS-MATCH
M99
13-104
PROGRAM SUPPORT FUNCTIONS 13
13-12-7 External output commands (Output via RS-232C)
1. Overview
In addition to standard user macros, the types of macros listed below are provided as external
output commands. These external output macros can be used to output character data or the
numerical data in variables to an external unit via an RS-232C interface. The data are outputted
in a data length of 7 bits with an even-parity bit added.
B. Programming order
13-105
13 PROGRAM SUPPORT FUNCTIONS
Detailed description
- The command BPRNT can be used to output characters or to output variable data in binary
form.
- The designated character string is outputted directly in the ISO coded format. Alphanumerics
(A to Z, and 0 to 9) and/or special characters (+, –, , /) can be used. Of these characters, only
the asterisk () is outputted as a space code.
- Since all variables are saved as those having a decimal point, the necessary number of
decimal digits must be enclosed in brackets ([ ]).
All variables are handled as data of four bytes (32 bits), and each byte is outputted as binary
data in the order of the most significant byte first. Minus data is processed as the complement
for that data.
Example 1: If three digits are specified for 12.3456, then
3
[12.346 × 10 ] = 12346 (0000303A)
will be outputted as binary data.
Example 2: If no digits are specified for –100.0, then
–100 (FFFFFF9C)
will be outputted as binary data.
- After the specified data has been outputted, the EOB (End Of Block) code is outputted in the
format of the appropriate ISO code.
- Variables containing <empty> are interpreted as 0s.
13-106
PROGRAM SUPPORT FUNCTIONS 13
13-12-8 External output command (Output onto the local disk)
1. Overview
External output macros can also be used to output data in text file format into the predetermined
directory on the local disk.
2. Related parameters
- DPR14: Selection of an output destination port
Set DPR14 to “4” (Output onto the local disk) under OTHER on the DATA I/O PARAMETER
display.
- DPR15: Number of lines in feed section
Set the required number of lines to be fed.
- DPR8: Output file size
Use this parameter to specify the maximum permissible output file size.
Maximum permissible file size: DPR8 × 100 (KB)
A command for outputting a greater file will cause the alarm 1420 FILE SIZE LIMIT
EXCEEDED.
However, the file size limit is 100 KB if the value in DPR8 is 0.
Note: Output of a file of smaller size than the limit, however, may not be possible due to a
shortage of available area on the local disk.
The DATA I/O PARAMETER display can be selected by tapping the [DATA I/O PARAM.] menu
item on the DATA I/O display.
For further details of the parameters, refer to the separate Parameter List/
Alarm List/M-code List.
3. Output file
The text file will be automatically outputted with a particular file name into the predetermined
directory.
Output directory: c:\ymw\M8Y\data\MC_sdg\print\
Output file name: [Link]
(A file of this name will be automatically created, if required, or the text data
will be added to the current contents of the file.)
13-107
13 PROGRAM SUPPORT FUNCTIONS
File contents:
Given below on the right is an example of text file contents created by the execution of the
program shown on the left under the particular parameter settings.
POPEN %
DPRNT[OOOOOOOOOOOO] OOOOOOOOOOOO
DPRNT[XXXXXXXXXXXX] XXXXXXXXXXXX
DPRNT[IIIIIIIIIIII] IIIIIIIIIIII
PCLOS %
G0X100.Y100.Z100.
M30
[Parameter]
DPR14: 4
DPR15: No setting
4. Related alarms
The alarm given for text file output is described below.
13-108
PROGRAM SUPPORT FUNCTIONS 13
13-12-9 Precautions
Use of user macro commands allows a machining program to be created by combining arithmetic
operation, judgment, branchining, or other macro commands with conventional NC commands
such as move commands, M-, S-, T-commands, etc. The statement defined by these macro
commands and that of conventional NC commands are taken as a macro statement and an NC
execute statement, respectively. The treatment of a macro statement has no direct rerations with
machine control. Its treatment as short as possible is effective for shortening machining time.
Parallel processing of the NC execute statement and the macro statement becomes possible
according to the setting of bit 6 of parameter F93.
(It becomes possible to process all macro statements in batch form by setting the parameter bit
to OFF when machining the workpiece, or to execute the macro statements block-by-block by
setting the parameter bit to ON when checking the program. Therefore, set the parameter bit
according to your requirements.)
Sample program
N1 G91G28X0Y0Z0
N2 G92X0Y0Z0
N3 G00X–100.Y–100.
N4 #101=100.COS[210.] Macro statements
N5 #102=100.SIN[210.]
N6 G01X#101Y#102F800
A macro statement refers to a statement that consists of the following blocks:
- Arithmetic operation command block (compassing the equal sign =)
- Control command block (compassing GOTO, DO END, etc.)
- Macro call command block (compassing macro call or cancellation G-code commands G65,
G66, G66.1, or G67)
An NC execute statement refers to a non-macro statement.
13-109
13 PROGRAM SUPPORT FUNCTIONS
N1 N2 N3 N4 N5 N6 N7
Program analysis
Macroprogram statement N4 N5
Parameter treatment
OFF N2 N3 N6 N7
Next command
NC statement
treatment N1 N2 N3 N6
In execution
N1 N2 N3 N4 N5 N6 N7
Program analysis
N4 N5
Macroprogram statement
Parameter treatment
ON N2 N3 N4 N7
Next command
NC statement
treatment N1 N2 N3 N6
In execution
13-110
PROGRAM SUPPORT FUNCTIONS 13
13-12-10 Specific examples of programming using user macros
The following three examples of programming are shown here:
Example 1: SIN curve
Example 2: Bolt-hole circle
Example 3: Grid
Y (sin )
A: Initial value 0°
B: Final value 360° X
C: R of RSIN
0 90. 180. 270. 360.
F: Feed rate
–100.
MEP172
WHILE[#1LE#2]DO1
G65P9910A0B360.C100.F100
To subprogram #10=#3SIN[#1]
Note
G90G1X#1Y#10F#9
#1=#1+10.
END1
#1 = 0 M99
Local variable set
in argument #2 = 360.000
#3 = 100.000
#9 = 100.000
Note: G90G01X#1Y[#3SIN[#1]]F#9
makes one block command available.
13-111
13 PROGRAM SUPPORT FUNCTIONS
Main program –X x1
W
a1 : Start angle
G81Z–100.R50.F300 b1 : Hole quantity a1
To sub y1
G65P9920Aa1Bb1Rr1Xx1Yy1 r1 : Radius
program
x1 : X-axis center position
y1 : Y-axis center position –Y
MEP173
O9920
O9920 (Subprogram)
#120=#24+#18COS[#111]
Note
#121=#25+#18SIN[#111] No
#101 Hole END
quantity
#122=#120 #123=#121
IF[#102EQ90]GOTO100 Yes
END1 No
M99
#120 – #103 #122 #122 = X-axis incremental value
#121 – #104 #123 #123 = Y-axis incremental value
#120 #103 X-axis present position renewal
#121 #104 Y-axis present position renewal
#111 =
13-112
PROGRAM SUPPORT FUNCTIONS 13
–X –500. W
G28X Y Z
T1 M06
G90 G43 Z100. H01
G54 G00 X0 Y0
To subprogram
G81 Z-100. R3. F100 M03
G65 P9920X-500. Y-500. A0 B8R100.
G65 P9920X-500. Y-500. A30. B8R200.
G65 P9920X-500. Y-500. A60. B8R300. 100.
–500.
200.
300.
–Y
MEP174
Example 3: Grid
After hole data has been defined using fixed-cycle machining commands G72 to
G89, hole positions are to be designated using macro call commands.
MEP175
To subprogram –Y
G84 Z–90. R3. F250M03
G65P9930 X0 Y0 I–100. J–75. A5B3
–X
–100.
–Z
MEP176
13-113
13 PROGRAM SUPPORT FUNCTIONS
No
#105 > 0 N X direction hole drilling
WHILE[#105GT0]DO1 100 completion check
#101=#101+#113 Yes
#105=#105–1 Note
X#101Y#102 #101 + #113 #101 X coordinates renewal
#105 –1 #105 X direction hole quantity – 1
IF[#112EQ1]GOTO10
IF[#111NE1]GOTO10 X#101 Y#102 Drilling command
N10 #113=#103 No
END1 For even times (#111 = 0), X
No distance is same as command.
N100 #106=#106–1 #111 = 1 For odd times (#111 = 1), X-axis
#112=0 drilling direction reverse switch on
Note Yes
#110=#110+1
0 – #103 #103
IF[#106LT0]GOTO200
1 #112
#105=#1
N10
#102=#102+#104
Note
#111=#110 #103 #113 X-axis drilling distance reset
#111=#111AND1 N
100
GOTO2
#106 – 1 #106 Y-axis hole quantity – 1
N200 M99 0 #112 X-axis drilling direction reverse switch off
#110 + 1 #110 Y direction line count-up
13-114