To explain further about Gerbers, below is an article on Gerbers written for Beginners.
(Source: http://www.kxcad.net/visualcam/visualcam/tutorials/gerber_for_beginners.htm)
_________________________________________________________________________________
While it is not necessary to understand the syntax of a Gerber file in order to import and manipulate your data in VisualCAM, a basic understanding of Gerber is helpful in understanding the elements of your design. This tutorial is intended to be a guide to understanding the fundamentals of Gerber, and how it relates to your use of VisualCAM. If you would like a more thorough explanation of the Gerber 274-X format, we recommend the "Gerber RS-274X Format User's Guide" by Barco Graphics N.V. That document was used as a primary information source for this tutorial.
When you import Gerber or any other data file into VisualCAM, VisualCAM reads the information and stores it in its own internal database format. When you manipulate the data, you are not manipulating your original files. You can save your data in a VisualCAM .vcam file, which is a single file that contains all your data, or you can export your files as Gerber or any of the supported file formats listed in the File|Export menu.
Apertures and D-codes
Two types of Gerber data (274-D, and 274-X) can be used to create individual, photoplotted layers of PCB artwork. The original Gerber formats were designed for use by vector photoplotters. These photoplotters selected individual aperture shapes from an aperture wheel, exposed the aperture to film by opening and closing a shutter. The Gerber file provided the instructions to the photoplotter, telling it which shape to place and where to place it.
When an aperture was "flashed", the shutter merely opened and closed in a single location on the film. When an aperture was "drawn", the shutter opened, the aperture was moved across the film, and then the shutter closed, thus creating a line segment. Thus a Gerber file is essentially an ASCII file with a series of commands instructing the photoplotter where to move, when to open and close the shutter, and which aperture to use.
In order for this to occur, the photoplotter needs an aperture list to define the shapes, or D-codes, used. The aperture list cross-references the aperture number with a D-code of the desired shape and size. Each aperture is assigned a number (which represented its position on the wheel). In the 274-D format, the aperture list is a separate file. Following is an example of an aperture list:
Aper
|
Dcode
|
Type
|
Size-X
|
Size-Y
|
1
|
10
|
Round
|
10
|
0
|
2
|
11
|
Round
|
5
|
0
|
3
|
12
|
Round
|
20
|
0
|
4
|
13
|
Round
|
12
|
0
|
5
|
14
|
Round
|
75
|
0
|
6
|
15
|
Round
|
50
|
0
|
7
|
16
|
Round
|
80
|
0
|
8
|
17
|
Round
|
100
|
0
|
9
|
18
|
Round
|
60
|
0
|
10
|
19
|
Square
|
60
|
60
|
11
|
72
|
Target
|
200
|
0
|
12
|
73
|
Thermal
|
80
|
60
|
Aperture lists do not always appear as the above example. Each CAD/CAM system can use whichever format they desire. Because of this, when VisualCAM imports an aperture list, an Automatic Conversion Rule (ACR) file is necessary to interpret the aperture list. VisualCAM provides a GUI-driven ACR File creator that allows you interactively create an ACR file for any aperture list, rather than creating it manually in a text editor.
There are a few things you will notice in the aperture list. Aperture numbers are always listed sequentially, although the D-codes are not. You will also notice that the D-code numbers begin with "10". This is because D01, D02, and D03 are special D-codes used to control the drawing and flashing of the apertures. Only D-codes 10 and higher are used for the aperture shapes.
D-code
|
Function
|
D01 or D1
|
Shutter open (begin draw).
|
D02 or D2
|
Shutter closed.
|
D03 or D3
|
Flash.
|
D10 and higher
|
Apertures.
|
When using VisualCAM to view your 274-D Gerber files, you must import both the Gerber files and the aperture list files. You can subsequently use the Setup|Apertures command to view and edit your aperture list, if necessary. If you do not import the aperture list files, you will be warned that your apertures are undefined. The VisualCAM aperture table will contain the D-code references from your Gerber file, but you will have to assign the shapes and sizes.
Because 274-D does not have the notion of a "custom aperture", if you export an aperture list from VisualCAM that contains custom apertures, the custom apertures are listed but not completely defined (only their size is indicated). If you wish, prior to exporting, you can "explode" your custom apertures into their individual elements by using the Edit|D-Code|Explode Customs command. This essentially removes all customs from your database. Otherwise, you can save your custom apertures to separate library files, which contain their complete information.
When you re-import a VisualCAM aperture list that contains custom apertures, they are defined as "moires". You will then have to use the Custom Ap button in the Aperture Setup dialog box to reload or define your custom apertures. Use of 274-X will avoid these issues, because the custom aperture definitions are contained within the 274-X data.
G-codes
Now that we understand how to identify the apertures that are used in the Gerber file, we have to tell the photoplotter what to do with them. G-codes are used for this purpose.
G-code
|
Function
|
G00
|
Move
|
G01 or G1
|
Linear Interpolation (1X scale)
|
G02 or G2
|
Clockwise Circular Interpolation
|
G03 or G3
|
Counterclockwise Circular Interpolation
|
G04 or G4
|
Ignore Data Block (used for comments)
|
G10
|
Linear Interpolation (10X scale)
|
G11
|
Linear Interpolation (0.1X scale)
|
G12
|
Linear Interpolation (0.01X scale)
|
G36
|
Turn On Polygon Area Fill
|
G37
|
Turn Off Polygon Area Fill
|
G54
|
Tool Prepare
|
G70
|
Specify Inches
|
G71
|
Specify Millimeters
|
G74
|
Disable 360° Circular Interpolation (single quadrant)
|
G75
|
Enable 360° Circular Interpolation (multi-quadrant)
|
G90
|
Specify Absolute Format
|
G91
|
Specify Incremental Format
|
You will not see all of these G-codes in a 274-D file. They simply aren't required. You will normally only see G01 and G54.
Linear interpolation plots a straight line from the present position to the X:Y coordinate specified by the data block.
The format of a G01 command is:
G01X<X coordinate>Y<Y coordinate>D<D-code number>*
Circular interpolation is used to create arcs and circles. The G02 and G03 commands control single quadrant (90°) interpolation, which produces an arc. The G75 command controls multi-quadrant (360°) interpolation, which produces a circle. The G74 command disables interpolation.
G<nn>X<X coordinate>Y<Y coordinate>I<X distance>J<Y distance>D<D-code number>*
Parameter
|
Description
|
G<nn>
|
The G-code number (G02, G03, or G75)
|
X<X coordinate>Y<Y
coordinate>
|
Defines the arc end point. The starting point is the current tool
position (wherever the last command left it).
|
I<X distance>J<Y
distance>
|
Defines the incremental distance between the arc
start point and the
center, measured parallel to the X and Y axes,
respectively. The direction to the center is determined implicitly. Used in a G75 command, the X and Y
distance can be signed ("+" to draw the circle in a positive
direction, "-" to draw in a negative direction).
|
Polygon area fill, using G36, provides a more efficient means of filling closed polygons than stroke fill. Rather than specifying numerous G01 commands to fill an area, the G36 command allows you to simply define a polygon by its closed outline. G36 is followed by D01 commands, which are considered edges of the polygon. D02 closes and fills the polygon, and G37 turns the command off.
M-codes
M-codes are used to identify the end of a file.
M-code
|
Function
|
M00
|
Program stop
|
M01 or M1
|
Optional stop
|
M02 or M2
|
End of program
|
Example 274-D Files
Following is an example of a simple plot. D-code 10 is used for the round flashes on each end, and D-code 11 is used for the square draws in between.
This file was exported from VisualCAM in 274-D format, Absolute Coordinates with a Coordinate (m.n) Format of 2.4, leading zeros suppressed. The resulting 274-D Gerber file is below, with a description of each data block.
G54D10*
G1X55000Y32000D3*
G1X55500Y31500D3*
G1X55000Y32000D2*
G54D11*
G1X55000Y31500D1*
G1X55500Y31500D1*
M2*
|
Prepare D-code 10.
Flash at X:Y coordinates
5.5000:3.2000.
Flash at 5.5500:3.1500.
Move (shutter closed) to
5.5000:3.2000.
Prepare D-code 11.
Move (draw) to 5.5000:3.1500
(this creates the vertical line segment).
Move (draw) to 5.5500:3.1500 (this creates the horizontal line segment).
End of plot.
|
|
|
Each data block ends with an asterisk (*). A Gerber file can be exported in Inches or Millimeters; the one above is in Inches.
How do we know where the decimal is in the coordinates? That is where the "Coordinate Format" or "m.n" value comes into play. A 2.4 format means that there are 2 digits before the decimal point, and 4 digits after. However, this can be confusing when leading or trailing zeros are suppressed, as in the above example. When leading zeros are suppressed, then we only need to pay attention to the number to the right of the decimal point.
"Absolute Coordinates" means that the coordinates you are looking at are the actual X:Y values based on a 0:0 origin. "Incremental Coordinates" means that each X:Y coordinate is a displacement from the previous coordinate.
Following is the same Gerber file, except it was exported with no zero suppression, and in Incremental Coordinates.
G54D10*
G01X055000Y032000D03*
G01X000500Y-000500D03*
G01X-000500Y000500D02*
G54D11*
G01X000000Y-000500D01*
G01X000500Y000000D01*
M02*
The following Gerber file is an illustration of a filled polygon (the G36 command). It is a simple square.
G36*
G1X0Y40D02*
G75*
G3X40Y0I40J0D01*
G1X9960Y0D01*
G3X10000Y40I0J40D1*
G1X10000Y9960D1*
G3X9960Y10000I-40J0D1*
G1X40Y10000D1*
G3X0Y9960I0J-40D1*
G1X0Y40D1*
G37*
G74*
M2*
Your next question is likely, "How am I supposed to know what all the formatting values are?" Well, that's a disadvantage to using 274-D. Someone with a lot of experience with Gerber may be able to tell just by looking at the file, but interpreting a 274-D Gerber file can be difficult for the novice user. In a perfect world, the CAD system that created the files might actually use all the G-codes that specify the format, add comments (using the G04 command), or provide you with a separate Read Me file identifying the correct format.
If you are trying to import 274-D Gerber Files into VisualCAM and are unsure of the formatting, you should use the Import Wizard. The Import Wizard not only helps in identifying whether your files are 274-D or 274-X, but also makes an educated guess at the format of the file contents. You are provided with a preview before the files are loaded, so that you can identify any discrepancies in the format settings. If you'd rather eliminate the guesswork with file formats, use 274-X.
274-X and Apertures
The 274-X, or Extended Gerber, format has many advantages over 274-D. One advantage is that a 274-X format file does not use a separate aperture list file like the previously discussed. The aperture information is embedded in the Gerber file, along with the photoplotter commands. So we do not have to worry about converting aperture lists or having undefined apertures.
Standard apertures are identified with an AD command as follows:
%ADD<D-code number><type>,<modifier>[X<modifier>]*%
Each parameter block begins and ends with a "%", and each modifier is separated by an "X". In order for VisualCAM's Import Wizard to identify a file as 274-X, at least one %ADD statement must be present. If your file does not have the statement, you will have to manually identify the Data Format as 274-X in Page 2 of the Wizard. The file will then import, but no aperture information will be present in the data.
Type
|
Modifier
|
C
Circle
|
<outside
diameter>[X<X-axis hole dimension>[X<Y-axis hole dimension>]]
To
define a solid circle, enter only the diameter. Enter one dimension to add a
round hole in the center, two dimensions of equal value for a square hole.
Example:
%ADD10C,.10X0.025X0.025*%
A .05
circle with a .025 square hole in the center.
|
R
Rectangle/Square
|
<X-axis
dimension>X<Y-axis dimension[X<X-axis hole dimension>X<Y-axis
hole dimension>]
To
define a solid aperture, enter only the X-axis and Y-axis dimensions. A
square would have dimensions of equal value. To add a hole in the center,
enter one additional dimension for a round hole, two for a square/rectangular
hole.
Example:
%ADD11R,0.10X0.05X0.04X0.02*%
A .10 X
.05 rectangle with a .04 X .02 rectangular hole in the center.
|
O
Oval
|
<X-axis
dimension>X<Y-axis dimension>[X<X-axis hole
dimension>[X<Y-axis hole dimension>]]
To
define an oval that is elongated horizontally, the X dimension is larger than
the Y. If the Y dimension is larger, the oval is vertical. Enter only the X
and Y values for a solid aperture. Enter one dimension to add a round hole in
the center, two dimensions of equal value for a square hole.
Example:
%ADD12O,0.05X0.10*%
A
horizontal, solid oval.
|
P
Regular
Polygon
|
<outside
dimension>X<number of sides>[X<degrees of
rotation>[X<X-axis hole dimension>X<Y-axis hole dimension>]]
To
define a solid polygon, enter the outside dimension and number of sides. The
first point is located on the X-axis, and you can add a dimension rotate the
image. Enter one additional dimension to add a round hole in the center, two
dimensions of equal value for a square hole.
Example:
%ADD13P,.10X5*%
A solid
pentagon with a .10 outside dimension.
|
274-X also has the ability to define custom apertures, such as Targets and Donuts. AM (Aperture Macro) parameters are used define multiple shapes that are combined into a single aperture. They are then used in the same way as standard apertures.
%AM<aperture macro name>*<primitive>,<modifier$1>,<modifier$2>,[<...>]*[<primitive>[<modifiers>]]*...*%
The "aperture macro name" is the name to be used in the AD parameter. Each primitive has an assigned number, as well as various modifiers. Modifiers may be absolute values, or may be variables to be supplied by the AD parameter, as described below. If an absolute value is entered instead of a variable, then the variable numbers are "shifted right". For example, if an absolute number is used for the first variable, then the next variable becomes $1.
Primitive Number
|
Modifier Variables
|
1
Circle
|
$1
0 = exposure off
1 = exposure on
2 = reverse current exposure state
|
$2
Diameter
|
$3
X center position
|
$4
Y center position
|
2 or 20
Line (vector)
A line whose end points are rectangular.
|
$1
0 = exposure off
1 = exposure on
2 = reverse current exposure state
|
$2
Line width
|
$3
X start point
|
$4
Y start point
|
$5
X end point
|
$6
Y end point
|
$7
Rotation in degrees
+ = counterclockwise
- = clockwise
|
21
Line (center)
A centered rectangle.
|
$1
0 = exposure off
1 = exposure on
2 = reverse current exposure state
|
$2
Rectangle width
|
$3
Rectangle height
|
$4
X center point
|
$5
Y center point
|
$6
Rotation in degrees
+ = counterclockwise
- = clockwise
|
22
Line (lower-left)
A rectangle based on a lower-left point.
|
$1
0 = exposure off
1 = exposure on
2 = reverse current exposure state
|
$2
Rectangle width
|
$3
Rectangle height
|
$4
X lower-left point
|
$5
Y lower-left point
|
$6
Rotation in degrees
+ = counterclockwise
- = clockwise
|
4
Outline
An open or closed shape defined by a series of X:Y points (up to 50). The first and last points are the same in a closed shape.
|
$1
0 = exposure off
1 = exposure on
2 = reverse current exposure state
|
$2
The number of points in the outline
|
$3
X start point
|
$4
Y start point
|
$5
Second X point
|
$6
Second Y point
|
$7
Third X point
|
$8, etc.
Third Y point (continue as needed)
|
$9, or last number used
Rotation in degrees
+ = counterclockwise
- = clockwise
|
5
Polygon
A closed shape with sides of equal length. It is defined by 3 to 10 vertices, a center point, diameter, and rotation.
|
$1
0 = exposure off
1 = exposure on
2 = reverse current exposure state
|
$2
Number of vertices
|
$3
X center point
|
$4
Y center point
|
$5
Diameter
|
$6
Rotation in degrees
+ = counterclockwise
- = clockwise
|
6
Moiré
A cross hair centered on concentric circles.
|
$1
X center point
|
$2
Y center point
|
$3
Outside diameter
|
$4
Circle line thickness (positive data)
|
$5
Gap between circles (negative data)
|
$6
Number of circles
|
$7
Cross hair thickness (positive data)
|
$8
Cross hair length
|
$9
Rotation in degrees
+ = counterclockwise
- = clockwise
|
7
Thermal
A solid circle of positive data, with a smaller circle and cross ties of negative data centered on it.
|
$1
X center point
|
$2
Y center point
|
$3
Outer (positive) circle diameter
|
$4
Inner (negative) circle diameter
|
$5
Cross tie thickness (negative data)
|
$6
Rotation in degrees
+ = counterclockwise
- = clockwise
|
Custom Aperture Examples
%AMDONUT*
1,1,$1,0.0,0.0*
1,0,$2,0.0,0.0*
%
%ADD10DONUT,0.60X0.40%
%ADD20DONUT,0.08X0.70%
In the above example, D10 is defined as a 60 mil donut with a 40 mil hole and D20 is defined as an 80 mil donut with a 70 mil hole. Note that both D10 and D20 refer to the same aperture macro but have different sizes.
%AMTHSS3*
20,1,0.200000,-0.100000,0.000000,0.100000,0.000000,0.000000*
20,0,0.100000,-0.050000,0.000000,0.050000,0.000000,0.000000*
20,0,0.030000,0.000000,0.000000,-0.141400,0.000000,0.000000*
20,0,0.030000,0.000000,0.000000,0.070700,-0.122456,0.000000*
20,0,0.030000,0.000000,0.000000,0.070700,0.122456,0.000000*
%
%ADD64THSS3*%
The above example assigns the aperture to D64. Absolute values are used in the Aperture Macro, so no additional values are specified in the AD command.
%AMOCTAGON_DIA*
5,1,8,0,0,0.09000,-22.50000*
21,0,0.04000,0.04000,0,0,45.00000*
Example 274-X File
If we export our example plot into a 274-X file this time (in 2.4, absolute coordinates, leading zero suppression), we get the following file:
*
%LPD*%
%LNLayer2*%
%FSLAX24Y24*%
%MOIN*%
%AD*%
%ADD10C,0.010000*%
%ADD11R,0.005000X0.005000*%
G54D10*
%SRX1Y1I0.0J0.0*%
G1X55000Y32000D3*
G1X55500Y31500D3*
G1X55000Y32000D2*
G54D11*
G1X55000Y31500D1*
G1X55500Y31500D1*
M2*
We are provided with a lot more information in this file than in 274-D. Next we will discuss each of the parameters that precede the Aperture/D-code definitions and photoplotter instructions in the example, as well as some other parameters you might see in a Gerber file.
Polarity
274-X has the concept of "Polarity", where 274-D does not. In essence, positive polarity refers to visible items. Negative polarity refers to items that clear away or erase visible items (on a plot, this reveals the background color). The LP (Layer Polarity) parameter specifies positive or negative polarity for all the data following it, until another LP parameter is encountered. "D" stands for Dark, or positive, polarity. "C" stands for Clear, or negative polarity. In our example, the parameter is %LPD*%, or positive polarity. All items on a layer do not necessarily have to have the same polarity — the LP parameter can be used on an "item level".
Layer Name
The LN parameter assigns a name to the layer whose information follows the parameter. This name can be anything, but it usually describes either the layer's place in the stack-up, such as "Layer2", or what type of layer it is, such as "Border".
Format Statement
This is the format information we were lacking in the 274-D file. It describes zero suppression, coordinate values and coordinate format (M.N). In order for VisualCAM's Import Wizard to identify a file as 274-X, this statement must be present. If your file does not have the statement, you will have to manually identify the Data Format as 274-X in Page 2 of the Wizard. You will also have to identify the proper M.N, Coordinate Mode, and Zero Suppression in order for the file to be read properly.
The file will then import.
%FS<L or T><A or I><Xn><Yn>*%
Parameter Value
|
Description
|
<L
or T>
|
L =
suppress leading zeros
T =
suppress trailing zeros
|
<A
or I>
|
A =
Absolute Coordinates
I =
Incremental Coordinates
|
<Xn>
& <Yn>
|
n = the
number of integer and decimal places for X and Y
In our
example 274-X file, "X24Y24" is a coordinate format of 2.4. It is
customary for the values to be the same for X and Y.
|
The MO parameter specifies if units of measure are in Inches (IN) or millimeters (MM). This is another piece of information that is omitted from 274-D (unless you used G70 or G71).MO Parameter
The SR parameter is used to duplicate data a specific number of times (repeats) at regular intervals (steps). When entered without parameters, it is also used to disable the previous SR parameter. Step and Repeat eliminates repetitive entry of data and helps to keep file sizes to a minimum. A common use for step and repeat is in panelization.
%SR[X<number of repeats>][Y<number of repeats>][I<X-axis step>][J<Y-axis step>]*%
Parameter Value
|
Description
|
X<number
of repeats>
|
the
number of times the data will be repeated along the X-axis
|
Y<number
of repeats>
|
the
number of times the data will be repeated along the Y-axis
|
I<X-axis
step>
|
the
distance between the X-axis repeats
|
J<Y-axis
step>
|
the
distance between the Y-axis repeats
|
Mirror Image
The MI parameter is used to "flip" data on either the X or Y axis. When turned on, all the data that follows is mirrored until another MI command is used.
The AS parameter is used to correlate the X and Y axes with the output device's A and B axes.
%MI[A<1 or 0>][B<1 or 0>}*%
Parameter Value
|
Description
|
A<1
or 0>
|
1 =
invert A-axis data (flip image on the B-axis)
0 =
disable
|
B<1
or 0>
|
1 =
invert B-axis data (flip image on the A-axis)
0 =
disable
|
%ASAXBY*%
The following example inverts Y-axis data, flipping the image on the X-axis.
%MIA0B1*%
Composites
Basically, a composite is a single layer (and hence, a single Gerber file), which is made up of a set of positive (dark) and negative (clear) layers. When you look at a composite file in ASCII format, you will see two or more layers defined, with LP, LN, and MO parameters defined for each. They are primarily used to route traces on power planes. For more information on composites, see Working with Composites.
Gerber from Japan
In recent years, a version of Gerber that utilizes decimal points has emerged from Japan. In versions we have seen, instead of a leading or trailing zero (L or T) parameter in the format statement, a "D" appears. In addition, all the Gerber commands in the body of the file have the decimal points inserted in them (whereas a correct Gerber file would not have decimals, because that M.N information is gained from the XnYn parameter in the Format Statement). Although this use of decimal points does not conform to the Gerber standard, VisualCAM will import this type of Gerber file. All Gerber files we export, however, conform to the Gerber standard.