Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
How to Convert Excellon Drill Files to G-Code: Complete Guide for PCB Prototyping
When I first started milling PCBs on my CNC router, I assumed the drilling part would be simple. Export a drill file from KiCad, load it into my machine, and watch the holes appear. Reality was different. My CNC controller had no idea what to do with an Excellon file. It needed G-Code, and bridging that gap turned out to be more nuanced than I expected.
This guide covers everything you need to know about converting Excellon drill files to G-Code, from understanding the file format itself to generating optimized drilling programs for your CNC machine.
Understanding Excellon Drill Files
Before jumping into conversion, it helps to understand what you are actually working with. An Excellon drill file is a text-based format that describes where holes should be drilled on a PCB, along with the drill bit sizes required. The format was developed by Excellon Automation, which dominated the PCB drilling equipment market in the 1980s and became the de facto industry standard.
What Information Does an Excellon File Contain?
Every Excellon file includes several critical pieces of data:
Header information specifies the measurement units (inches or millimeters), coordinate format, and zero suppression method. This metadata is essential for correctly interpreting the coordinate values that follow.
Tool definitions list each drill bit required, identified by a tool number (T01, T02, etc.) and its diameter. A typical PCB might require anywhere from 3 to 20 different drill sizes depending on the component mix.
Hole coordinates provide the X and Y locations for every hole, grouped by tool number. When the drilling machine encounters a tool change command, it knows all subsequent coordinates use that specific drill diameter.
Excellon File Structure Example
Here is what a basic Excellon drill file looks like when opened in a text editor:
The M48 command signals the start of the header. METRIC tells us coordinates are in millimeters, and LZ indicates leading zero suppression. Each T line followed by a C value defines a tool and its diameter. After the % symbol, the actual drilling data begins, with coordinates grouped under each tool selection.
Why Excellon Files Need Conversion to G-Code
CNC machines speak G-Code, a standardized language that provides explicit movement instructions including axis positions, feed rates, spindle speeds, and various machine control commands. While Excellon files contain position data, they lack the operational parameters your CNC needs.
A proper drilling G-Code file includes:
Spindle start commands (M3) with specified RPM (S parameter), rapid positioning moves (G0) to travel height, controlled feed moves (G1) for actual drilling, retract commands back to safe height, and tool change sequences when switching drill bits.
The conversion process transforms the compact Excellon format into verbose G-Code that tells your machine exactly how to execute each drilling operation.
Software Options for Excellon to G-Code Conversion
Several tools handle this conversion, ranging from full-featured CAM applications to simple command-line utilities.
Software
Type
Platform
Cost
Best For
FlatCAM
CAM Application
Windows, Linux, Mac
Free
Complete PCB workflows
pcb2gcode
Command Line
Linux, Mac, Windows
Free
Automated batch processing
drl2gcode
Python Script
Any with Python
Free
Simple conversions
CopperCAM
CAM Application
Windows
€80
Ease of use
Carbide Copper
Web-Based
Browser
Free
Quick simple boards
PCB-GCode
Eagle ULP
Eagle only
Free
Eagle integration
FlatCAM: The Most Complete Solution
FlatCAM has become the go-to choice for hobbyist PCB milling because it handles the entire workflow from Gerber and Excellon files through to G-Code output. For drill file conversion specifically, FlatCAM reads your Excellon file, displays the hole locations visually, and generates drilling G-Code with your specified parameters.
The software runs on all major operating systems and provides both a graphical interface and a command-line shell for automation. One particularly useful feature is the ability to combine multiple drill sizes into a single operation if you plan to use one drill bit for everything, or keep them separate for proper tool changes.
pcb2gcode: Power Through Command Line
For those comfortable with terminal commands, pcb2gcode offers excellent control through a configuration file that stores all your parameters. You define your drilling settings once, then convert files with a single command. This approach works well when you have established parameters for your machine and want consistent results without clicking through interface options each time.
Dedicated Conversion Scripts
Several standalone Python and Bash scripts exist specifically for Excellon to G-Code conversion. The drl2gcode script on GitHub, for example, takes an Excellon file and outputs separate G-Code files for each drill tool, with configurable spindle speed, feed rates, and drilling depth. These lightweight tools work well when you need a simple solution without the overhead of a full CAM application.
Step-by-Step Guide: Converting Excellon to G-Code with FlatCAM
Let me walk through the complete process using FlatCAM, as it provides visual feedback that helps catch problems before they reach your machine.
Step 1: Exporting Your Excellon File Correctly
Before opening FlatCAM, ensure your PCB design software exports the Excellon file with proper settings.
For KiCad: Go to File, then Fabrication Outputs, then Drill Files. Select Excellon as the format, use millimeters or inches consistently with your project, set the coordinate format to decimal, and choose your board origin point. Click Generate Drill File.
For Eagle: Run the CAM Processor and select the Excellon drill output. Ensure the units match your design and the coordinate precision is adequate for your machine.
Critical settings to verify: The measurement units (METRIC or INCH in the header), zero suppression format (leading or trailing), and coordinate format (typically 2:4 or 3:3 for integer and decimal places) must be correct or your holes will end up in wrong locations or at wrong scales.
Step 2: Importing into FlatCAM
Open FlatCAM and use File, Open Excellon to load your drill file. The software parses the file and displays the hole locations in the plot window. Small circles indicate drill positions, with different colors often representing different tool sizes.
Take a moment to verify what you see matches your PCB design. If holes appear clustered in one corner or the board seems extremely small or large, you likely have a units or format mismatch. FlatCAM allows you to scale and offset the imported data to correct such issues.
Step 3: Reviewing Tool Information
With your Excellon file selected in the Project panel, look at the tool list. FlatCAM shows each tool number with its diameter and the count of holes using that tool. This information helps you prepare the correct drill bits for your machine.
Common hole sizes in PCB work include 0.6mm for small vias, 0.8mm for standard through-hole component leads, 1.0mm for larger component pins, and various sizes up to 3mm or more for mounting holes.
Step 4: Configuring Drilling Parameters
The critical parameters for drilling G-Code generation are:
Cut Z (Drill Depth): How far below the surface the drill plunges. This should exceed your PCB thickness plus any backing material. For a 1.6mm board on a spoilboard, setting Cut Z to -2.5mm or -3mm ensures complete penetration.
Travel Z (Safe Height): The height for rapid moves between holes. Set this high enough that the drill clears any clamps or uneven board surfaces, typically 2mm to 5mm above the PCB.
Feed Rate: The plunge speed during actual drilling, specified in your project units per minute. For carbide PCB drill bits in FR4 material, typical values range from 30 to 100 mm/min depending on hole size and machine rigidity.
Spindle Speed: The RPM setting for your spindle. Small PCB drills often run between 8,000 and 30,000 RPM. If your machine lacks spindle speed control, you may need to add or remove this command from the output.
Step 5: Generating the CNC Job
Select which tools to include in your drilling operation. You can generate a single G-Code file that includes tool change commands for each drill size, or create separate files per tool if your workflow handles them independently.
Click Generate to create the CNC Job object. FlatCAM adds this to your project and shows the drilling sequence visually. Review the toolpath to ensure it looks reasonable.
Step 6: Exporting G-Code
With the CNC Job selected, click Export G-Code and save the file. Open it in a text editor to verify the output makes sense for your machine.
A typical drilling G-Code sequence looks like this:
gcode
G21 (Units: millimeters)G90 (Absolute coordinates)G94 (Feed rate mode)M3 S10000 (Spindle on at 10000 RPM)G4 P1 (Dwell 1 second)G0 Z2.0000 (Rapid to safe height)G0 X8.5000 Y4.8000 (Rapid to first hole)G1 Z-2.5000 F50 (Drill down)G0 Z2.0000 (Retract)G0 X8.5500 Y2.8500 (Next hole)G1 Z-2.5000 F50G0 Z2.0000…M5 (Spindle off)M30 (Program end)
Recommended Drilling Parameters for PCB Work
Getting your speeds and feeds right prevents broken bits and ensures clean holes. Here are parameters that work well for typical desktop CNC machines and carbide PCB drill bits:
Feed Rates by Drill Diameter
Drill Size
Plunge Feed Rate
Spindle Speed
0.4 – 0.6 mm
20 – 40 mm/min
15,000 – 25,000 RPM
0.7 – 0.9 mm
40 – 60 mm/min
12,000 – 20,000 RPM
1.0 – 1.5 mm
60 – 100 mm/min
10,000 – 15,000 RPM
1.6 – 2.5 mm
80 – 150 mm/min
8,000 – 12,000 RPM
2.6 – 3.5 mm
100 – 200 mm/min
6,000 – 10,000 RPM
These are starting points. Adjust based on your specific machine, spindle, and bit quality.
Safe Height and Depth Settings
Parameter
Typical Value
Notes
Travel Z
2.0 – 5.0 mm
Clear of clamps and board warpage
Cut Z
-(PCB thickness + 1 mm)
Ensure complete penetration
Peck Depth
Not usually needed
FR4 drills cleanly in single plunge
Common Problems and Solutions
Holes in Wrong Locations
This almost always indicates a units or format mismatch. Check that your Excellon file header specifies METRIC or INCH correctly and that FlatCAM interprets it as expected. The coordinate format (number of integer and decimal places) must also match between the export and import settings.
Holes Wrong Size
The Excellon file specifies tool diameters, but your G-Code only positions the drill. If holes come out wrong, verify your physical drill bits match the tool definitions. Also check that your spindle has minimal runout, as excessive wobble effectively enlarges the hole.
Drill Breaking
Small carbide drills are brittle. Common causes of breakage include plunging too fast (reduce feed rate), hitting the spoilboard too hard (verify your Z zero and depth settings), pecking when not needed (single-pass drilling works fine for thin PCBs), and worn or chipped bits (inspect under magnification).
Incomplete Holes
If the drill does not penetrate completely through the board, increase your Cut Z depth. Account for any air gap between the PCB and spoilboard, variations in board thickness, and the drill point angle which extends beyond the cut depth.
Advanced Techniques
Optimizing Hole Order
The sequence in which holes are drilled affects total machining time. Some CAM software automatically optimizes the drilling order to minimize travel distance between holes. If yours does not, you can often improve efficiency by grouping nearby holes and using a traveling salesman algorithm approach.
Tool Change Strategies
When your design requires multiple drill sizes, you have options. You can generate one G-Code file with tool change commands (M6) at each size transition, which requires your machine to support programmatic tool changes. Alternatively, generate separate files per tool and run them sequentially with manual bit swaps between operations.
Auto-Leveling for Drilling
While auto-leveling is more commonly associated with isolation milling, it can help drilling too. If your PCB is not perfectly flat, probing the surface and adjusting Z coordinates ensures consistent penetration depth across the board. Software like bCNC supports this functionality.
Useful Resources and Tools
CAM Software Downloads
FlatCAM is available at flatcam.org with documentation, tutorials, and downloads for Windows, Linux, and Mac systems.
pcb2gcode source code and binaries are hosted on GitHub at github.com/pcb2gcode/pcb2gcode with detailed parameter documentation.
The drl2gcode Python script can be found at github.com/jes/drl2gcode for straightforward Excellon conversion.
G-Code Senders and Simulation
Universal G-Code Sender (UGS) at winder.github.io/ugs_website provides reliable G-Code streaming to GRBL-based controllers.
Camotics at camotics.org offers free G-Code simulation so you can verify your drilling program before cutting.
Reference Documentation
The Excellon format specification explains coordinate formats, commands, and header options in detail.
PreciseBits at precisebits.com/reference/drillfeedspeed.htm publishes feed and speed tables specifically for PCB carbide drills.
Frequently Asked Questions
What is the difference between Excellon and G-Code?
Excellon is a specialized format for specifying drill hole locations and sizes in PCB manufacturing. It contains coordinate data organized by tool number but lacks machine control instructions. G-Code is a general-purpose CNC programming language that provides complete machine instructions including movement commands, feed rates, spindle control, and coordinate positioning. Converting Excellon to G-Code adds the operational parameters needed to actually execute the drilling on a CNC machine.
Can I drill all holes with one bit size?
Technically yes, but it creates problems. Using an oversized bit for small holes produces sloppy connections and may damage delicate pads. Using an undersized bit for large holes means component leads will not fit. For prototyping, you might compromise by grouping similar sizes and using the closest available bit, but proper hole sizes improve both assembly ease and electrical reliability.
Why do my Excellon coordinates seem wrong when imported?
The most common cause is mismatched coordinate format interpretation. Excellon files use either leading or trailing zero suppression, and the number of integer versus decimal places varies. If your CAD exports as 2:4 format (two integer, four decimal places) but your CAM reads it as 3:3, coordinates will be off by factors of ten. Always verify the format settings match between export and import.
Do I need peck drilling for PCBs?
Generally no. Standard FR4 PCB material is only 1.6mm thick, and carbide drill bits can plunge through in a single pass without chip evacuation problems. Peck drilling (retracting partially to clear chips, then continuing) adds cycle time without benefit for thin materials. Reserve pecking for unusually thick boards or when drilling mounting holes through additional material beneath the PCB.
How do I handle multiple drill sizes on a manual tool change machine?
Export separate G-Code files for each tool size, labeled clearly with the required drill diameter. Run them in sequence, changing bits between files. Set your Z zero consistently after each tool change, either by re-probing or using a fixed-length tool holder. Some users create a tool change pause command (M0 or M6 with dwell) within a single file and manually swap bits when the machine stops.
Conclusion
Converting Excellon drill files to G-Code connects your PCB design to your CNC machine. While the concept is straightforward, getting the details right determines whether your holes land accurately and your bits survive the job.
Start with FlatCAM or a similar CAM tool to visualize your drilling data and configure parameters through a graphical interface. As you gain experience, command-line tools like pcb2gcode offer faster workflows for repeated operations. Pay attention to coordinate formats when exporting from your PCB software, and always verify the imported data looks correct before generating G-Code.With proper conversion settings and reasonable drilling parameters, your CNC machine becomes a reliable tool for producing precise PCB prototypes without the tedium of hand drilling hundreds of holes.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.