What does the P CNC code do?
The P code is used for multiple uses in CNC programming.
Those uses depend on which other codes the P code is combined with.
The four uses of the P code are selecting a subprogram, setting a dwell time, selecting an offset number, and setting a scale factor.
The most common uses of the P code are to select a subprogram and to set dwell times.
Subprogram number when choosing a subprogram with M97 or M98
Subprograms are a separate CNC program selected to run from within another program.
They are used to perform repetitive machining operations or sequences such as drilling, counterboring and countersinking a hole.
CNC machines run the lines of code in a program in order.
Using subprograms allows the programmer to jump around to different sections of the current program or to run a different program and come back to the current program.
This will either be a specific line in the current program (M97) or an entirely different program (M98).
Learn CNC Programming – It’s Easier Than You Think!
Learning G Code doesn’t have to be difficult…
If you know what to focus on.
Join our simple, easy-to-follow course, “G Code Made Easy: CNC Programming for Beginners“. We walk you through all the important codes – with simple explanations and real-world examples.
Want to become a super-skilled CNC programmer? Join now to take the shortcut to becoming a G Code Master today!Make Learning G Code Easy
The P code when using M97 [subprogram call by line]
M97 P1234 L5
This line of code will tell the machine to move to line N1234 of the current program.
The L code tells the CNC machine to run the subprogram five times. The L code can be left out if the subprogram will only be run once.
Line 1234 will be after the program end command (M30). Once the machine reaches the M99 command it will return to the line after the example shown above.
The P code when using M98 [subprogram call by program number]
M98 P5678 L2
This line of code will tell the machine to go run program number 5678 two times.
The L code tells the CNC machine to run the subprogram twice. The L code can be left out if the subprogram will only be run once.
The M99 command will make the machine return to the line after the example shown above.
On the other hand, both commands (M98 and M97) use parameters K (or L) as the number of repetitions of a given subprogram.
The use of the letter K or L depends on the CNC model. Always check the machine’s manual for further details.
Dwell time with G04
Another use of the P code is to set a dwell time.
A G04 code makes the cutting tool stop moving for specified amount of time. Following that amount of time, the machine will proceed to the next line of code.
There are some variations between machines when using G04.
Not all machines will use the P code to set the dwell time.
Some CNCs use either F, U or X instead of P.
Also, some machines will read the value after the P code as seconds and some will read it as milliseconds.
1 second = 1,000 milliseconds.
So P300 could mean 300 seconds (5 minutes) or 0.3 seconds depending on how your CNC reads the code. Makes sure to verify how you machine will read the P code when using the G04 command.
Dwell time with G82 and G89
G82 [drill cycle with dwell] and G89 [boring cycle with dwell] are both canned cycles with dwells.
Similar to the G04 command, G82 and G89 both use the P code to specify how long to stop and wait at the bottom of the hole.
Usually this time is in milliseconds. Machines vary though so make sure your machine isn’t reading the P code as full seconds.
Fixture offset number with G10
Using the P code with G10 tells the machine which fixture offset to change.
Below is a list of the values used with the P code and which fixture offset they correspond to:
Scale factor with G51
CNC programs can be scaled up or down using the G51 command.
The P code is used to set the scaling factor when used with G51.
This means that a P2 code will tell the machine to make everything in the program 2x larger.
On the opposite end, a P0.5 code will tell the machine to make everything half the normal size.
The P code can be used in many different ways when CNC programming.
Using the P code to select a subprogram is pretty much universal across the different CNC machine manufacturers.
The other uses of the P code are less standard.
At times the CNC will read the code different such as seconds vs. milliseconds or it will require a different code altogether such as in the case of dwell times with G04.
Make sure you check your individual machine to understand the requirements of your individual CNC.