コード例 #1
0
def footprint():
    try:
        args = parse_spiral_request()
    except Exception as e:
        return flask.render_template('error.html', error=str(e))
    args['width'] -= args['trace_width']
    args['height'] -= args['trace_width']
    inductance = flask.request.values.get('inductance', default='')
    resistance = flask.request.values.get('resistance', default='')
    qfactor = flask.request.values.get('qfactor', default='')
    capacitance = flask.request.values.get('capacitance', default='')
    coil = list(squarespiral(args['width']/2, args['height']/2, args['pitch'],
        args['turns']))
    description = 'PCB inductor {}m x {}m {} turns {}m pitch'.format(
        format_si_prefix(args['width']*1e-3),
        format_si_prefix(args['height']*1e-3), 
        args['turns'], format_si_prefix(args['pitch']*1e-3))
    description += ' inductance {} Q={} at {}Hz'.format(
            inductance, qfactor, args['frequency'])
    description += ' generated with https://github.com/ignamv/kicad_scripts'
    response = flask.Response(mimetype='text/plain',
            headers=[('Content-disposition',
                'attachment; filename = pcbantenna.kicad_mod')])
    write_trace_footprint(response.stream, 'PCBAntenna', description,
            coil, args['trace_width'], args['pad_size'])
    return response
コード例 #2
0
def calculate():
    if flask.request.values.get('download', type=bool, default=False):
        return footprint()
    try:
        args = parse_spiral_request()
    except Exception as e:
        return dict(success=False, error=str(e))
    args['width'] -= args['trace_width']
    args['height'] -= args['trace_width']
    coil = ((x, y, 0) for x,y in squarespiral(args['width']/2, args['height']/2,
        args['pitch'], args['turns']))
    try:
        impedance = coil_impedance(coil, args['trace_width'],
        args['trace_height'],
        args['frequency'], 
        './fasthenry')
    except TimeoutExpired:
        return dict(success=False, error='Calculations took too long')
    angfreq = 2 * math.pi * args['frequency']
    resistance = format_si_prefix(impedance.real) + 'Ω'
    inductance = format_si_prefix(impedance.imag / angfreq) + 'H'
    qfactor = '{:.2g}'.format(impedance.imag / impedance.real)
    capacitance = format_si_prefix(1 / (angfreq * impedance.imag)) + 'F'
    args.update(resistance=resistance, inductance=inductance, qfactor=qfactor,
            capacitance=capacitance)
    return dict(success=True, resistance=resistance, inductance=inductance,
            qfactor=qfactor, capacitance=capacitance,
            download=flask.url_for('footprint', **args))
コード例 #3
0
ファイル: cmdline.py プロジェクト: ignamv/kicad_scripts
    pitch = args.separation + trace_width
pitch *= args.scale
zpitch = args.zpitch * args.scale
if args.pad_size is None:
    pad_size = trace_width
else:
    pad_size = args.pad_size * args.scale

if args.thickness is not None:
    trace_height = args.thickness * args.scale
else:
    # 1 oz/ft² copper is 1.5 mils thick = .03406 mm
    trace_height = args.weight * .03406

if args.shape == 'square':
    coil = spiral.squarespiral(side1, side2, pitch, args.turns)
else:
    coil = spiral.ellipticalspiral(side1, side2, pitch, args.turns,
            args.vertices_per_turn)
coil = list((x * args.mirror, y) for x,y in coil)

if args.fasthenry:
    angfreq = 2 * math.pi * args.frequency
    Z = coil_impedance(((x,y,ii*zpitch/4) for ii, (x,y) in enumerate(coil)),
            trace_width, trace_height, args.frequency)
    L = Z.imag / angfreq
    C = 1 / (angfreq * Z.imag)
    Q = Z.imag / Z.real
    print('Analysis of {}m x {}m {}-turn {}m pitch {}m trace inductor at {}Hz\n'.format(
        si_prefix_format(side1*2e-3), si_prefix_format(side2*2e-3), args.turns,
        si_prefix_format(pitch*1e-3), si_prefix_format(trace_width*1e-3),
コード例 #4
0
    pitch = args.separation + trace_width
pitch *= args.scale
zpitch = args.zpitch * args.scale
if args.pad_size is None:
    pad_size = trace_width
else:
    pad_size = args.pad_size * args.scale

if args.thickness is not None:
    trace_height = args.thickness * args.scale
else:
    # 1 oz/ft² copper is 1.5 mils thick = .03406 mm
    trace_height = args.weight * .03406

if args.shape == 'square':
    coil = spiral.squarespiral(side1, side2, pitch, args.turns)
else:
    coil = spiral.ellipticalspiral(side1, side2, pitch, args.turns,
                                   args.vertices_per_turn)
coil = list((x * args.mirror, y) for x, y in coil)

if args.fasthenry:
    angfreq = 2 * math.pi * args.frequency
    Z = coil_impedance(
        ((x, y, ii * zpitch / 4) for ii, (x, y) in enumerate(coil)),
        trace_width, trace_height, args.frequency)
    L = Z.imag / angfreq
    C = 1 / (angfreq * Z.imag)
    Q = Z.imag / Z.real
    print(
        'Analysis of {}m x {}m {}-turn {}m pitch {}m trace inductor at {}Hz\n'.