Custom DRC distance rule with exception

Hey,
I try to create a custom distance rule. The distance shall be 1.5 mm to all nets but ground.
I don’t know how set up this rule. This is what I have for now:

(rule “Minimum distance to all Nets 1.5mm”
(condition “A.NetClass == ‘1.5mm’”)
(constraint physical_clearance (min 1.5mm))
)

Thanks for all help!

That rule will only apply to items of the Net Class “1.5mm”.

You probably want something more like (condition "A.NetClass != 'GND'") (assuming you use the “GND” Net Class to flag all your ground nets).

A netclass would normally be a name, not a named constraint. Like “HV” for high voltage.
So you want net to net to be 1.5mm, except all nets to ground , where you need the limit clearance ?

perhaps if ground is the exception, then create a global constraint of say 1,5mm just for ground net

(rule “ground clearance example”
(condition “A.NetName == ‘GND’”)
(constraint physical_clearance (min 1.5mm)))

@JeffYoung, BTW my k8rc2 doesnt like spaces in the rule name string between single quotes but is OK with double quotes.

@glenenglish, be careful with @ names, you are calling someone completely different than JeffYoung…

1 Like

Thanks for your answers.

Yes, the NetClass name is 1.5mm in this case. What I want is actually simple in a distance matrix:
Net “1.5mm” against all other nets: clearance min. 1.5 mm
Net “1.5mm” against GND: 0.2 mm

This is needed because failure against GND is safe and against the other nets not.
Maybe the name is not the best without context, but in the schematic it makes sense.

Any ideas how to do so? Or is it impossible beause its kind of overwriting itself.

(rule “Minimum distance to all Nets 1.5mm”
(condition “A.NetClass == ‘1.5mm’”)
(constraint physical_clearance (min 1.5mm))
)

(rule “Minimum distance Net 1.5mm to GND”
(condition “A.NetClass == ‘1.5mm’ && B.NetClass == ‘GND’”)
(constraint physical_clearance (min 0.2mm))
)

Be sure you are using at least V8 rc2. rule systems before that are… sketchy.

you can do something like this with net names (or you could have A. NetClass && B.NetClass

or
(rule “ground clearance example”
(condition “A.NetClass == ‘MYNETCLASS’ && B.NetName != ‘GND’”)
(constraint physical_clearance (min 1.5mm)))

(rule “ground clearance example”
(condition “A.NetClass == ‘MYNETCLASS’ && B.NetName == ‘GND’”)
(constraint physical_clearance (min 0.2mm)))

or global…
(rule “ground clearance example”
(condition “A.NetClass == ‘MYNETCLASS’ && B.NetName != ‘MYNETCLASS’”)
(constraint physical_clearance (min 1.5mm)))

I have no idea where to find the version of the rules system.

I tried this now for two classes, but it does exactly nothing.
The classes are attached to the track in the schematic. Do I need to configure the Netclass in the PCB configurator in the layout editor? That would not make sence because I will do it with the rules, right?

(version 0)

(rule “Minimum distance Net 1.5mm to GND”
(condition “A.NetClass == ‘1.5mm’&& B.NetName == ‘GND’”)
(constraint physical_clearance (min 0.2mm))
)

(rule “Minimum distance Net 1.5mm to all other”
(condition “A.NetClass == ‘1.5mm’ && B.NetClass != ‘GND’”)
(constraint physical_clearance (min 1.5mm))
)

(rule “Minimum distance Net 1.5mm_to_all”
(condition “A.NetClass == ‘1.5mm_to_all’ && B.NetName !=‘1.5mm_to_all’”)
(constraint physical_clearance (min 1.5mm))
)

NetClass must be a name, not a value. Just like NetName. Do you have a netclass called 1.5mm?

Yes, that is the name as you can also see on the screenshot of the schematic. Here is where I define the class. Is it sufficient there?

I’ve been using custom rules since v6 and I wouldn’t describe it as sketchy at any point. There were a handful of bugfixes in those 2-3 years and lots of features added. The feature additions do not matter for this basic usecase, except perhaps clearance vs physical_clearance.

@snooziestStuff please tell us your KiCad version (copy from the About KiCad window). Some of the details have changed from version to version.

In any version, you don’t need to use physical_clearance, you can just use clearance for copper-to-copper. physical_clearance considers all types of objects, runs slower, and was added later so may not be present in your version of KiCad.

As I mentioned in another thread, any time you have issues getting a clearance rule to work the way you expect, use the clearance inspector to figure out why. Select both traces, then hit Inspect → Clearance Resolution.

Thanks, that helped. I found out, that the Netclass was not assigned in the schematic. You see this Pin in the screenshot above? I thought that will assign the netclass, but it doesn’t.

I will now figure out, how to assign netclasses.
I’m on KiCad 7.06

You see this Pin in the screenshot above? I thought that will assign the netclass, but it doesn’t.

The Pin assigns the netclass. But as a first step you have to define the netclass in File–>Schematic Setup–>Project–>Net Classes.
Long description here: Schematic Editor | 7.0 | English | Documentation | KiCad

After defining the netclasses you have to “Update the pcb from Schematic” to get the netclass introduced to the pcb.

1 Like

Ok, I needed to setup the netclasses in the schematic designer, those little poles where not sufficient. Now it is working. Further I needed to add GND to NetClass GND, which results in a funny symbol like that (any way to avoid that?!)

grafik

(rule “Minimum distance Net 1.5mm to GND”
(constraint clearance (min 0.2mm))
(condition “A.NetClass == ‘1.5mm’&& B.NetName == ‘GND’”)
)

(rule “Minimum distance Net 1.5mm to all other”
(constraint clearance (min 1.5mm))
(condition “A.NetClass == ‘1.5mm’ && B.NetClass != ‘GND’”)
)

(rule “Minimum distance Net 1.5mm_to_all”
(constraint clearance (min 1.5mm))
(condition “A.NetClass == ‘1.5mm_to_all’ && B.NetName !=‘1.5mm_to_all’”)
)

I wished we would have chosen the distance matrix and not this way of programming everything. I mean it is powerful, I know, but the usability is not great.

Thanks for helping!

You don’t need to use the net class directive labels, they are just one way of several to assign net classes. You can also assign net classes in schematic/board setup using wildcard expressions. For example, for your ground case I would just add a line in schematic setup that assigns all nets matching GND* to the GND net class. See the docs linked earlier for details. The directive labels you are using are good for when you really want to visually see the net class assignments, or when you’re assigning net classes to unnamed nets.

Finally, when you’re writing custom rules, keep in mind that later rules override earlier rules (as well as the default rules set in the GUI). So you can write a generic 1.5mm clearance rule, with no net class qualifications, and then follow that with a specific rule that overrides it in certain situations. The general rule could also probably just be your default clearance set in the GUI.

Thank you very much. Looks like I oversaw the link. It explains it pretty good. I think there are quite some good options to setup the rules as I need them. The wildcard is great. Can I use it for defining rules, too?

Snooziest - take a look at my thread of questions, might be useful. BTW for a net like ground, convention is not to use a netclass for that. Use netclasses for things light high voltage nets (more clearance), nets that must be times, nets that MUST be thick and width (current) etc.

and

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