How to Add a Custom M-Code on a FANUC CNC: PMC Ladder Workflow
A practical engineering overview of the network connection, unused PMC addresses, M-code decoding, execution latch and FIN completion handshake used when integrating auxiliary equipment with a FANUC-controlled machine.
Safety notice: PMC ladder and machine I/O changes can cause unexpected motion, equipment damage or loss of safety functions. Back up the machine first and have the exact machine-builder electrical drawings reviewed by a qualified controls engineer.
When a custom M-code is useful
A custom M-code lets a CNC program command auxiliary equipment through the machine PMC. Probe power, air blast, part clamping and inspection peripherals are common examples, but the exact implementation is machine-builder specific.
The general sequence is decode the commanded M-code, energize or latch the required output, then return the completion signal so the CNC program can continue.
1. Back up and identify the exact control
Before editing, record the FANUC control series and software version, machine model, PMC type and ladder password or protection state. Export the current ladder, parameters, keep relays and relevant SRAM/PMC data using the machine builder's approved procedure.
- Obtain the machine electrical schematic and I/O allocation table
- Confirm whether online ladder editing is permitted
- Identify safety-related rungs that must never be altered
- Plan a controlled test with spindle, axes and actuators made safe
2. Connect FANUC LADDER-III
The source workflow uses an Ethernet connection between the service computer and CNC, then adds the CNC as a host in FANUC LADDER-III. One example uses CNC address 192.168.1.1, service-PC address 192.168.1.2 and TCP port 8193.
Those values are examples, not universal settings. Use an unused subnet approved for the machine network, confirm the CNC communication parameters, and avoid changing a production network without authorization.
3. Allocate unused internal and physical I/O addresses
Locate an unused internal relay address in the PMC address map and verify that it is not written anywhere else in the ladder. Then identify an unused physical output from the electrical drawings and terminal map.
Never infer an X or Y address from a generic table alone. Connector pinout, source/sink logic, common wiring and output capacity differ by machine and I/O module. Test the chosen point with the machine isolated and observe it in PMC diagnostics before connecting equipment.
4. Build the three ladder functions
A typical custom M-code implementation has three logical parts. The decode rung recognizes the requested M-code and sets an internal relay. The execution rung uses that relay to drive or latch the auxiliary output. The completion rung returns the appropriate FIN handshake after the command has completed.
- Decode: map the selected M-code to a dedicated, verified internal relay
- Execute: control the physical output with interlocks, reset conditions and fault handling
- Complete: issue FIN only when the requested state is safely achieved
- Document every new address and add clear ladder comments
5. Validate, store and monitor
Compile and check the edited ladder before transfer. During a controlled maintenance window, update the PMC, monitor the affected rungs and verify the output without running an automatic production cycle.
An online edit may reside only in volatile memory until it is stored to ROM. Follow the control- and machine-specific save procedure, then perform a restart check and confirm that alarms, emergency stops, interlocks and the M-code completion handshake behave correctly.
Commissioning checklist
- Original ladder and machine data can be restored
- New internal relay and output addresses have no conflicts
- Output defaults to a safe state at power-up and reset
- Cycle start waits for the correct completion condition
- Timeout and alarm behavior are defined for peripheral failure
- Single-block, reset, emergency stop and restart cases are tested
- Final ladder, I/O table and change record are archived
Frequently Asked Questions
Is TCP port 8193 correct for every FANUC control?
No. It appears in the supplied example, but the correct connection method and port depend on the control, options and network configuration.
Can any unused Y address be assigned?
No. The output must be confirmed against the machine-builder electrical drawings, connector wiring, common voltage and I/O module capacity.
Why is the FIN signal important?
FIN tells the CNC that the M function has completed. An incorrect handshake can stall the program or allow it to continue before the auxiliary action is safe.
