Trouble with custom DRC rules

Hi there,

We’re working on setting the minimum clearance for different copper thicknesses on our PCB. We have a 6-layer board where the inner layers have a copper thickness of 2 oz, and the outer layers have a thickness of 1 oz. We’re looking to establish clearance rules for each layer to ensure that we can properly validate the spacing constraints.

We’ve tried the following rules without success. Does anyone have any suggestions on how to set this up?

(version 1)

(rule "InnerClearance"
   
   (constraint clearance (min 0.2mm))
	(condition "A.Layer == 'In1.Cu 2oz' || 'In2.Cu 2oz' || 'In3.Cu 2oz' || 'In4.Cu 2oz' "))

(rule "OuterClearance"
   
   (constraint clearance (min 0.127mm))
	(condition "A.Layer == 'F.Cu 1oz' || 'B.Cu 1oz' "))

Try:

(version 1)

(rule "InnerClearance"
   
   (constraint clearance (min 0.2mm))
	(condition "A.Layer == 'In1.Cu 2oz' || A.Layer == 'In2.Cu 2oz' || A.Layer ==  'In3.Cu 2oz' || A.Layer == 'In4.Cu 2oz' "))

(rule "OuterClearance"
   
   (constraint clearance (min 0.127mm))
	(condition "A.Layer == 'F.Cu 1oz' || A.Layer ==  'B.Cu 1oz' "))

(I’m assuming you’ve changed your layer names to include the copper weight)

Just guessing, but maybe the rules get confused by spaces in layer names. I never use spaces in identifiers, path names etc, even when they are supposed to be supported. There are just too many bugs lingering in such areas.

1 Like

Nope. It’s because the || (or) operator applies to the whole expression, not just the right hand side.

Note there appears to be a bug in the interactive router not updating clearance sizes (visually in the status bar, at least) when changing layers. I’m taking a look.

Hey James. That seemed to fix it. I also updated kicad and it seems to be reliable now.

Should I use A.Layer == 'In2.Cu 2oz' or A.existsOnLayer('In1.Cu 2oz')
I’m not sure of the differences between these two.

I guess (again) that

A.existsOnLayer(  'In*' )

may also work. From the Syntax help

All function parameters support simple wildcards (* and ?).

1 Like

The difference is for items that exist on multiple layers (such as vias). For items which only exist on one layer (such as a track), they are equivalent. For items on multiple layers, A.Layer will only match the name of the first layer the obect is on, whereas A.existsOnLayer will match any layer the object exists on.

1 Like

I’ve just fixed this for v8 and v9.

4 Likes

For economy of expression and efficiency, the best option might be


(rule Inner
	(layer inner)
	(constraint clearance (min 0.2mm)))

and nothing else. Notice that you can as well leave the outer layers out and handle them through the GUI with netclasses and board settings Constraints. For the inner layers, this textual rule overwrites the rules defined in the GUI. The reference manual says

While the layer of objects can be tested in the condition clause as described below, using the layer clause is more efficient.

The rule also seems to work for vias, at least when zones are filled: the filling next to via has smaller clearance in the outer layer and larger in the inner layer. Using the layer clause isn’t identical to using a condition clause, not even when when rule match is tested (and not only for efficiency as the manual would let you understand). The reference manual doesn’t describe the difference adequately, and doesn’t describe nuances for sure.

Sometimes custom rules are dangerous because they seem to work but the situation changes when the layout changes. Imagine for example that you replace 6 zones in different layers with one zone which exists in all layers. Whether you use X.Layer== or existsOnLayer, the old rules may work differently for the new situation. I even doubt if you can write a rule you want using X.Layer and existsOnLayer so that it works always, at least easily. The layer clause may be the only way.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.