def simulate(self): nTurns = float(self.nTurnsLineEdit.text()) innerRadius = float(self.innerRadiusLineEdit.text()) pitch = float(self.pitchLineEdit.text()) spacing = float(self.spacingLineEdit.text()) traceWidth = float(self.traceWidthLineEdit.text()) cuThickness = float(self.cuThicknessLineEdit.text()) pcbThickness = float(self.pcbThicknessLineEdit.text()) nLayers = int(self.nLayersLineEdit.text()) freq = float(self.freqLineEdit.text()) d = float(self.drawTolLineEdit.text()) # compute smaller filament size (see fasthenry docs) nw = 2 # fasthenry default nh = 2 # fasthenry default nwinc = 1 # needs to be odd while True: n = (nwinc - 1) / 2 # rounding down nfils = (2.0 - nw**n * (1.0 + nw)) / (1 - nw) fw = 1e-3 * traceWidth / nfils # smaller width filament size if (fw < self.delta): break nwinc = nwinc + 2 nhinc = 1 # needs to be odd while True: n = (nhinc - 1) / 2 # rounding down nfils = (2.0 - nh**n * (1.0 + nh)) / (1 - nh) fh = 1e-6 * cuThickness / nfils # smaller height filament if (fh < self.delta): break nhinc = nhinc + 2 # print 'nwinc =', nwinc # print 'nhinc =', nhinc sf = dos.fh_file('test.inp') sf.write_header(nwinc, nhinc) #draw_arcs_spiral(N_turns, r_in, pitch, tr_w, N, dir) dir = 1 inductorStyleIndex = self.indStyleCB.currentIndex() if (inductorStyleIndex == InductorStyle.SQUARE): vx = dos.square_spiral(nTurns, innerRadius, pitch) else: vx = dos.circ_spiral(nTurns, innerRadius, pitch, dir, d) sf.add_circ_spiral(vx, 1, traceWidth, cuThickness * 1e-3, pcbThickness) sf.add_ports() if (nLayers == 2): vx = dos.circ_spiral(nTurns, innerRadius, pitch, -dir, d) sf.add_circ_spiral( vx, 2, traceWidth, cuThickness * 1e-3, pcbThickness) sf.add_ports() sf.add_frequency(freq * 1e6) sf.close() sf.run() freqs, mats = sf.readZc() if (nLayers == 1): Xs = mats[0][0][0].imag Rs = mats[0][0][0].real else: Zs1 = mats[0][0][0] Zs2 = mats[0][1][1] M1 = mats[0][0][1] M2 = mats[0][1][0] # inductors in series, aiding; minus sign due to coils ports order Zs = Zs1 + Zs2 - (M1 + M2) Xs = Zs.imag Rs = Zs.real Ls = 1e6 * Xs / (2.0 * math.pi * freqs[0]) # uH Q = Xs / Rs self.simIndLineEdit.setText("%.3e" % Ls) self.simResLineEdit.setText("%.3e" % Rs) self.simQLineEdit.setText("%.1e" % Q) return Ls
def writeModule(self): fname, ok = QFileDialog.getSaveFileName(self, 'Save Module', '.', 'Footprint (*.kicad_mod);;Any File (*)') if (not fname): return if (not fname.endswith('.kicad_mod')): fname = fname + '.kicad_mod' nTurns = float(self.nTurnsLineEdit.text()) innerRadius = float(self.innerRadiusLineEdit.text()) pitch = float(self.pitchLineEdit.text()) spacing = float(self.spacingLineEdit.text()) traceWidth = float(self.traceWidthLineEdit.text()) nLayers = int(self.nLayersLineEdit.text()) d = float(self.drawTolLineEdit.text()) polygonVertexCount = None geometricPrimitives = None dir = 1 inductorStyleIndex = self.indStyleCB.currentIndex() if (inductorStyleIndex == InductorStyle.CIRCULAR_SEGMENTS): # circular segments geometricPrimitives = dos.circ_spiral(nTurns, innerRadius, pitch, dir, d) elif (inductorStyleIndex == InductorStyle.CIRCULAR_ARCS): # circular arcs polygonVertexCount = int(self.polygonVertexCountLineEdit.text()) geometricPrimitives = dos.arcs_spiral(nTurns, innerRadius, pitch, dir, polygonVertexCount) elif (inductorStyleIndex == InductorStyle.SQUARE): # rectangle geometricPrimitives = dos.square_spiral(nTurns, innerRadius, pitch) # Check if making an inductor from the given parameters is at all possible if (geometricPrimitives is None): self.showInvalidParametersErrorMsg() else: sm = dos.kmodule(fname) sm.write_header(name='SIND', descr='spiral inductor', tags='SMD') if (inductorStyleIndex == InductorStyle.CIRCULAR_SEGMENTS): # circular segments vx = geometricPrimitives sm.add_circ_spiral(vx, 'F.Cu', traceWidth) if (nLayers == 2): pad1 = vx[-1] # inductor starts at end of top spiral vx = dos.circ_spiral(nTurns, innerRadius, pitch, -dir, d) sm.add_circ_spiral(vx, 'B.Cu', traceWidth) sm.add_thru_pad('lc', 'circle', vx[0], dos.Point(0.6, 0.6), 0.3) end_layer = 'B' else: # single-layer spiral pad1 = vx[0] # inductor starts at center of spiral end_layer = 'F' pad2 = vx[-1] # inductor ends always at end of last spiral elif (inductorStyleIndex == InductorStyle.CIRCULAR_ARCS): # circular arcs arcs = geometricPrimitives sm.add_arc_spiral(arcs, 'F.Cu', traceWidth) if (nLayers == 2): # inductor starts at end of top spiral p_end = arcs[-1][1].copy() # starting point of the last arc p_center = arcs[-1][0] # centre of the last arc theta = arcs[-1][2] # arc starting point p_end.rotate_about(p_center, theta) # end point of the circular arc pad1 = p_end arcs = dos.arcs_spiral(nTurns, innerRadius, pitch, -dir, polygonVertexCount) sm.add_arc_spiral(arcs, 'B.Cu', traceWidth) sm.add_thru_pad('lc', 'circle', arcs[0][1], dos.Point(0.6, 0.6), 0.3) end_layer = 'B' else: # single-layer spiral # inductor starts at center of spiral pad1 = arcs[0][1] # starting point of the last arc end_layer = 'F' # inductor ends always at end of last spiral p_end = arcs[-1][1].copy() # starting point of the last arc p_center = arcs[-1][0] # centre of the last arc theta = arcs[-1][2] # arc starting point p_end.rotate_about(p_center, theta) # end point of the circular arc pad2 = p_end elif (inductorStyleIndex == InductorStyle.SQUARE): # rectangle vx = geometricPrimitives sm.add_circ_spiral(vx, 'F.Cu', traceWidth) # single-layer spiral pad1 = vx[0] # inductor starts at center of spiral end_layer = 'F' pad2 = vx[-1] # inductor ends always at end of last spiral else: pass # add SMD pads at the beginning and end padSize = dos.Point(traceWidth/2.0, traceWidth/2.0) sm.add_smd_pad('1', 'rect', pad1, padSize, 'F') sm.add_smd_pad('2', 'rect', pad2, padSize, end_layer) #draw_arcs_spiral(nTurns, innerRadius, pitch, traceWidth, N, dir) sm.write_refs(0, 0, ref='REF**', value='LLL') sm.close()
def writeModule(self): fname = QtGui.QFileDialog.getSaveFileName(self, 'Save Module', '.', 'Footprint (*.kicad_mod);;Any File (*)') if (not fname): return if (not fname.endsWith('.kicad_mod')): fname = fname + '.kicad_mod' nTurns = float(self.nTurnsLineEdit.text()) innerRadius = float(self.innerRadiusLineEdit.text()) pitch = float(self.pitchLineEdit.text()) spacing = float(self.spacingLineEdit.text()) traceWidth = float(self.traceWidthLineEdit.text()) nLayers = int(self.nLayersLineEdit.text()) d = float(self.drawTolLineEdit.text()) sm = dos.kmodule(fname) sm.write_header(name='SIND', descr='spiral inductor', tags='SMD') dir = 1 if (self.indStyleCB.currentIndex() == 0): # circular segments vx = dos.circ_spiral(nTurns, innerRadius, pitch, dir, d) sm.add_circ_spiral(vx, 'F.Cu', traceWidth) if (nLayers == 2): pad1 = vx[-1] # inductor starts at end of top spiral vx = dos.circ_spiral(nTurns, innerRadius, pitch, -dir, d) sm.add_circ_spiral(vx, 'B.Cu', traceWidth) sm.add_thru_pad('lc', 'circle', vx[0], dos.Point(0.6, 0.6), 0.3) end_layer = 'B' else: # single-layer spiral pad1 = vx[0] # inductor starts at center of spiral end_layer = 'F' pad2 = vx[-1] # inductor ends always at end of last spiral else: # circular arcs # FIXME: make N below user-configurable instead of 4 arcs = dos.arcs_spiral(nTurns, innerRadius, pitch, dir, 4) sm.add_arc_spiral(arcs, 'F.Cu', traceWidth) if (nLayers == 2): # inductor starts at end of top spiral p_end = arcs[-1][1].copy() # starting point of the last arc p_center = arcs[-1][0] # centre of the last arc theta = arcs[-1][2] # arc starting point p_end.rotate_about(p_center, theta) # end point of the circular arc pad1 = p_end arcs = dos.arcs_spiral(nTurns, innerRadius, pitch, -dir, 4) sm.add_arc_spiral(arcs, 'B.Cu', traceWidth) sm.add_thru_pad('lc', 'circle', arcs[0][1], dos.Point(0.6, 0.6), 0.3) end_layer = 'B' else: # single-layer spiral # inductor starts at center of spiral pad1 = arcs[0][1] # starting point of the last arc end_layer = 'F' # inductor ends always at end of last spiral p_end = arcs[-1][1].copy() # starting point of the last arc p_center = arcs[-1][0] # centre of the last arc theta = arcs[-1][2] # arc starting point p_end.rotate_about(p_center, theta) # end point of the circular arc pad2 = p_end # add SMD pads at the beginning and end padSize = dos.Point(traceWidth/2.0, traceWidth/2.0) sm.add_smd_pad('1', 'rect', pad1, padSize, 'F') sm.add_smd_pad('2', 'rect', pad2, padSize, end_layer) #draw_arcs_spiral(nTurns, innerRadius, pitch, traceWidth, N, dir) sm.write_refs(0, 0, ref='REF**', value='LLL') sm.close()