A subprogram is a separate block of code that performs a specific task and can be called multiple times within the main program to repeat patterns without rewriting the code.
Click to reveal answer
beginner
Why use subprograms for repeated patterns in CNC?
Using subprograms saves time and reduces errors by reusing code for repeated shapes or movements, making the program shorter and easier to maintain.
Click to reveal answer
beginner
How do you call a subprogram in CNC code?
You call a subprogram using the M98 command followed by the subprogram number, for example, M98 P1000 calls subprogram O1000.
Click to reveal answer
beginner
What is the purpose of the M99 command in a subprogram?
M99 ends the subprogram and returns control back to the main program to continue execution after the subprogram call.
Click to reveal answer
intermediate
How can you repeat a subprogram multiple times?
You can repeat a subprogram multiple times by adding the L parameter to M98, for example, M98 P1000 L5 calls subprogram O1000 five times.
Click to reveal answer
Which command is used to call a subprogram in CNC?
AM98
BM30
CM99
DG00
✗ Incorrect
M98 is the command used to call a subprogram by specifying its program number.
What does the M99 command do in a subprogram?
AStarts the subprogram
BEnds the subprogram and returns to main program
CCalls another subprogram
DStops the machine
✗ Incorrect
M99 ends the subprogram and returns control to the main program.
How do you repeat a subprogram 3 times?
AM98 P1000 L3
BM98 P1000 R3
CM99 P1000 L3
DM30 P1000 L3
✗ Incorrect
The L parameter with M98 specifies how many times to repeat the subprogram.
Why use subprograms for repeated patterns?
ATo make the program longer
BTo slow down the machine
CTo avoid repeating code and reduce errors
DTo confuse the operator
✗ Incorrect
Subprograms help reuse code, making programs shorter and easier to maintain.
What is the correct format to define a subprogram named 1000?
AG00 O1000 ... M99
BM98 P1000 ... M30
CO1000 ... M30
DO1000 ... M99
✗ Incorrect
Subprograms start with O followed by the number and end with M99.
Explain how subprograms help in CNC programming for repeated patterns.
Think about how you avoid writing the same instructions many times.
You got /4 concepts.
Describe the commands used to call and end a subprogram in CNC code.
Focus on the commands that start and finish the subprogram.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using a subprogram in CNC programming?
easy
A. To stop the machine immediately
B. To speed up the machine spindle
C. To change the tool automatically
D. To repeat a set of instructions multiple times without rewriting them
Solution
Step 1: Understand subprogram concept
Subprograms are blocks of code that can be reused multiple times in CNC programming.
Step 2: Identify main purpose
They help avoid rewriting the same instructions repeatedly, making code shorter and easier to manage.
Final Answer:
To repeat a set of instructions multiple times without rewriting them -> Option D
Quick Check:
Subprograms repeat code = D [OK]
Hint: Subprograms repeat code blocks to save writing [OK]
Common Mistakes:
Confusing subprograms with tool changes
Thinking subprograms control spindle speed
Assuming subprograms stop the machine
2. Which of the following is the correct syntax to call a subprogram numbered 100 in CNC code?
easy
A. M99 P100
B. M98 P100
C. M100 P98
D. M98 L100
Solution
Step 1: Recall subprogram call command
M98 is the standard command to call a subprogram in CNC programming.
Step 2: Match syntax with subprogram number
The correct syntax is M98 followed by P and the subprogram number, e.g., M98 P100.
Final Answer:
M98 P100 -> Option B
Quick Check:
Call subprogram = M98 P[number] [OK]
Hint: Use M98 P[number] to call subprograms [OK]
Common Mistakes:
Using M99 to call instead of return
Swapping M98 and M99 commands
Using L instead of P for subprogram number
3. Given the following CNC code snippet, what will be the output movement commands executed?
C. L0 causes no repetition, so subprogram never runs
D. Missing G00 command before M98
Solution
Step 1: Check repetition count in subprogram call
L0 means repeat zero times, so the subprogram is not executed at all.
Step 2: Confirm other commands are correct
M99 is correct to return from subprogram, P2000 is valid, and G00 is not mandatory before M98.
Final Answer:
L0 causes no repetition, so subprogram never runs -> Option C
Quick Check:
L0 means zero repeats = B [OK]
Hint: L0 means no repeats, so subprogram won't run [OK]
Common Mistakes:
Thinking M99 is wrong inside subprogram
Assuming P2000 is invalid
Believing G00 is required before M98
5. You want to drill 5 holes spaced 10mm apart along the X-axis starting at X0 Y0 using a subprogram. Which code snippet correctly uses a subprogram with a loop to achieve this?