Introduction
A drill file tells a circuit board maker where to drill holes and rout slots, and with what
diameters. These text files are usually called Excellon files, after the drilling machine maker
whose specification, based on IPC-NC-349 (1985), they loosely follow. KiCad and DipTrace name
them .drl, Eagle .xln; .nc and .txt are also
used.
Because the many dialects caused trouble, Ucamco and several CAD and CAM developers published
XNC, a small strict subset for passing drill data from design to manufacture,
with the extension .xnc. Its specification recommends
Gerber for the same job where possible.
Structure
A file is lines of text, one command per line. A header sets the unit and declares the tools; the body selects tools and gives coordinates.
M48
METRIC
T01C0.6
T02C0.8
%
G05
T01
X9.01Y3.3375
X9.01Y4.3125
T02
G00X8.01Y3.825
M15
G01X6.54Y3.825
M16
G05
X8.0Y8.0
M30
XNC
An XNC file uses only the printable ASCII codes 32 to 126, plus line feed and carriage
return. It is case-sensitive, commands are in upper case, and spaces are allowed only in
comments. The order is header, body, M30.
| Command | Meaning |
|---|---|
;text | Comment, at most 255 characters, allowed anywhere. |
M48 | Start of the header. |
METRIC or INCH | The unit of the whole file, coordinates and diameters; metric is millimetres. Given once, in the header. |
TnnCd | Declares tool nn (two digits, 01–99, unique) with diameter d, the finished hole size after plating. |
% | End of the header. |
G05 | Drill mode. |
G00XxYy | Rout mode; move to the start of a rout. |
Tn | Select a declared tool (one or two digits). |
XxYy | Drill a hole there (drill mode). |
M15 | Tool down: start a rout path (rout mode). |
G01XxYy | Straight rout to the point. |
G02XxYyAr | Clockwise arc of radius r to the point, spanning at most 180°. |
G03XxYyAr | Counter-clockwise arc, likewise. |
M16 | Tool up: end the rout path. |
M30 | End of file; nothing may follow. |
Coordinates are decimal numbers in the file’s unit, with an optional sign; zero is written
0. Drill data sent with Gerber files must use the same origin and axes as the
copper layers. The result is a series of round holes, straight slots with round ends and
arc-shaped slots, all as wide as the selected tool.
Attributes
Extra information travels in comments that start ; #@! followed by an attribute in
the syntax of the Gerber X2 attributes. File attributes (TF) describe the file;
attributes placed before tool declarations (TA) describe those tools; object
attributes can mark single holes. Readers that ignore comments still get the right holes.
The standard names and values are listed under
Gerber attributes.
M48
; #@! TF.FileFunction,Plated,1,4,PTH
METRIC
; #@! TA.AperFunction,ViaDrill
T01C0.300
; #@! TA.AperFunction,ComponentDrill
T02C0.900
%
Plating is a property of the whole file, so plated and non-plated holes go in separate files.
Excellon files in use
Files outside the XNC subset add commands. The following are those that the drill reader of the Gerber viewer gerbv and the drill writer of KiCad handle.
| Command | Meaning |
|---|---|
FMAT,2 | Format 2 commands. KiCad writes it; gerbv ignores it and rejects FMAT,1. |
VER,1 | Version line. |
METRIC,TZ, INCH,LZ | Unit with zero handling, see below. METRIC may also carry a digit pattern: 000.000, 000.00 or 0000.00. |
M71, M72 | Metric and inch measuring mode. |
ICI,ON, ICI,OFF | Incremental input of coordinates. |
DETECT,ON, DETECT,OFF | Broken tool detection. |
M95 | End of the header, like %. |
TnF…S…Cd | Tool declaration with feed rate and spindle speed. |
G90, G91 | Absolute and incremental coordinates. |
G93XxYy | Set the zero point. |
XxYyG85XxYy | A slot between two points, in drill mode. |
RnXdxYdy | Repeat the last hole n times, stepping by dx, dy. |
M45, M47 | Long and short operator messages. |
M00, M30 | End of program; end of program with rewind. |
Tool lines in more detail
The pcb-tools library reads these letters in a tool declaration, each followed by its value:
| Letter | Value |
|---|---|
T | Tool number. |
C | Diameter. |
F | Z-axis feed rate. |
S | Spindle speed, in thousands of revolutions per minute. |
B | Retraction rate. |
H | Number of hits allowed before a tool change. |
Z | Depth offset from the tip of the tool. |
In a tool selection of more than three digits it takes the first two as the tool and the
rest as a cutter compensation index: T0102 is tool 1 with index 2. It also
reads a line Fnn on its own as a Z-axis infeed rate, tool numbers
joined by / as linked tools, and M30XxYy
as an end of program with a position.
Routing, pattern and machine codes
gerbv’s reader has a name for each of the following. Most it reports as unsupported or skips; the names say what each is for, but not what arguments it takes.
| Code | Name |
|---|---|
G00, G01 | Rout mode; linear move. |
G02, G03 | Circular move, clockwise and counter-clockwise. |
G04 | Variable dwell. |
G05 | Drill mode. |
G07 | Override the current tool’s feed or speed. |
G32, G33 | Routed circle canned cycle, clockwise and counter-clockwise. |
G34 | Select vision tool. |
G35, G36 | Single point vision offset; multipoint vision translation. |
G37 | Cancel vision translation or offset. |
G38 | Vision-corrected single hole drilling. |
G39 | Vision system autocalibration. |
G40, G41, G42 | Cutter compensation off, left and right. |
G45, G46 | Single point offset and multipoint translation relative to G35 or G36. |
G47 | Cancel the translation or offset of G45 or G46. |
G48 | Vision-corrected single hole drilling relative to G35 or G36. |
G81, G82 | Dual in-line package; the source notes that G81 is the same as G82 in format 2. |
G83 | Eight-pin L package. |
G84 | Canned circle. |
G85 | Canned slot. |
G87 | Routed step slot canned cycle. |
M01 | End of pattern. |
M02 | Repeat pattern offset. |
M06 | Optional stop. |
M08 | End of step and repeat. |
M09 | Stop for inspection. |
M14 | Z-axis rout position with depth control. |
M15 | Z-axis rout position. |
M16, M17 | Retract with and without clamping. |
M18 | Tool tip check. |
M25 | Start of pattern. |
M50, M51, M52 | Vision step and repeat: pattern start, rewind, offset counter control. |
M60, M61 | Reference scaling on and off. |
M62, M63 | Peck drilling on and off. |
M70 | Swap axes. |
M80, M90 | Mirror image, X axis and Y axis. |
M97, M98 | Canned text along the X axis and the Y axis; the text is the rest of the line. |
M99 | User defined stored pattern. |
KiCad’s drill file viewer accepts M25, M01, M97 and
M98 without acting on them, treats M17 like M16, and
also recognises the header words ATC (automatic tool change),
TCST (tool change stop) and AFS (automatic feeds and speeds).
Arguments as one machine control reads them
A German programming manual for the Schmoll CNC X30 drilling and routing control, published by Kawa, describes how that control interprets Excellon format 1 and format 2. Other controls may differ. Where the two formats use different codes:
| Function | Format 1 | Format 2 |
|---|---|---|
| Start of a step and repeat pattern | M25 | M25; M31 as on older controls, after which the next M30 is skipped |
| End of the pattern | M24 | M01 |
| Draw the pattern again at an incremental offset | M26XxYy | M02XxYy |
| The same offset n times | RnM26X…Y… | RnM02X…Y… |
| Offset with the sign of X reversed | M26X…Y…M21 | M02X…Y…M80 |
| Offset with the sign of Y reversed | M26X…Y…M22 | M02X…Y…M90 |
| Offset with X and Y exchanged | M26X…Y…M23 | M02X…Y…M70 |
| End of step and repeat | M27 | M08 |
| Inspection stop, optionally moving to a position without drilling | M00 | M09 |
| Optional stop, in the same way | M01 | M06 |
End of program with rewind (M30 in both) | M02 | M00 |
Inch mode (metric is M71 in both) | M70 | M72 |
| Return to drill mode | G81 | G05 |
A closing offset block returns to the original zero and needs no coordinates. With
R, the number of repeated boards equals the number of offset blocks it
replaces.
Stored patterns and repeats:
| Block | Effect |
|---|---|
G82X…Y… then X…Y… | Dual in-line package: the first position, then the opposite one, which fixes the pin count and spacing and is by default an increment from the first even in absolute mode. In format 2, G81 is the 14-pin form and G82 the 16-pin one; the control turns G81 into G82 on input. |
G83 with two positions | Eight-pin package; the two reference positions face each other on a line parallel to X or Y. |
X…Y…G84Xd | Nibble a circle of diameter d about the centre, allowing for the tool diameter. |
X…Y…G85X…Y… | Nibble a slot from start to end, without allowing for the tool diameter. |
RnXdxYdy | Repeat a hole at equal steps, up to 9999 times. |
PnXdxYdy | Repeat the preceding stored pattern n times at that spacing. |
Routing:
| Block | Effect |
|---|---|
G00X…Y… | Rapid move that ends a routing path; a routing program starts with one. |
G01; G02, G03 | Straight move; clockwise and counter-clockwise arc to the given end point. |
Ar | Arc radius, given again only when it changes. A positive value selects an arc of at most 180 degrees, a negative one a larger arc. A radius that does not fit the end points is corrected. |
Tmmii | Magazine position mm with entry ii of a list of up to 99 compensation diameters; without ii the entry number equals the position. It precedes the first G00. |
Fn | Table feed, after a G00 block; the unit is set at the control. |
G40, G41, G42 | Cutter radius compensation off, left and right of the routing direction, each in its own block and not inside a path. The control can be configured to exchange left and right. |
G32X…Y…A…, G33X…Y…A… | Rout an inner circle, clockwise or counter-clockwise, from centre and radius; unchanged values may be left out. The cutter enters at the centre, runs a half circle of half the radius, then the full circle, then a quarter circle with a radius 0.2 mm smaller, and lifts. Compensation is built in. |
G49X…Y…I…J…, G50… | Format 2 only: rout a rectangle clockwise or counter-clockwise from its centre and outer X and Y sizes, with built-in compensation. |
M15, M17 | Lower and raise the Z axis in Excellon files; this control does both itself and skips them. |
M16 | Raise at the end of a path, releasing the sliding pressure foot about 5 mm before the end. |
Hn, Zn | Upper and lower Z levels in hundredths of a millimetre above the table, in their own block (both may share it) and not inside a routing path. H moves at once; Z applies from the next stroke. |
Zero points and other blocks: G90 and G91 select absolute and
incremental coordinates. G92X…Y… (format 1) shifts the zero relative to the
current position until program end, while G93X…Y… sets the work zero relative
to the machine zero. A block marked / is skipped when block delete is on, and
a % after the header marks the rewind stop. In format 2 the manual also names
G06 (2½D routing), G08 and G09 (depth-controlled
drilling and routing on and off), G10 (chip-breaking cycle),
M47 (operator message), M95 and M96 (subprogram and
its end), M99 (subprogram call), and M97 and M98
(drilled text along X and Y).
Coordinates without a decimal point
Many files write coordinates as bare digits with an implied decimal point. The reader must know how many digits are before and after it, and which zeros were left out:
| Header word | Meaning |
|---|---|
TZ | Trailing zeros are present; leading zeros are left out, so digits count from the right. |
LZ | Leading zeros are present; trailing zeros are left out, so digits count from the left. |
KiCad’s defaults are 3 + 3 digits for millimetres and 2 + 4 for inches, and it can instead
write coordinates with a decimal point. It records its choice in a comment such as
; FORMAT={3:3/ absolute / metric / suppress leading zeros}, or
-:- in place of the digits for decimal numbers. gerbv assumes 2 + 4 for inches
and, for METRIC,TZ or METRIC,LZ, 3 + 3, and reads the digit counts
from a comment of the form ;FILE_FORMAT=4:4.
Recognising a file
The header starts with M48, which only comments may precede, and ends with
% or M95; tool lines of the form
TnCd and a final M30 confirm it.
The extension .nc alone says little: it is also used for
NetCDF data and for G-code.
Old files may have no header at all.
Divergence from spec and in software
- KiCad’s drill files are not strict XNC: they can contain
FMAT,2,G90,G85slots (or, as an option,G00,M15,G01,M16), a,TZor,LZsuffix and implied decimal points. - When a header gives no zero handling, gerbv assumes that leading zeros are left out, while noting in its source that Excellon’s documentation states the opposite default.
- One example in the XNC specification has a line with two
Yvalues (G01X5.0Y4.5Y3.825), which its grammar does not allow. - Spindle speed units differ: pcb-tools takes
Sin thousands of revolutions per minute, while the Schmoll control manual givesS600as 60,000 revolutions per minute. - That manual uses
M95in format 2 for a subprogram, where gerbv reads it as the end of the header.
In the explorer
A .drl, .xln or .xnc file, and a .nc
file that begins with M48, opens as a drill pattern: a picture of all holes and
routed paths with one colour per tool, a table of tools with a picture of each tool alone,
and lists of holes, routed features, attributes, operator messages, codes and problems.
- Coordinates with and without a decimal point are read. The units, the number of digits and which zeros are left out come from the header or from the comments of gerbv and KiCad, and each can be chosen by hand. The dialect (format 1 or 2) can be chosen too.
- Absolute and incremental coordinates, zero setting, repeats, slots, canned circles and rectangles, the two package patterns, stored patterns, step and repeat with mirroring and swapped axes, and routing with straight lines and arcs are carried out.
- With cutter radius compensation, either the path of the tool centre or the programmed
path is drawn. Blocks marked with
/can be carried out or left out. - A diameter written without a decimal point is read as gerbv reads it. A file with no unit is read in inches and reported.
Not described
XNC is described from Ucamco’s specification, revision 2021.11. The wider Excellon commands come from the gerbv, KiCad and pcb-tools sources and the Schmoll control manual.
Known, not yet covered
- Reference: the closing chapters of the control manual, on the structure of part programs and step and repeat programming.
- Viewer: text drilled by
M97andM98is listed but not drawn, since the shapes of the letters are not known. - Viewer: subprograms (
M95,M96,M99) are not run, and codes that the viewer does not carry out, such asG06,G07,G34toG39,G45toG48andG87, are reported as problems. - Viewer: mirroring and swapped axes are applied only within step and repeat.
- Viewer: only the first 256 MB of a file are read, and repeats stop at 10,000,000 holes and segments.
Unknown
- Reference: the arguments and exact behaviour of the vision codes,
G04,G07,G87,M14,M18, reference scaling, peck drilling, and of the format 2 depth, chip-breaking, message, subprogram and drilled text codes. - Reference: the full command set and defaults of IPC-NC-349 and of Excellon’s own manuals; neither was available as an authorised copy.
Links
Software
Developers
- gerbv drill.c – drill file parser (C)
- KiCad Excellon writer – how KiCad builds its files (C++)
- KiCad drill file reader – the Excellon reader of KiCad’s viewer (C++)
- pcb-tools – library for reading Gerber and Excellon files (Python)
- tracespace – PCB file parsing and rendering libraries, including layer detection by file name (JavaScript)
Reference
- Ucamco downloads – the XNC format specification and the Gerber specification
- Excellon format 1 and 2 programming, CNC X30 – control manual published by Kawa (PDF, German, 2013)