PCB Fab and Assembly -- http://www.bittele.com/ -- PCB Fab and Assembly

Saturday, June 30, 2012

What's all this about RS274X Anyway?


Introduction

If you're a PCB designer you're probably hearing more and more about extended Gerber - RS274X. The latest versions of many PCB layout programs either offer RS274X as an option or only output RS274X-- such as Cadence's Allegro.


Benefits of RS274X

RS274X includes many high level commands and controls that let the creator of the Gerber data specify the photoplot very precisely - much more so than RS274D which entailed passing a lot of critical information separately from the data file.

What is RS274X anyway?

It is an extension to standard RS274D (commonly known as Gerber) that includes:
  • embedded format, unit and data information
  • embedded apertures
  • custom aperture definitions
  • film control statements
  • multiple layers embedded in a single file
  • special polygon definitions
This document assumes that you are familiar with the basic Gerber commands - if not you may wish to first review the article Apertures, D-Codes and Plot Files which summarizes basic Gerber.

Some of the embedded information we mention here is actually available, although rarely used, in the RS274D specification.


Where to Get the Official RS274X Spec?

The RS274X specification was developed by Gerber Scientific. Gerber was purchased by Barco, then Barco by Mania, a Belgian company. The 274X spec is now available at this link.




Embedding Format Info in the 274X Header

RS274X includes a statement that embeds key information about the format, zero suppression and data mode into a single line:
  • format (x,y)
  • zero suppression (leading, trailing or none)
  • coordinates (absolute or incremental)
where:

L  = leading zeros omitted
T  = trailing zeros omitted
D  = explicit decimal point (i.e. no zeros omitted)

A  = absolute coordinate mode
I  = incremental coordinate mode

Nn = sequence number, where n is number of digits (rarely used)
Gn = prepartory function code (rarely used)

Xa = format of input data (5.5 is max)
Yb = format of input data
Zb = format of input data (Z is rarely if ever seen)

Dn = draft code (rarely used)
Mn = misc code (rarely used)

Examples

 %FSLAX24Y24*%
Format Statement Leading Zeros Suppression, Absolute Coordinates format=2.4
 
 %FSTIX44Y44*%
Format Statement Trailing Zero Supression, Incremental Coordinates, format=4.4

Embedded Units

RS274X files can use coordinate and aperture units of either inches or millimeters.

The statements:
%MOIN*%     indicates inches

%MOMM*%     indicates millimeters

Controlling Image Polarity

When using RS274D one had to set the photoplotter manually on the desired polarity of the film. If the operator didn't pay attention or got confused then your film came out wrong. With RS274X, a command near the beginning of the file can invert the film's polarity.

%IPPOS*% - positive (left)

%IPNEG*% - negative (right)

Do not confuse image polarity with individual layer polarity. It is possible to build up a very complex plot by combining individual dark and clear plots and then setting the overall polarity of the film.

Embedded Aperture Definitions

One of the major shortcomings of the old RS274D spec was that the definition of each aperture was not part of data file; instead it was transferred manually on paper or as a text file similar to what is seen below:

     Aperture Definitions
     D-code     Shape       SizeX       Size Y
     d10           round        0.010
     d11           square      0.030
     d12           rect           0.060       0.020
     d13           thermal     0.050
     d14           oblong      0.060       0.025

Some apertures are obvious - the round, square and rectangle. But both the oblong and the thermal are subject to the photoplot operator's interpretation as shown below.


Basic Thermal     Rotated Thermal     Square Thermal

With 274D, the exact shape of the thermal shape was a job for the photoplot operator; there was significant amount of effort and expense involved in creating these custom apertures and libraries had to be maintained. With 274X even complex apertures are described using macros that the photoplotter synthesizes on-the-fly.

The Basic Aperture Definitions

RS274x includes several "standard" apertures since these represent more than 90 percent of the flash types used:
  • circle
  • rectangle
  • obround
  • polygon
These are all assumed to be centered and can be defined with a round or rectangular hole if desired.

Standard Circle
%ADD{code}C,{$1}X{$2}X{$3}*%

where

AD -      aperture description parameter
D{code}   d-code to which this aperture is assigned (10-999)
C         tells 274X this is a circle macro

$1        value (inches or mm) of the outside diameter
$2        optional, if present defines the diameter of the hole
$3        optional, if present the $2 and $3 represent the size of
          a rectangular hole.

Circle Examples
%ADD21C,.100*%                      (a) 0.10 diameter circle on d21

%ADD22C,.100X.050*%                 (b) 0.10 dia circle with 0.05 hole on d22.
                                      
%ADD23C,.100X.050X.050*%            (c) 0.10 dia circle with 0.05 square hole on d23.
                                      
%ADD24C,.100X.050X.025*%            (d) 0.10 dia circle with 0.05 x 0.025 rectangular hole on d24.
                                      


Standard Rectangles

%ADD{code}R,{$1}X{$2}X{$3}X{$4}*%

where

AD -      aperture description parameter
D{code}   d-code to which this aperture is assigned (10-999)
R         tells 274X this is a rectangle macro

$1        value (inches or mm) of rect's length in X
$2        value if rect's height in Y
$3        optional, if present defines the diameter of the hole
$4        optional, if present the $2 and $3 represent the size of
          a rectangular hole.

For details on the obround and polygon (which are rarely used) see Gerber Format Guide, Doc 0000-000-RM-00.

Aperture Macros

The more general aperture macro can be thought of as a type of programming language where one builds up a complex aperture definition from a series of simpler primitives. Macros are almost required for properly defining thermal reliefs - and since thermal reliefs are very important in power and ground planes we'll do a detailed example of macros using the thermal primitive.

Macro Primitives

Remember we said a macro is like a programming language - the complex aperture is built from one or more shapes called primitives. Available primitives include:

Primitive Name      Primitive Number      Description and Parameter Number

Circle                                 (1)                        round

Line Vector                        (2 or 20)             rectangle defined by endpoints
                                                                        width and rotation. Square ends.

Line Center                      (21)                       rect - defined by center and length, width
                                                                        and rotation. Square ends.

Line-Lower Left                (22)                      rect - defined by lower left coordinate,
                                                                        length, width and rotation.

Outline                              (4)                        outlines an area defined by coordinate pairs.
                                                                       max vertice=50.

Polygon                            (5)                        a regular polygon with 3-10 sides. defined
                                                                       by center, outer diameter and rotation.

Moire                                (6)                        target defined by center, number of circles
                                                                      circle thickness, cross hair length, thickness
                                                                      and rotation.

Thermal                             (7)                      thermal relief defined by outer diameter, inner
                                                                     diameter, crosshair thickness and rotation.


Aperture Macro Example - Thermal Relief
The thermal relief is so important that it has its own primitive - even though it could be built from other primitives.
      %AMTHERM100*7,0,0,0.100,0.050,0.025,0.0*%
      
      %ADD32THERM100*%                           assigns THERM100 to d-code 32
      
      where

      AM         -       aperture macro
      THERM100   -       name of the macro
      *          -       terminates name
      7          -       primitive 7, which is a thermal relief
      0,0        -       first two parms: x,y center
      0.100      -       third parm: outer diameter (solid black see (a) above)
      0.050      -       fourth parm: inner diameter (clear see (b) above)
      0.025      -       fifth parm: crosshair width (clear see (c) above)
      0.0        -       sixth parm: crosshair rotation (not used here)



Multiple Internal Layers

When photoplotting was done by vector machines which directly exposed a piece of film through a shutter and aperture, the concept of multiple internal layers had little use, since once film was exposed the process could not be reversed. 

However the development of raster based photoplotters which used computer memory to compose a bitmap image prior to exposing the film enabled a user to combine multiple layers and to easily remove data using one layer that had be laid down by a previous layer.

With RS274, the photoplotter operator had to key in the various input layers (individual RS274 files) and set the "polarity" of the layer manually - see a typical instruction list provided to an operator below:
Plotting Instructions for Board XYZ

Film1: top
targets.gbr                 pos
comp.gbr                    pos
padmaster.gbr               pos

Film2: bottom
targets.gbr                 pos
sold.gbr                    pos
padmaster.gbr               pos

Film3: vcc
vcc1.gbr                    neg
clearance.gbr               neg
traces.gbr                  pos

RS274X includes two special commands, %LPD*% (Layer Polarity Dark) and %LPC*% (Layer Polarity Clear) that apply to internal layers within an RS274X file. With a few judicious LPD/LPC commands combined with the IP (image polarity) command one can build up complex ground planes quickly and easily. In the example below we will show how the LPD/LPC can be used to put a circuit trace easily on a power plane.

The main difficulty with putting a circuit trace on a power plane is clearing away the metal around the circuit trace and it's associated pads. With standard Gerber the layout software often had to fill in with small strokes the entire powerplane metal area except where the clearance would be. This results in a very large and unwieldy Gerber file.
When creating such a Gerber file in 274X we can use the LPC (clear layer) to draw the trace.

G04 Image Parameters ***
%MOIN*%
%FSLAX24Y24*%
%IPNEG*%            this will reverse polarity of the entire film, eliminating the need to 
                    stroke fill the metal area of the powerplane.

%ADD10C,,,*%        here we define some round apertures and a thermal  
%ADD11C...*%
%ADD12C...*%
%AMTHERMAL*...*%
%ADD13THERMAL*%
G04*
%LNINTERNAL_VCC*%   this is our basic vcc powerplane layer consisting of clearance pads, thermal reliefs,
                    the outer trace that defines the board edge, and the clearance for the inner trace.

%LPD*%              indicates digitized data is dark. However when the entire film is reversed the 
                    digitized data will be clear.
G54D10*
data
data
data

G04 NEW LAYER ***
%LNTRACE_VCC*%      this is a new internal layer which will be used to define the circuit trace and two pads

%LPC*%              note that the data here is clear or reversed out. When the entire film is negated 
                    the digitized data will be black on the film.
G54D12*
data
data
data
M02*                end of the job
          
The series of images below show how a ground plane can be easily drawn, a trace within the ground plane is placed and substracted, and the entire image is then reversed.
Figure 1: This is what the data on the layer Internal_VCC would look like if a) it were not reversed out and b) we did not yet deal with the next layer. Note the large pads at A,B and the fat clearance trace.



Figure 2: Here is what the data for the layer TRACE_VCC would look like a) before the image is reversed b) before the LPC directive is implemented. Because of LPC, this data will be "subtracted" from the data laid down by the first layer.


Figure 3: The LPD layer, Internal_VCC merged with the LPC layer TRACE_VCC layer but before polarity reversal.



Figure 4: The final image on the film after the IPNEG directive has reversed the polarity of the merged internal layers.



G36/G37 Polygons
The G36/G37 polygon command precedes the RS274X spec but only the raster based photoplotters supported it. It is a very powerful command and will see more use in the future for describing complex data often encountered in IC packages, RF and microwave circuits and analog devices
.
When the photoplotter sees a G36* command it immediately changes mode - it now ignores any aperture setting and treats each draw command as the edge of a polygon to be filled in. The application creating the Gerber file should create simple clean polygons.

Sample Usage of G36/G37

         G04 G36/G37 Polygon Example ***
         %MOIN*%             set the units to inches
         %FSLAX24Y24*%       set the format statement
         %IPPOS*%            set polarity to positive
         
         %ADD10C,,,*%        here we define some apertures
         %ADD11C...*%
         %ADD12C...*%
         G04*
         %LPD*%
         G54D10*            select D10 [not mandatory to select a D-Code]
         G01*               set linear draw mode
         G36*               switch into polygon mode. The shape of D10 no longer matters.
         X123Y123D02*       move to initial position with pen up
         X234D01*           draw a line (edge)
         Y456D01*           draw a line (edge)
         X234D01*           draw a line (edge)
         Y123D01*           draw a line (edge) back to original start
         G37*               end polygon mode.

It is possible (and fairly common) to switch back and forth between G36/G37 and standard draws and flashes. Many PCB tools use round draws for circuit traces, flashes for pads and G36/G37 for any shapes such as power planes.













_________________________________________________________________


Source:  http://www.artwork.com/gerber/274x/rs274x.htm


Written by: 
Steve DiBartolomeo
Applications Manager
Artwork Conversion Software, Inc.
© 1995 Artwork Conversion Software, Inc

Thursday, June 28, 2012

D-codes, Aperture and Gerber File Plots

Another interesting material relevant to D-codes, Aperture and Gerber File Plots 
written by Steve DiBartolomeo --  http://www.artwork.com/gerber/appl2.htm






Introduction

No matter how powerful your design software may be, you must eventually create a photoplot file in Gerber format to create film. Aggravation can be reduced by better understanding what is contained in a photoplot file. Misunderstandings between the PCB designer and photoplot operator account for a large percent of the bad film produced in this industry.


A Brief Description of the Photoplotter

Before diving into the details of the photoplot file a short discussion of photoplotters will make the following material easier to digest. Early photoplotters consisted of a precision servo controlled X-Y table to which a piece of high contrast film is attached. A bright light source is directed through a shutter, through an aperture wheel and focused onto the film. A controller converts Gerber commands into the appropriate table movements, wheel rotation and shutter opening.



Figure 1 - Photoplotter Schematic

When the shutter is open light shines through the aperture exposing the aperture's image onto the film. When the table simultaneously moves while the shutter is open, a line or stripe is imaged onto the film. Given the proper commands for table motion, aperture selection and shutter operations, one can construct just about any image on film.





Figure 2. Plotter Operation


Simplicity: A double-edged sword


 

The beauty of the Gerber database is its simplicity. There are only four essential commands plus coordinate data. The database had to be simple and compact because the first machines were driven by a fragile punched paper tape. The need to compress as much information as possible into as few bytes as possible explains many of the "problems" we encounter today when storage space is measured in hundreds of megabytes instead of hundreds of bytes. 

But simplicity exacts its own price. The Gerber file lacks essential information necessary to run the plotter. This missing data is handed from the designer to the plotter operator separately, and is often the source of errors. Further, the temptation to create non-standard extensions is impossible to resist. Every photoplotter manufacturer supports the basic Gerber commands plus whatever features they feel necessary to differentiate their machine. The result is that one man's feature is the next man's unsupported problem. 

Gerber File Contents

Below is a simple Gerber file illustrating the structure and content of the format:

G90*                   1
G70*                   2
G54D10*                3
G01X0Y0D02*            4
X450Y330D01*           5
X455Y300D03*           6
G54D11*                7
Y250D03*               8
Y200D03*               9
Y150D03*               10
X0Y0D02*               11
M02*                   12


The line numbers at far right are not part of the file. Examining this file without any prior knowledge of Gerber one would correctly deduce that each line represents a particular machine command and that the asterisk (*) is the end of command character. There seems to be different kinds of commands: instructions beginning with G, D, M and x,y coordinate data. 


G-Codes: Setting the Initial Conditions

Gerber calls the Gxx commands preparatory codes. In most cases these codes are used to prepare the machine's state prior to drawing. Several G codes are important to recognize:
G90/G91 Incremental vs. Absolute Coordinates

The G90 command in line 1 tells the machine that data coordinates are absolute. Each set of coordinates is referenced to the table's origin (0,0). The converse to absolute is incremental -- each coordinate is measured relative the previous coordinate value and is set by issuing the G91 command.
You may never encounter the G90 command in any Gerber file since most programs assume that absolute coordinates are the default and do not bother to write the G90 command. What's worse is that many incremental databases don't bother to use the G91 command either. If you see a "starburst" display similar to figure 3 on your CAM station you are probably trying to read a file written with incremental coordinates.

Figure 3 Left: correctly displayed. Right: Viewer set to incremental when data is absolute.


G70/G71 Inches vs. Millimeters
The G70* (line 2) indicates that data following is in units of inches. This is another G-code that rarely appears in Gerber files. In the U.S. one assumes that Gerber files are output in inches, but files generated in the rest of the world may be in inches or millimeters. G71 indicates units of millimeters.



Tool Select G54

G54, tool select, (line 3) is the most commonly encountered G code and instructs the plotter to rotate the aperture wheel to the position described by Dxx immediately following the G54 command. If you find no G54's in a particular file don't panic. G54 is an optional command on many photoplotters; some programs don't use it and the photoplotter recognizes that by specificity Dxx (where xx is not 01,02,03) that the correct tool should be selected.


Draw and Flash Commands D01, D02, D03

D-codes are instructions to the photoplotter that naturally include the letter "D." The first three D-codes control the movement of the x-y table.

D01 (D1): move to the x-y location specified with the shutter open.

D02 (D2): move to the x-y location specified with the shutter closed.

D03 (D3): move to the x-y location specified with the shutter closed;

          then open and close the shutter -known as flashing the exposure.
    D01 is the command that "draws" lines.

    D02 is the command to move the table without exposing any film. D01 and D02 correspond to moving the paper on a pen plotter with the pen down and pen up.

    D03 is the "flash" command. The table is moved with the shutter closed. When the desired x-y coordinates are reached the shutter opens and closes leaving the image of the aperture on the film. The flash instruction is an efficient way to image the thousands of pads present on most circuit boards.
D01, D02 and D03 commands follow their coordinate data. 

For example the following sequence of commands:

X0Y0D02*
X450Y330D01*
X455Y300D03*

would move the table position to 0,0 with the shutter closed and then would draw a line from 0,0 to 450,330. A flash would be located at 455,300.


Wheel Positions/Apertures D10-D999

Unlike D01, D02 and D03 the D-codes with values from 10-999 are data, not commands. They represent apertures or positions on the photoplotter's wheel. Early photoplotters used a wheel with 24 positions.
Each slot is filled with a piece of film. The wheel rotates, positioning the desired aperture in the light path. Table 1 shows the correspondence between D-code and aperture position.


Table 1. D-codes vs. Apertures
D-code Aperture   D-code   Aperture

       Position            Position
  10       1        20        13
  11       2        21        14
  12       3        22        15
  13       4        23        16
  14       5        24        17
  15       6        25        18
  16       7        26        19
  17       8        27        20
  18       9        28        21
  19       10       29        22
  70       11       72        23
  71       12       73        24

One can see that it proceeds logically from D10 through D19. Then, instead of D20 mapping into position 11, 
D70 and D71 intrude. The mapping continues, now skewed by two places until reaching the point where one 
would expect to see D30. Instead D72 and D73 jump in. Most photoplotters and CAM software ask you to enter 
the aperture descriptions by D-code; a few reference by aperture position.

There are D-codes between 3 and 9 but they are specialized commands for rare or obsolete machines.



Miscellaneous M Codes

At the end of the file we see the command M02*. Gerber calls the M codes, miscellaneous codes. The only common M-code used is at the end of the file- M00, M01 and M02 which are all different types of program "stop" commands. Occasionally one sees an M02 at the beginning of a Gerber file. Apparently some applications issue this to insure that any previous file running is stopped - however many CAM softwares see the M02 at the beginning of the file and ignore anything following it.


X,Y Coordinate Data

Coordinate data makes up the bulk of the Gerber file. It is difficult to manually follow table motion from a printout because Gerber uses several techniques to minimize the number of bytes required to represent the data. These are:
  • Suppress the decimal point in the x,y data
  • Suppress either the leading or the trailing zeros
  • Only output changes in coordinate data

Decimal Point Suppression

The decimal point is redundant if you know in advance where it will be. The decimal point needs to be reinserted by the photoplotter control software in the correct location. One of the most common errors that novice designers make is to assume that the person receiving their data knows you data format. 

Consider the following Gerber commands:
X00560Y00320D02*
X00670Y00305D01*
X00700Y00305D01*

The table moves along X from 00560 to 00670 during the first two commands. But what does 00560 represent? It could be 5.6 inches, 0.56 inches, 0.056 inches or even (but not likely) 0.0056 inches. No way to tell. If the designer tells you that there are two integers before the decimal point and 4 integers after the decimal point then you know that 00560 represents 0.56 inch.


Leading and Trailing Zero Suppression

The designers of the Gerber database didn't rest after eliminating the decimal point. They must have looked at a printout and thought,
"What good are all those extra zeros in front? suppose we cut them off. You can still figure out the coordinate value if you count decimal points from the right side of the number."
           No Zero                    Leading Zero
          Suppression                  Suppression

          X00560Y00320D02*             X560Y320D2*
          X00670Y00305D01*             X670Y305D1*
          X00700Y00305D01*             X700Y305D1*

Without zero suppression 48 bytes are used. With leading zero suppression 33 bytes are required to represent the same information. In the days of paper tape this was a very significant reduction.

Depending on the data you might be better off leaving the leading zeros on and suppressing the trailing zeros.
           
           No Zero                   Trailing Zero
          Suppression                  Suppression

          X00560Y00320D02*             X0056Y0032D2* 
          X00670Y00305D01*             X0067Y00305D1*
          X00700Y00305D01*             X007Y00305D1* 

To correctly interpret the data you must count from the left side of the number to locate the decimal point. Confusing? Yes.


Modal Data Coordinates

After eliminating the decimal point and suppressing the redundant zeros you might think that the database designers would rest on their success. Not at all. One sharp eyed programmer noticed that the same coordinate would appear over and over again when the table moved only along X or Y.
"Why not remember the last value of X and Y; output a coordinate only if it changes!"
          All Coordinates             Modal Coordinates

          X560Y230D2*                    X560Y230D2*
          X670Y305D1*                    X670Y305D1*
          X700Y305D1*                    X700D1*    

The concept that the plotter remembers the last value of coordinates is called modality. PC boards often have hundreds of pads in a row along X or Y and a properly sorted Gerber file will be much smaller when the redundant coordinate is eliminated. This is such a fundamental concept that coordinate data is always modal. You don't need to inform your target site that data is modal or nonmodal - every photoplotter and CAM software supports modal data. In this example an additional 4 bytes were save by using modal coordinates.


Commands can be Modal

Modality is a good concept for data and works equally well for commands. For example, if you have a string of draw commands why repeat the D01 command again and again. Let it stay in effect until another command (D02 or D03) occurs to change it.

          D1 not modal                    D1 modal
          X560Y230D2*                   X560Y230D2*
          X670Y305D1*                   X670Y305D1*
          X700D1*                       X700*
          X730D1*                       X730*
          X760D1*                       X760*
          Y335D1*                       Y335*

It would appear that all commands in Gerber ought to be modal. Once issued the command is in effect until otherwise superseded or turned off. However there are a couple of erratic exceptions that occasionally cause trouble. The most curious is the D03 flash command.

Certain brands of photoplotters don't treat D03 as modal. That is, they expect to see D03 at the end of each flash command. We've encountered this on MDA's FIRE 9000 family of photoplotters.

Flashes that were displayed on our CAM software didn't appear on the film. The problem is easily solved by re-outing the Gerber data with explicit D03's - Lavenir has a utility that does this and many CAM software's can be configured to treat D03 as either modal or non-modal.

The other erratic exception to the standard modal behavior of commands is the G02/G03 command - circular interpolation. Many photoplotters revert to G01 (linear) after a G02/G03 (circular).


Circular Commands: G02/G03 and G75

Gerber photoplotters can draw arcs when instructed to do so. In the past, circular commands were rarely used for PCB manufacturing. Flex circuit boards use curved traces to reduce stress, and high speed logic uses uses smooth radii to reduce signal reflection. There is renewed interest in reading and writing Gerber data with arcs and few rude surprises are surfacing.
The basic format for circular interpolation is:
GNN   XNNNN   YNNNN   INNNN   JNNNN   DNN *

Example: G02X40Y30150J0D01*
Where G02 indicates clockwise rotation, G03 indicates counterclockwise rotation and G75 turns on full 360 degree circular. I,J are additional coordinates required to locate the center of the arc. G02 and G03 commands are rarely treated as modal.
It would take more room available in this paper to properly treat the various permutations that can occur. Circular commands may be limited to just quadrant data on older machines or can describe full 360 degree arcs on newer machines. The meaning of I, J changes depend on whether data coordinates are absolute or incremental.

Popular CAM programs don't always display or edit circular commands correctly. If you wish to test your CAM software, we have provide some text files on diskette. Test your software in advance. Don't wait until you're up against a deadline.

Aperture Lists


We've seen that the Gerber file itself lacks critical information such as data format, units and information about whether the leading or trailing zeros have been suppressed. Nevertheless, a savvy photoplot operator can deduce parameters by viewing the data on a CAM station and adjusting the values until the display looks reasonable. The Gerber file is still missing data that even the most experienced operator can not guess at.

This is the description of what is contained in each aperture position. The actual D-code in the Gerber data only refers to a position on the wheel. It says nothing about what is contained in that slot. The designer has to hand over to the photoplot operator a complete description of what each D-code (aperture) looks like. This description is called the aperture list.

Rule 3. A Gerber file is not complete without an accompanying aperture list.

Without the aperture list, you have nothing!

What can an Aperture Look Like?
There is no theoretical limit on what each aperture can look like. Apertures for vector plotters are made from a piece of film. Whatever can be exposed on film can be used as an aperture. Practically speaking, there are a half dozen common shapes that represent 90% of all the work done. Since these shapes are commonly agreed upon, you can pass this information to the photoplot operator in tabular form.
Complicated Apertures
Complicated apertures need to be described in detail. A drawing of the aperture with coordinates is appropriate. Failure to precisely describe the desired shape results in bad film. A common custom aperture often mangled is the thermal relief pad. PCB fabricators are very particular about the details of the thermal relief , and will reject a film if the thermal relief design does not conform 100% to their specification.

Photoplot File Headers

Lack of Standardization

Why can't we put all these essential pieces of information into the Gerber file now that the memory and media no longer limit the number of bytes? You can put in a header and almost every photoplotter can read a header. The problem lies in standardization. Gerber's RS274X format with an embedded header was not popular enough to establish itself as a defactostandard until the late 90's. Each photoplotter manufacturer and each independent CAM software developer use a different internal database to express format, unit and aperture information.

Even different members of Gerber's family of photoplotters support different parameters in the header. If 10 photoplotters and 10 independent CAM developers each use a different format, the odds that any one header you put into your Gerber files will be readable by both the CAM software and the photoplotter are 1 in 100. It's too late until the IPC-350 standard becomes widely used to resolve this header problem. Until then, the safest approach is to create a form on paper, and in a machine readable format, properly documenting your files.

Sample Header Files 
Below are two sample header files, and a plain text interpretation.
Header for MDA's FIRE 9000 Photoplotter

G04%PAR.%*
G04%MODE=ABSOLUTE;%*
G04%ZERO=LEADING;%*
G04%FORM=4.4;%*
G04%EOP.%*
G04%APR,10000.%*
G04%A010:CIR,250.%*
G04%A011:CIR,300.%*
G04%A012:CIR;-CIR,100.%*
G04%A013:SQR,300.%*
G04%A014:REC,300,1000.%*
G04%A017:POL,X200,Y83,STR,X83,Y200,STR,X-83,Y200,STR,X-200,Y83.%*
G04%STR,X-200,Y-83,STR,X-83,Y-200,STR,X83,-Y200.STR%*
G04%X200, 7-83, STR, X200, Y83.%*
G04%EOA.%*
Header for Gerber Model 4X00
%
FSLAX44Y44*                         
ADD10C,.025*                        
ADD11C,.030*                        
ADD12C,.030X.010*                  
ADD13R,.030X.030*                   
ADD14R,.020X.100*                   
ADD17P,.040X8*                     
%
Plain Text Meaning


Leading Zero Suppression, Absolute, 4.4
D10 Round 0.025 diameter
D11 Round .030 diameter 
D12 Donut OD=.030 ID 
D13 Square Side=.030 
D14 Rectangle X=.030 Y=.100 
D17 Octagon Dia=.040  
Rule 1. When you send a Gerber file, always provide the data format. When you receive a Gerber file, always ask for the data format.

What if your customer violates Rule 1 and sends you a Gerber file with no data format information? You're working graveyard shift, it's 11pm and you need to plot the film by 8am the next morning. Make an educated guess. There are five digits in the coordinates so that the sum of integers before and after the decimal point must equal 5. The most likely candidate is 2.3.

Why? Not many boards are longer than 99 inches and not many boards are built to a precision less than 0.001 inch these days. Display the board on your CAM station. If the overall size looks good (say 8 inches) go ahead. If the board shows up as 80 inches or 0.8 inches long you are probably off by a factor of 10 in one direction or the other.


Leading to Rule 2: Rule 2.
 When you send a Gerber file, always indicate leading or trailing zero suppression. When you receive a Gerber file, always ask about leading or trailing zero suppression.

Tuesday, June 26, 2012

Gerber for Beginners

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


Step and Repeat

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.