Pick n Place G Code generated by MS Excel


SO we now have excel taking the diptrace output and ny adding a couple of formulas and vlookups back to head & feeder offset we have all x y coordinates calcualted for populating a single PCB.

A small VB program is outputting gcode and it works.

Now to allow for an array of pcbs.

It seems the G Code process is to put the pick place gcode for each identical PCB into a subroutine and then offset the PCB coordinates using the G52 command..

Seems easy enough.. but.. the G52 command effects all fixture offsets so perhaps not so suitable..

So.. how about a variable that identifies the current pcb which relates to the fixture offset..


G56 is the origin for the first PCB in the array, this is our PCB global reference.

If we move to G56,  we can set G59 P101 etc using relative G91 from G56 coordinates per the required offset..

So if 4 PCBs we set G59 P101 - P104

Then our main GCode sets #100 = 101 and calls the subroutine, which uses G59 P[#100] (instead of the current G56 fixture setting).. then set #100 = 102 and repeat etc..

Well, I'm sure I tested that G10 responds to G91, ie make an offset relative to the current position but it ain't working now..

So.. to achieve the same thing, ie set offsets in G code from G56 when G56 is unknown at the time of creating the GCode.. I can use variables:

G56 is work offset 3, the Mach 3 Mill manual tells me vars #5261-5263 are G56 X Y & Z respectively.. so we will use these in our code..




So we cant use named variables in Mach 3 G Code, or pass params to subs

So we will see if we can setup tables of params in Excel and generate G Code from them.


  • G55 is feeder row 1 origin
  • G56 is PCB holder origin


DipTrace exports Pick n Place table based on its origin.. we can use this after manually cleaning it up..

Example for LED4R, note this board layout was horizontal with RJ12 on the right, origin bottom left.

Export is:

  • Refdes, Type, Mid X, Mid Y, Side, Rotate, Value

From this we create corrected:

  • Rotation (no ratation if not a part to be pick placed), Feeder, Rotation X, Rotation y

We then manually add sensibly for that component step:

  • Step (sequence ordering), Head

We then sort the entire array by:

  • Rotation, Step & Head

We then add calculated columns for direct use in resulting gode:

  • Pickup offset x, pickup offset y, placement offset x, placement offset y

We then run our macro to create G Code sequence for each rotation.

Possible options:

  • Single PCB manually repeated?
  • Array of PCB's


G Code requirements:

For each different PCB assembly orientation (0, 90, 180, 270 degrees clockwise) require an instruction G Code file..

Comprising of:

  • Pickup 1..4
  • Placement 1..4

For each pickup instruction need to know:

  • Feeder component
    • Feeder base x y offset from feeder 
    • Component count for stepping
  • Head
    • Offset
    • Head A depth for pickup for this component

Pickup sequence:

  • G55 Move to feeder x y + head x y + component count * component spacing (y dimension)
  • Head select
  • Move head to pickup depth
  • Vacuum toggle

For each place instruction need to know:

  • PCB:
    • PCB Offset from PCB holder origin
  • Component:
    • x y offset from PCB origin
  • Head
    • offset
    • head depth A for placing this component on this thickness PCB

Placement Sequence:

  • G56 Move to PCB x y + component x y
  • Head select
  • Move head to placement depth
  • Vacuum toggle