4
\$\begingroup\$

Context

I am currently looking for alternative PCB manufacturers for my company and have sent Gerber files to some (Chinese) companies. These Gerber files have already been used in the past by various companies to manufacture PCBs and to date I have never had any problems with my files not opening correctly. Every Gerber viewer I can get my hands on displays the files as intended.

The Problem

Now, some manufacturers are having problems displaying circles correctly in their CAM software.

After some research, I found that the Gerber command "G75", which enables 360° circular interpolation, might not be implemented (correctly) in outdated CAM software.

There are quite some forum posts and discussions on the internet, stating that some companies use pirated or outdated CAM software and that the problem only exists for closed circles. It is suggested to divide circles into arc segments in the layout. But for me that would mean that I have to rework all PCBs that I want to send to one of those manufacturers or that many manufacturers would not be eligible.

Attempted Solution

I am looking for a way to apply a fix on the Gerber level and have written a Python script that searches a Gerber file for the corresponding sequence (drawing a closed circle with G75) and then replaces it with an equivalent consisting of 4 quarter circles.

This is an example of a gerber section that needs to be fixed:

X5000000Y0D02* % set position to (5;0) -> start point of circle % G75* % enable 360 circular interpolation % G02* % CW circular interpolation % X5000000Y0I-5000000J0D01* % draw to (X;Y) around center point -> specified by (I;J)% 

And this is what my Python script makes of it:

X5000000Y0D02* G75* G02* X0Y-5000000I-5000000J0D01* X-5000000Y0I0J5000000D01* X0Y5000000I5000000J0D01* X5000000Y0I0J-5000000D01* 

I think I know how these Gerber commands work in general and the "fixed" file looks as expected (in GerbV), but I don't fully understand how G75 works.

Sure, there is an ambiguity:
Since the arc segments are defined by start point and end point, the Gerber command for a full 360° arc (=circle) would be the same as a 0° arc (=dot) - starpoint equals endpoint in both cases.
My assumption was, that G75 is needed to handle this exact case. However, after I removed all G75 commands from my Gerber file, it still displays correctly.

Question

Can someone explain to me what the G75 command actually does and what causes the "G75-Bug" on the CAM side?

I'd like to share my script on Github since I think it could be usefull to many others, but first I need to be confident enough that there aren't any pitfalls that cause the production of faulty PCBs...

\$\endgroup\$
1
  • \$\begingroup\$ PCB makers do not use Gerber files. The files you send are instructions that they use to create manufacturing files. If you aren't sure if they will understand a "circle" instruction, get someone who writes Chinese to tell them what you mean. Also, it's not surprising the PCB manufactures don't understand Groove instructions in your Gerber file: Groove instructions should be in the Routing layer, not in the Hole layer. \$\endgroup\$ Commented Dec 2, 2023 at 9:07

1 Answer 1

3
\$\begingroup\$

Gerber Format Minutiae

First, and let me be very clear here:

G75 doesn't do anything.

From the gerber spec:

For compatibility with older versions of the Gerber format, a G75* must be issued before the first D01 in circular mode

That's it. It doesn't enable anything that isn't already the default. 360° circular interpolation mode is the only circular interpolation mode. Any implementations more recent than 1998 simply ignore G75 entirely. So I would certainly hope that removing it from your gerbers would have no effect, as this is the correct and expected behavior.

There used to be a G74 mode but it's deprecated and generally unsupported. G74 is 90 degree arc interpolation mode, but this doesn't actually change how the gerber is drawn. Even when it is supported, it is not 'on' by default. And good thing too!

The only difference between G75 and G74 is that if you try to draw an arc with an angle > 90° in G74 mode, it would result in an error and the gerber would be unpoenable/invalid.

The CAM350 bug

Floating point arithmetic is sensitive to the order it is performed (in other words, it is not associative). In the python REPL, just give this code a try:

print (0.7 + 0.1 + 0.2) # Prints 1.0 print (0.7 + 0.2 + 0.1) # Prints 0.9999999999999999 

Ancient versions of CAM350 were using floating point arithmetic internally, and however they were doing their calculations and floating point to fixed point conversion, it wasn't properly accounting for these small numerical errors inherent in floating point math. This would result in arcs with the same start and end coordinate no longer having the same start and end coordinates, which of course results in some absolutely massive arc getting drawn instead.

Fortunately, these errors were too small to actually impact anything except in one specific circumstance: when the gerber was using the highest possible fixed point precision. In other words, it is really only an issue when specifically using both 4:6 coordinate format and metric units. This is the highest resolution, with 4:6 in inches having 1/25th the resolution, and even 4:5 metric having 1/10th. All other combination of units and coordinate formats other than metric and 4:6 are unaffected by this bug.

4:6 in metric is equal to 1nm resolution, while 4:5 metric is 10nm. You do not need 1nm resolution, nor do you need 10nm resolution. Even 4:6 in inches (25nm resolution) is overkill. The gerber to CAM conversion has a built-in ±0.5µm tolerance so you will loose that additional accuracy whether you like it or not, and that's not even factoring physical manufacturing tolerances like layer registration error etc.

What I am getting at is the correct way to avoid this bug is to simply export your gerbers using the 4:5 coordinate format, or export them in inches. That's all you need to do to ensure you will never be impacted by this bug.

If you can't re-export the gerbers, then just truncate off the last digit of every coordinate (or round if you really want to, but it doesn't matter) and change %FSLAX46Y46*% to %FSLAX45Y45*%

Here's how to do it with sed:

file=<path to gerber> sed -i -E 's/([XYIJ]-?[0-9][0-9][0-9][0-9][0-9]+)([0-9])/\1/g' "$file" &&\ sed -i 's/FSLAX46Y46/FSLAX45Y45/' "$file" 
\$\endgroup\$
2
  • \$\begingroup\$ I'm sorry to tell you that that's not it. It's not entirely true that G75 does nothing, it does configure how 360° circles are handled. This command may or may not be obsolete in modern gerber versions, but the thing is that specific historic CAM350 versions (may even be pre 2000) have a bug occuring with G75 enabled. So it's not an issue with the gerber format, but with this specific piece of software. This version is easy to pirate and often used by smaller chinese companies. You can find it on the chinese internet and it is... OLD :D \$\endgroup\$ Commented Apr 18 at 12:48
  • \$\begingroup\$ The issue I was talking about definitely has nothing to do with floating point precision and replacing full circles with quarter circles proofed to be a solid workaround, which I'm using since - though we avoid these manufacturers for moral reasons.Eventually I decided against publishing my code for the same reasons. \$\endgroup\$ Commented Apr 18 at 12:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.