summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-06-20 14:40:55 +0200
committerjaseg <git@jaseg.de>2023-06-20 14:40:55 +0200
commitdd8507d202e1fe0dbcb39aacf87fb07eaa07ec8a (patch)
tree54f04eb14ed6c795423009c669cc9b468787f7c7
parentd43308c5cc767d817ac8f77d38c6baf124de1b7c (diff)
downloadgerbonara-dd8507d202e1fe0dbcb39aacf87fb07eaa07ec8a.tar.gz
gerbonara-dd8507d202e1fe0dbcb39aacf87fb07eaa07ec8a.tar.bz2
gerbonara-dd8507d202e1fe0dbcb39aacf87fb07eaa07ec8a.zip
Polish twisted coil generator
-rw-r--r--twisted_coil_gen.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/twisted_coil_gen.py b/twisted_coil_gen.py
index 218c020..253f173 100644
--- a/twisted_coil_gen.py
+++ b/twisted_coil_gen.py
@@ -6,6 +6,7 @@ import os
from math import *
from pathlib import Path
from itertools import cycle
+from scipy.constants import mu_0
from gerbonara.cad.kicad import pcb as kicad_pcb
from gerbonara.cad.kicad import footprints as kicad_fp
@@ -89,8 +90,8 @@ def svg_file(fn, stuff, vbw, vbh, vbx=0, vby=0):
@click.option('--footprint-name', help="Name for the generated footprint. Default: Output file name sans extension.")
@click.option('--target-layer', default='F.Cu', help="Target KiCad layer for the generated footprint. Default: F.Cu.")
@click.option('--jumper-layer', default='B.Cu', help="KiCad layer for jumper connections. Default: B.Cu.")
-@click.option('--windings', type=int, default=5, help='Number of windings to generate')
-@click.option('--diameter', type=float, default=50, help='Outer diameter')
+@click.option('--turns', type=int, default=5, help='Number of turns')
+@click.option('--diameter', type=float, default=50, help='Outer diameter [mm]')
@click.option('--trace-width', type=float, default=0.15)
@click.option('--via-diameter', type=float, default=0.6)
@click.option('--via-drill', type=float, default=0.3)
@@ -99,7 +100,7 @@ def svg_file(fn, stuff, vbw, vbh, vbx=0, vby=0):
@click.option('--clearance', type=float, default=0.15)
@click.option('--clipboard/--no-clipboard', help='Use clipboard integration (requires wl-clipboard)')
@click.option('--counter-clockwise/--clockwise', help='Direction of generated spiral. Default: clockwise when wound from the inside.')
-def generate(outfile, windings, diameter, via_diameter, via_drill, trace_width, clearance, footprint_name, target_layer,
+def generate(outfile, turns, diameter, via_diameter, via_drill, trace_width, clearance, footprint_name, target_layer,
jumper_layer, twist_width, num_twists, clipboard, counter_clockwise):
if 'WAYLAND_DISPLAY' in os.environ:
copy, paste, cliputil = ['wl-copy'], ['wl-paste'], 'xclip'
@@ -112,11 +113,25 @@ def generate(outfile, windings, diameter, via_diameter, via_drill, trace_width,
svg_stuff = [jumper_path, out_path]
pitch = clearance + trace_width
- twist_angle = 2*pi / (windings * num_twists - 1)
+ twist_angle = 2*pi / (turns * num_twists - 1)
twist_width = twist_angle * twist_width/100
via_diameter = max(trace_width, via_diameter)
+ # See https://coil32.net/pcb-coil.html for details
+
+ d_inside = diameter - 2*(pitch*turns - clearance)
+ d_avg = (diameter + d_inside)/2
+ phi = (diameter - d_inside) / (diameter + d_inside)
+ c1, c2, c3, c4 = 1.00, 2.46, 0.00, 0.20
+ L = mu_0 * turns**2 * d_avg*1e3 * c1 / 2 * (log(c2/phi) + c3*phi + c4*phi**2)
+ print(f'Outer diameter: {diameter:g} mm')
+ print(f'Average diameter: {d_avg:g} mm')
+ print(f'Inner diameter: {d_inside:g} mm')
+ print(f'Fill factor: {phi:g}')
+ print(f'Approximate inductance: {L:g} µH')
+
+
make_pad = lambda num, x, y: kicad_fp.Pad(
number=str(num),
type=kicad_fp.Atom.smd,
@@ -155,8 +170,8 @@ def generate(outfile, windings, diameter, via_diameter, via_drill, trace_width,
lines = []
arcs = []
- for n in range(windings * num_twists - 1):
- for k in range(windings):
+ for n in range(turns * num_twists - 1):
+ for k in range(turns):
r = diameter/2 - trace_width/2 - k*pitch
a1 = n*twist_angle + twist_width/2
a2 = a1 + twist_angle - twist_width
@@ -168,7 +183,7 @@ def generate(outfile, windings, diameter, via_diameter, via_drill, trace_width,
xm, ym = r*cos(a3), r*sin(a3)
arcs.append(make_arc(x2, y2, x1, y1, xm, ym))
- for k in range(windings-1):
+ for k in range(turns-1):
r1 = diameter/2 - trace_width/2 - (k+1)*pitch
r2 = diameter/2 - trace_width/2 - k*pitch
a1 = n*twist_angle - twist_width/2
@@ -196,7 +211,7 @@ def generate(outfile, windings, diameter, via_diameter, via_drill, trace_width,
lines.append(make_line(x1, y1, xv1, yv1))
a += twist_width
- rs = diameter/2 - trace_width/2 - (windings-1)*pitch
+ rs = diameter/2 - trace_width/2 - (turns-1)*pitch
rv = rs + trace_width/2 - via_diameter/2
x1, y1 = rs*cos(a), rs*sin(a)
@@ -239,7 +254,7 @@ def generate(outfile, windings, diameter, via_diameter, via_drill, trace_width,
name=name,
generator=kicad_fp.Atom('GerbonaraTwistedCoilGenV1'),
layer='F.Cu',
- descr=f"{windings} winding twisted coil footprint generated by gerbonara'c Twisted Coil generator, version {__version__}",
+ descr=f"{turns} turn {diameter:.2f} mm diameter twisted coil footprint, inductance approximately {L:.6f} µH. Generated by gerbonara'c Twisted Coil generator, version {__version__}.",
clearance=clearance,
zone_connect=0,
lines=lines,