Subprogram call (M98) and return (M99) in CNC Programming
📖 Scenario: You are programming a CNC machine to perform a drilling operation on multiple holes. To avoid repeating the same drilling commands, you will use subprogram calls with M98 and returns with M99.
🎯 Goal: Learn how to create a main CNC program that calls a drilling subprogram using M98 and returns from it using M99. This will help you write cleaner and more efficient CNC code.
📋 What You'll Learn
Create a main program that calls a subprogram using M98 P1000
Create a subprogram labeled O1000 that performs drilling commands
Use M99 in the subprogram to return to the main program
Print the program lines as output to simulate CNC code
💡 Why This Matters
🌍 Real World
Using subprogram calls and returns in CNC programming helps reduce code repetition and makes programs easier to maintain and modify.
💼 Career
CNC programmers and machinists use subprogram calls (M98) and returns (M99) daily to write efficient and modular CNC code for manufacturing parts.
Progress0 / 4 steps
1
Create the main CNC program header
Write the first three lines of the main CNC program exactly as follows: O0001 as the program number, G21 to set units to millimeters, and G90 for absolute positioning.
CNC Programming
Hint
Start your CNC program with a program number line like O0001. Then set units and positioning modes.
2
Add a subprogram call using M98
Add a line to the main program that calls the subprogram O1000 using M98 P1000. Then add a program end line M30.
CNC Programming
Hint
Use M98 P1000 to call subprogram O1000. End the main program with M30.
3
Create the drilling subprogram with M99 return
Write the subprogram O1000 that drills two holes at coordinates X10 Y10 and X20 Y20 using G81. End the subprogram with M99 to return to the main program.
CNC Programming
Hint
Start the subprogram with O1000. Use G81 drilling cycles for each hole. End with M99.
4
Print the complete CNC program
Print the entire CNC program stored in a variable called cnc_program to simulate sending it to the machine.
CNC Programming
Hint
Store the whole program as a string in cnc_program and print it.
Practice
(1/5)
1. What does the M98 command do in CNC programming?
easy
A. Stops the machine immediately
B. Ends the current subprogram and returns to the main program
C. Starts the spindle rotation
D. Calls a subprogram by its number, optionally repeating it
Solution
Step 1: Understand the role of M98
The M98 command is used to call a subprogram by its number and can repeat it multiple times if specified.
Step 2: Differentiate from M99
M99 is used to end a subprogram and return to the main program, not to call it.
Final Answer:
Calls a subprogram by its number, optionally repeating it -> Option D
Quick Check:
M98 calls subprogram [OK]
Hint: M98 calls subprogram; M99 returns from it [OK]
Common Mistakes:
Confusing M98 with M99
Thinking M98 stops the machine
Assuming M98 starts spindle
2. Which of the following is the correct syntax to call subprogram number 100 with 3 repetitions?
easy
A. M100 P98 L3
B. M98 P100 L3
C. M98 L3 P100
D. M99 P100 L3
Solution
Step 1: Identify correct M98 syntax
The correct syntax to call a subprogram is M98 followed by P (program number) and optionally L (repeat count), so M98 P100 L3 is correct.
Step 2: Check other options for errors
M99 is for return, not call; order matters; M100 is not a command.