Python Library for Planar Magnetics

This topic comes up once in a while, but I thought I would share an open-source project I am working on for designing planar magnetics for power electronics in KiCAD. Right now it can draw variable width spirals.

As well as inductors designs implementing the CFFC concept.

<Won’t le me post a second image as I am a new user>

Library can be found here. It is a work in progress.

4 Likes

Looks like it could be very useful, thanks.

Something to consider would be to put a minimum radius on the sharp points.

John

Thanks @JohnSG. Is there a way to specify that as a config option for a polygon, or do I need to specify new arcs at the corners?

This is very much alike your other post:

That other post was on a specific question relating to turning the polygon generation into a component. This post is meant to advertise the project and to let others node that the code is available, where to find it, and what is its state.

This is dope! I did this by hand a while ago lol… saving this, may come in handy soon :slight_smile:

That project could use some usage examples.
Have you thought of making it a kicad plugin? See docs, there are many examples in kicad plugin manager.

3 Likes

Yup, I hear you. I will work on that.

1 Like

Sorry, I do not actually use KiCAD at the moment, so I cannot help you. Still on Altium, but looking at KiCAD. Mostly I am waiting for a database library, since that is a work requirement. I was only suggesting from the point of view of someone who has done some power circuit layouts.

There are debates back and forth about whether or not sharp points are bad from a manufacturing standpoint, but they are definitely bad in that they result in high electric field and this can cause a failure mode in power electronic PCBs.

John

OK @JohnSG , smoothing arcs. This was surprisingly difficult trig.

1 Like

It looks beautiful!

John

I think there are some settings on the zone to let kicad smooth the corners.

Thanks @nickoe. I originally experimented with just using min thicknesses on the polygon lines to simulate edge smoothing, but was not happy with the result because it wouldn’t smooth inner corners. I ended up just writing a smoothing library which takes a list of arc segments and solves for tangential cornering arcs in between each. This allows for a true arc specification with mathematically optimized smoothing.

image

def smooth_polygon(polygon: Polygon, radius: float) -> Polygon:
    """Smooth the corners of a polygon

    Adds smooth transitions with tangential arcs in between the points of a polygon

    Args:
        polygon (Polygon): The origin polygon to smooth
        radius (float): The radius of the smoothing arcs

    Returns:
        Polygon: A new polygon with smoothed corners
    """

    assert radius > 0, "The radius must be a positive number"

    # smooth the corners
    arcs = [polygon.points[0]]
    for arc in polygon.points[1:]:
        arcs.extend(round_corner(arcs.pop(), arc, radius))

    # don't forget to smooth the start-to-finish transition
    arcs.extend(round_corner(arcs.pop(), arcs.pop(0), radius))

    return Polygon(arcs, polygon.layer, polygon.width, polygon.fill)
2 Likes

Ok, no worries. Good that you made a solution you are happy with :slight_smile:

I am running into a small issue with trying to export designs as a footprint file format. It appears you are not allowed to include vias in SMT footprints, which makes it impossible for me to connect the inductor/transformer turns across different layers. What I want amounts to what is effectively a net-tie spanning multiple layers with vias with the symbol of an inductor. Workaround right now is to simply not use an inductor/trnasformer in the schematic and just use shorts and manually include the planar magnetics geometries, but this seems really hacky and makes the schematic confusing. If I could generate footprint files that can be attached to the right symbols that would be WAY cleaner.

Why do you care that footprint is SMT? THT footprints can have smt pads.

I guess I don’t really. What are you suggesting? Just switching to TH and stimulating vias with TH pads? Can I still tent the “vias” and remove copper pads from unuseds layers (important for creepage from voltages generated between turns).

Yes. To “tent” the tht pads you should be able to remove the mask layers and there is also a property for only generating rings on connected layers.

1 Like

This worked great. Thanks @qu1ck!

Generated with just the following three lines of Python code.

from planar_magnetics import Cffc
    
inductor = Cffc(inner_radius=4.9e-3,
                 outer_radius=9e-3, 
                 num_turns=6,
                 voltage=500)

inductor.to_kicad_footprint("Cffc_Inductor_01")
3 Likes

@qu1ck,

I added some better examples to the project REAME. I plan to add more comprehensive documentation using sphinx with time.

I am not planning on creating a kicad plugin as this is designed to be a generic pip installable library, but I believe a plugin could easily be created using this. I will try and get a release onto PyPi in the next few weeks to simplify this.