Mastering CNC Programming: The Ultimate Guide to M99 Instruction
In the world of computer-aided manufacturing, CNC (Computer Numerical Control) programming is a technology used to control automatic machining of machine-tools. In this guide, we’ll delve into the world of CNC programming, exploring the basics, the G-code language, and the M99 instruction that ends a loop in a CNC program.
Introduction to CNC Programming
CNC programming is a technology widely used in the manufacturing industry, allowing machine tools to automatically treat parts according to predefined procedures. CNC programming is generally written using code G (CNC programming language). The M99 instruction is an important part of the G-code, ending a loop.
CNC Programming Basics
Before diving into the M99 instruction, it’s essential to understand the basics of CNC programming.
1.2 Machine-Tool CNC
CNC machine tools are machines that can automatically treat parts depending on predefined programs. They are widely used in manufacturing industries, particularly in the transformation of metals, plastic, wood, etc.
2.2 G Code
G Code is a programming language used for CNC programming. It consists of a series of letters and numbers to control the movement and operation of the tool-tool. G codes can be divided into two categories: code G0 (preparation function) and code G1 (linear interpolation).
2.3 Loop
In CNC programming, loops are a common programming structure used to perform a piece of code several times. Loops can be implemented using the G80 instructions (cancel loop) and M99 (end loop) in code G.
M99 Command
The M99 instruction is used to end the loop. In CNC programming, M99 is generally used with the G80 instructions (cancel loop) to obtain loop control.
3.1 Instruction Format M99
The format of the M99 instruction is as follows:
M99
3.2 The Role of Instruction M99
The function of instruction M99 is to end the current loop. When the CNC system meets an instruction M99, it ceases to execute the current loop and continues to execute the next part of the program.
Defining the Number of Cycles
In CNC programming, we can use the M99 instruction to define the number of loops. Here are some ways to define the number of loops:
4.1 Use the G80 and M99 Instructions
In the CNC programming, we can use the G80 instruction to cancel the loop and use the M99 instruction to end the loop. Here is an example:
N10 G00 x0 Y0
N20 G01 X10 Y10
N30 M99
In this example, we first use the G00 instruction to move the machine to the starting position (X0, Y0). Then, we use the G01 instruction to move the machine to the target position (X10, Y10). Finally, we end the loop using the M99 instruction.
4.2 Use of Variables and Calculations
In CNC programming, we can also use variables and calculations to define the number of loops. Here is an example:
100 = 5
N10 G00 x0 Y0
N20 #101 = [#100*2]
N30 WHILE [#101 GT 0] Make 1
N40 G01 X10 Y10
N50 #101 = #101 – 1
N60 M99
In this example, we first defined the number of loops as 5 using the variable #100. We then use the WHILE LOOP variable and #101 to control the execution of the loop. In each loop, we use the G01 instruction to move the machine to the target position (X10, Y10). We also use the variable #101 to update the number of loops and use the M99 instruction at the end of the loop.
Practical Applications of Loop Definition
In CNC programming, the definition of the number of cycles can be used to implement various complex machining tasks. Here are some examples of practical applications:
5.1 Drilling
In drilling, we can use loops to repeat the drilling operation. By defining the number of cycles, we can control the number of holes pierced.
5.2 Milling
In milling, we can use loops to repeat the milling operation. By defining the number of cycles, we can control the depth or width of the milling.
5.3 Engraving
In engraving, we can use loops to repeat the engraving operations. By defining the number of cycles, we can control the accuracy and complexity of the engraving.
In conclusion, the M99 instruction is a crucial part of CNC programming, used to end a loop and control the execution of a series of instructions. By mastering the concepts of CNC programming, loops, and the M99 instruction, you can effectively control complex machining tasks and achieve precise results in various manufacturing industries.


















