Just do
git clone https://github.com/FabriceSalvaire/PySpice
and install everything that it needs:
PySpice requires the following dependencies:
- Python 3
- Numpy
- Matplotlib
- Ngspice
- CFFI (only required for Ngspice shared)
The way to organize a project is to have the file.py, a folder called libraries and inside put folders with the element.lib files. These can also be put into folders to easily organize things. Then, call this
libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)
circuit.include(spice_library['2n2222a'])
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Resistor
circuit.R( name, +node, -node, value)
circuit.R(1, 'out', circuit.gnd, kilo(5))
Capacitor
circuit.C(1, +node, -node, value)
circuit.C(1, +node, -node, value, initial_condition=5)
BJT
circuit.BJT(1, 'collector', 'base', circuit.gnd, '2n2222a')
Results
analysis.base : the voltage of node named 'base'
Interesting features
https://github.com/FabriceSalvaire/PySpice/blob/gh-pages/downloads/voltage-divider.py
Shows how to put a voltage source defined in Python into Spice. This probably means that you can have an arbitrary function generator in Python!!!
No hay comentarios:
Publicar un comentario