G65 is a G-code command that is used to call a macro program in CNC machining. A macro program is a set of instructions that can perform complex or repetitive tasks, such as calculations, loops, conditional statements, and subroutines. Macros can be stored in the CNC machine’s memory or on an external device, such as a USB drive or a network server. Macros can be useful for simplifying the programming of CNC machines, reducing the number of lines of code, and increasing the flexibility and efficiency of the machining process.
Usage format
The general format of the G65 command is:
G65 Pxxxx Aaaa Bbbb Cccc ...
where:
Pxxxx
is the number of the macro program to be called. The number can be four or five digits, depending on the CNC machine’s configuration. For example,P1000
orP10000
.Aaaa
,Bbbb
,Cccc
, etc. are the arguments or parameters that are passed to the macro program. The arguments can be letters from A to Z, followed by numeric values. The number and meaning of the arguments depend on the macro program’s logic and purpose. For example,A10.5
orB-3.2
.- The G65 command can be followed by other G-code commands on the same line, such as
G00
,G01
,G02
, etc. The G65 command will be executed first, and then the following commands will be executed in sequence.
Explanation
When the CNC machine encounters a G65 command, it will look for the macro program with the specified number in its memory or on the external device. If the macro program is found, it will be executed with the given arguments. The macro program can contain any valid G-code commands, as well as special commands that are specific to macros, such as #
, IF
, WHILE
, GOTO
, etc. The macro program can also use local or global variables to store and manipulate data. The macro program will run until it reaches an M99
command, which indicates the end of the macro program. The CNC machine will then return to the main program and continue with the next command.
Example
Here is an example of a G65 command and a macro program that it calls. The G65 command is used to drill a series of holes along a circle with a given radius and angle increment. The macro program calculates the coordinates of each hole and moves the tool to the drilling position.
Main program:
N10 G90 G00 X0 Y0 Z5 ; Move to the center of the circle and 5 mm above the workpiece
N20 G65 P1000 R50 I10 ; Call macro program 1000 with radius 50 mm and angle increment 10 degrees
N30 G00 Z10 ; Move 10 mm above the workpiece
N40 M30 ; End of program
Macro program 1000:
O1000 ; Macro program number
#1 = #18 ; Store the radius in local variable #1
#2 = #19 ; Store the angle increment in local variable #2
#3 = 0 ; Initialize the angle in local variable #3
WHILE [#3 LT 360] DO1 ; Loop until the angle reaches 360 degrees
#4 = [#1 * COS[#3]] ; Calculate the X coordinate of the hole
#5 = [#1 * SIN[#3]] ; Calculate the Y coordinate of the hole
G00 X#4 Y#5 ; Move to the hole position
G81 Z-10 R2 F100 ; Drill the hole with canned cycle
#3 = [#3 + #2] ; Increment the angle
END1 ; End of loop
M99 ; End of macro program