To control leakage to/from very high impedance nodes, I have to use many guard rings/traces.
These guard traces must be free of solder mask (i.e. exposed) so that they can readily intercept external leakage.
How to make this in KiCad ? I have found some older questions here, which used some customs scripts for it, but I thought I’d rather ask.
In EasyEDA it is as easy as just selecting traces and clicking “expose copper”. This will create a copy of the traces in the mask layer
As this option doesn’t seem to exist in Kicad, I tried copying the trace and manually pasting it into the Mask layer, but I just couldn’t figure out how to do it.
I would have to manually draw lines above the traces which is quite a lot of work for something that could be done with a basic copy-paste?
Is there a simpler way?
This seems easy to script though.
The steps for exposing copper are:
Copy (copies all selected trace segments)
modify the text according to: replace segment with gr_line and .Cu" with .Mask" and remove the (net X)
KiCad tries very hard to keep copper tracks and graphics separated, and this is one of the circumstances where this is quite a hindrance.
There is an issue on gitlab for this, which has a milestone (twice?) for KiCad V7, and the second time was just a week ago:
Is this copy on the mask layer an independent copy, or does it stay linked to the copper tracks?
One of the best implementations I can think off is to just add a flag to copper tracks, and when that flag is set, it also removes the mask from such a track segment. This way the mask moves with the copper track if it get’s pushed and shoved around. Maybe it should also have a clearance value (positive or negative) to adjust the mask cutout width.
In EasyEDA, it currently just creates a separate trace in the Mask layer, which will be left behind if you move the copper trace. Obviously, this solution is not excellent either.
Adding a flag to traces makes definitely the most sense… As I have just starting layouting with Kicad I also miss other features such as controlling the Mask cutout diameter on vias. So maybe such a “expose” flag could be used for more objects than merely traces.
So I made a python script to help me. Maybe it helps anyone else, or some adept coder could add what’s missing to make a Kicad extension out of it.
My workflow is as follows:
1.) I select the traces I want to expose. One segment per trace is enough - followed by the ‘U’ button.
2.) I Ctrl-C and paste the clipboard into a file called ‘covered_copper.txt’
3.) I run the py script (below) which does all the modifications turning the traces into mask openings with adjustable overwdith. It creates a new file called ‘mask_openings.txt’
4.) I paste the new file’s content into PCB Editor.
#use regular expression matching module 're'
import re
# Read in the file
with open('covered_copper.txt', 'r') as file :
filedata = file.read()
# Replace various strings
filedata = filedata.replace('segment', 'gr_line')
filedata = filedata.replace('.Cu")', '.Mask")')
# Delete the (net XYZ) property of the lines
filedata = re.sub(r'\(net.*\) \(', '(', filedata)
# Optionally adjust line width
widthadjust = 0.1
def modifynum(matchobj):
num = matchobj.group(0)
modstr = float(num) + widthadjust
return f'{modstr}'
matchpatt = '(?<=\(width )\d+(?:\.\d*)?(?=\))'
filedata = re.sub(matchpatt, modifynum, filedata)
# Write the file out again
with open('mask_opening.txt', 'w') as file:
file.write(filedata)
I guess the steps 2+3+4 could be merged into a Kicad extension somehow, removing the awkwardness of the file I/O and copy/pasting.