-
I've been able to run a SPICE simulation using Is there any way to do both things from the same schematic? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Here's one way to write some SKiDL code that generates an SVG schematic or does some SPICE stuff: from skidl.pyspice import *
draw_schematic = False # Set True to draw schematics, False to do SPICE stuff.
if draw_schematic:
# Use the KICAD Device library if you want to draw schematics.
uselib = SchLib("Device", tool=KICAD)
set_default_tool(KICAD)
else:
# Otherwise, use the PySpice library.
uselib = SchLib("pyspice", tool=SKIDL)
set_default_tool(SPICE)
# Create your circuit using the selected library of parts.
r = Part(uselib, "R", value=1@u_kOhm)
c = Part(uselib, "C", value=1@u_uF)
gnd & r & c & gnd
if draw_schematic:
# Draw the schematic.
generate_svg()
else:
# Otherwise, do some SPICE stuff in here...
print(generate_netlist()) You'll probably want a custom library of SPICE symbols when generating a schematic since the from skidl.pyspice import *
draw_schematic = False
if draw_schematic:
# Use the KICAD Device library if you want to draw schematics.
uselib = SchLib("My_SPICE_Library", tool=KICAD)
# Import the part names into the namespace so they can be instantiated easily.
import sys
_this_module = sys.modules[__name__]
for p in uselib.get_parts():
setattr(_this_module, p.name)
set_default_tool(KICAD)
else:
# Otherwise, use the PySpice library.
uselib = SchLib("pyspice", tool=SKIDL)
set_default_tool(SPICE)
# Create your circuit using the selected library of parts.
r = R(value=1@u_kOhm)
c = C(value=1@u_uF)
gnd & r & c & gnd
if draw_schematic:
# Draw the schematic.
generate_svg()
else:
# Otherwise, do some SPICE stuff in here...
print(generate_netlist()) |
Beta Was this translation helpful? Give feedback.
I added a simple method to
Part
objects to convert them into a form that's compatible with SPICE:Here's a simple test program I wrote that shows how it's used: