Вы находитесь на странице: 1из 11

8-14 Sub Program Function

When there are a fixed command sequence or the repeat patterns are in the program, the
program can be simplified registering those on the CNC memory as the subprogram.

 Commanding method
 M98 P△△△ □□□□ ;
Subprogram number
Number of repetitions (3-digit commands are available)
This can be omitted for single call

Subprogram call

 M99 P□□□□ ;
 When this is commanded at the end of a subprogram, the program will return to the
sequence number specified with P in the main program.
 When this is commanded in the main program, the program will return to the sequence
number specified with P in the main program.

NOTICE
 Subprograms can be nested up to four levels.

 Subprogram can be called only in the MEMORY mode, and not be called in the

MDI mode.

 Program flow
<Main program> toward subprogram <Subprogram>
O2234 ; ① ② ③ O3234
N1 N1 ;
N2 N2 ;
N3 M98 P33234; N3 ;
N4; N4 99 ;
N5
N6M99;
toward the main program

8-103
8-15 Macro Program (G65G67)
By making a special program with storing a certain group of commands in the part
program memory. Those programs can be recall and executed with G65 or G66. This special
program is called a macro program. It is created and recorded in the same way as a
subprogram.

However, those following points are different from subprogram.


 "Variables" can be used.
 "Operations" can be performed on variables and constants.
 "Control commands" such as a conditional jump are possible.
These functions permit a macro program to produce a program that can be made complex
operations or judgments over a wide range of applications.
Specifying the arguments when calling a macro program from a main program allots the actual
values and numbers to the variable groups of the macro in the correct sequence. As a result, a
macro program is executed as a series of concrete programs that accompany tool movement.
In this manual, a macro program will sometimes be called a "macro".

8-104
 Macro program call command
There are five ways to call a macro program as shown in the table below.
No. Call method Code Remarks
1 Simple call G65
2 Modal call G66 G67:Cancel
3 Optional G code call G
4 M code call M
5 T code call T Maximum 4 digits
 Simple call (G65)
G65 P ・・・ L ・・・ <Argument assignment> ;
With the above command, the custom macro program that is specified with "P" will be called
and repeated as same numeral in "L".
If the "L" designation is omitted, the custom program will be executed one time.
If arguments must be specified in the macro program, use <argument designation>.
"Argument designation" refers to assigning a real number to the "local variables" used in the
macro program.
 Modal call (G66, G67)
G66 P ・・・ L ・・・ <Argument assignment> ;
With the above command, the macro program that is specified by "P" will be called and
repeated same numeral in "L". And this will be executed as per execution of movement
command.
G67 ;
This will cancel the modal call mode.

 Argument assignment
An argument is an actual value that is passed to the variable used in the macro program.
Therefore, the argument assignment is the allotment of the actual values to the macro
variables in the correct sequence. There are two types of argument assignment, typeⅠ and
typeⅡ, and they may be freely mixed.
 Argument assignment Ⅰ
Argument assignment is possible with all 21 addresses except G, L, N, O and P.
I, J and K only must be specified in alphabetical order, but other addresses are not specified
in alphabetical order.
 Argument assignment Ⅱ
In addition to the fact that arguments can be assigned in addresses A, B and C, a maximum
of ten sets of arguments can be set for addresses I, J and K. In this case, it is necessary to
specify the group in the order of I, J and K.

NOTICE
 Argument assignment types I and II can be freely mixed. If the same variable is
mistakenly specified in two arguments, the last specified is effective.
 In both types I and II, addresses I, J and K only must be specified in alphabetical order.
The order of assignment of the other addresses is free.
 Symbols and decimal points can be used in argument assignment for all addresses.
 Always command G65 or G66 before any argument assignment in a G65 or G66 block.

8-105
 Macro program summary
Combining the following command groups creates a macro program.
 Variables
 Local variables (#1~#33)
 Common variables (#100~#149, #500~#531)
 System variables (#1000~#5108)
 Operation commands
 Arithmetic operations (, , ,  ・・・・・・)
 Function operations (SIN, COS, ROUND,・・・・・・)
 Control commands
 Divergence commands (IF [<Conditional expression>] GOTO n)
 Iteration commands (WHILE [<Condition expression>] DO m)
These commands will permit the creation of programs that perform complex operations and
conditional judgments for a wide range of applications. It is therefore characteristic of a macro
program that it can program CNC functions themselves and then store them in the unit for use
with simple machining cycles similar to subprograms or particularly complex canned
machining cycles.

8-106
 Variables
When a macro program uses a variable instead of a numeric value directly passed to an
address, a call to this numeric value during execution will take the value stored in the variable
area and make it the address value.
Variables comprise local variables, common variables and system variables and can be
distinguished by their respective variable numbers. In the case of local variables, actual
numeric values can be passed with the argument assignment in the macro call commands G65
or G66.

 Local variables (#1#33)


The local variable is used locally in each individual macro.
This means that the variable area (#1#33) is maintained independently for each macro call,
and variables can store a certain value by argument assignment or by result of operations in
the macro. Therefore, even the same macro, variable #1, #2, #3,… can have different values at
different call times.
These local variables are reset at each macro call and recorded by argument assignment.
However, any unspecified variables will become empty. When the power is turned ON or the
machine is reset, then all local variables become <empty>.
(However, they will not be affected by the reset operation if parameter #6001-bit7=1)

8-107
 Common variables (#100#149, #500#531)
Common variables can be used commonly by all macros and all nesting macro levels.
This means it is possible to take a look the results of certain macro operations in other macro.
Common variables are classified into the following two types whose clear conditions differ from
each other.
 #100~#149: When power is turned ON, common variables are empty.
However, it will be empty even with RESET operation when setting the
parameter No.6001–bit6=0.
 #500~#531:Common variables are not cleared by the above mentioned method.

NOTICE
 Do not use the following macro variables because they are being used as a standard.
HEAD1 side: #139#149, #500, #515#531
HEAD2 side: #143, #145#149, #500

 System variables
The Following variables are determined with the system about their use.
 Interface input signal : #1000#1015, #1032
 Interface output signal : #1100~#1115, #1132, #1133
 Tool offset amount (wear amount): #2001#2032, #2101#2132, #2201#2232, #2301#2332,
#2401#2432, #2107#2732, #2801#2832, #2901#2932
 Alarm message display : #3000
 Clock : #3001, #3002, #3011, #3012
 Single block stop, auxiliary function completion wait control: #3003
 Feed hold, feed rate overrides, exact stop check control: #3004
 Number of part : #3901, #3902
 Modal data : #4001#4120
 Position data : #5001#5108

8-108
 Operation commands
Operation can be performed with or between variables and constants.
The operation formula is described as...
#i=<formula>
It is a general arithmetic operation, which combines variables and constants with arithmetic
operators or functions. The following operators or functions can be used, and constants can be
substituted for #j or #k in the following format.
 Definition and substitution of constants
#i = #j Definition, Substitution
#i = #〔#j + #k〕 Indirect specification
 Addition operation
#i = #j + #k Addition
#i = #j – #k Subtraction
#i = #j OR #k Logical sum (at every bit of 32 bits)
#i = #j XOR #k Exclusive Legal sum (at every bit of 32 bits)
 Multiplication operation
#i = #j  #K Product
#i = #j / #K Quotient
#i = #j AND #k Logical product (every bit in 32 bits)
 Functions
#i = SIN〔#j〕 Sine (degrees)
#i = COS〔#j〕 Cosine (degrees)
#i = TAN〔#j〕 Tangent (degrees)
#i = ATAN〔#j〕/〔#k〕 Arc Tangent
#i = SQRT〔#j〕 Square root
#i = ABS〔#j〕 Absolute
#i = BIN〔#j〕 Conversion from BCD to BIN
#i = BCD〔#j〕 Conversion from BIN to BCD
#i = ROUND〔#j〕 Integer formed by rounding down from .4 or up from .5
#i = FIX〔#j〕 Truncation of decimal portion
#i = FUP〔#j〕 Rounding up of decimal

8-109
 Control commands
There are 2 types of commands to control the flow of a macro program.
 Divergence commands: IF [<Conditional expression>] GOTO n;
 Iteration commands: WHILE [<Conditional expression>] DO m;
 Divergence commands
 IF [<Conditional expression>] GOTO n;
The use of this command with a conditional expression will execute a jump to the block with
sequence number n in the same program.
 The use of variables or expressions in place of n can change the block to which the program
jumps.
 If a condition is false, the program will go to the next block.

 A simple jump command is possible by omitting IF [<Conditional expression>].

EQ, NE, GT, LT, GE and LE can be used in conditional expressions and are written in the
table below.
Conditional expressions Meaning
#i EQ #j (#i =#j)
#i NE #j (#i≠#j)
#i GT #j (#i>#j)
#i LT #j (#i<#j)
#i GE #j (#i≧#j)
#i LE #j (#i≦#j)
Constants or <Expressions> can be used in place of #i or #j

8-110
 Repetition command
 WHILE [<Conditional expression>] DO m; (m=1, 2 or3)

END m;
This command repeats the block from [DO m] to [END m] so long as the conditional
expression is true.
If the condition is false, the program jumps to the next block after [END m].

 It repeats a program from [DO m] to [END m] infinitely when commanding the program
without WHILE [Conditional expression] command.

8-111
 Registration of macro programs
 Registration of macro programs
The method of registration and editing macro programs is identical with the case of the usual
part and subprograms.
Hence, there is no limit for macro programs. The sum of part programs, sub-programs and
macro programs will be stored up to the memory capacity limit of the part program.
 Program number usage classification
Program numbers are classified for the use according to the table below. Therefore select
them freely.

NOTICE
 Do not use the following program number because they are being used as a standard.
HEAD1 side: O9010,O9810,O9820
HEAD2 side: O9010,O9820,O9821

Program number
O0001O7999 Free recording, deletion and editing can be performed.
Setting the parameter No. 3202-bit0=1 can not execute the
O8000O8999
deletion and edition of program.
Setting the parameter No. 3202-bit4=1 can not execute the
O9000O9999
deletion and edition of program.

8-112
 NOTE
 Relation to MDI operation

The macro call can be specified in MDI mode too. However, it is impossible to call a

macro program by switching to the MDI mode during automatic operation.

 Relation to address search


A sequence number search within a macro program is impossible with address search.

 Relation to SINGLE BLOCK


Even while a macro program is being executed, blocks can be stopped in the SINGLE BLOCK

mode (except blocks containing macro call commands, arithmetic operation commands,
and control commands). A block containing a macro call command (G65, G66 or G67) does not
stop even when the single block mode is on. Blocks containing arithmetic operation
commands and control commands can be stopped in single block mode by setting the parame-
ter (No.6000-bit5=1).
Note that when a single block occurs at a macro statement in tool nose radius compensation
mode, the statement is assumed to be a block that does not involve movement, and proper
compensation cannot be performed in same cases. (Strictly speaking, the block is regarded as
specifying a movement with a travel distance 0.

 Relation to optional block skip


A "/" appearing in the middle of an <expression> (enclosed in brackets [ ] on the right-hand
side of an arithmetic expression) is regarded as a division operator; it is not regarded as the
specified for an optional block skip code.

 Relation to feed hold


When feed hold is enabled during execution of a macro statement the machine stops after
execution of the macro statement. The machine also stops when a reset or alarm occurs.

 Relation to multiple repetitive canned cycle


Macro cannot be used in the multiple repetitive canned cycles (G71, G72 and G73).

 Nesting
 Maximum 4 level macro calls is possible.
 Maximum 8 level subprogram calls are possible with macro calls.
 Maximum 3 level WHILE-DO repeats sequences are possible.
 Maximum 5 level formula [ ] is possible.

8-113

Вам также может понравиться