Folks that do software and analog electronics: (and please boost for visibility)

Is there an OSS tool that simulates analog circuits for signals? In particular, I want something that I can script and write expectations of the output signals for given inputs. And ideally that scripting would include programmatically adding/removing/changing components in the simulated circuit and then testing the outputs.

Thanks!

#electronics #analogElectronics #simulations #programming

@mathias There is Qucs, which is like a Spice simulator. I haven't used it in a while and I'm not sure how scriptable it is.

@mathias You an use kicad with a spice:
https://www.kicad.org/discover/spice/

There are python bindings for kicad, but I haven't used them.

SPICE Simulation

KiCad integrates the open source spice simulator ngspice to provide simulation capability in graphical form through integration with the Schematic Editor.

@mathias if I’m understanding you right it seems like you want a SPICE simulator. LTspice is an OSS implementation

@kevin @mathias free, but not OSS

The OG Spice 3 (from 1989) is BSD licensed however. I’m sure there’s OSS derivatives out there

@mathias I’ve used lcapy in the past, though it solves everything algebraically in pure Python so it quickly slows down for complex circuits

Id love to do a proper SPICE from code but I haven’t been able to make sense of any of the Python spice libraries

@mathias Also the open source software Modellica can simulate all kinds of electronic circuits, but I don't know if it simulates also the parasitic effects like most SPICE software.
@mathias It has either a GUI clicky interface but also a equivalent text base programming interface. If it doesn't support self modifying structures, you could at least build a scaffolding around it that generates the models iteratively.
@mathias I've only ever hacked falstad (javacript version) since there is not much on offer. But I haven't looked at recent kicad spice support.
@mathias
ngspice should be powerful enough.
Your goal can be achieved in several ways. Scripts can be used to control the simulator and manipulate the netlist as a text file. Ngspice itself supports "alter" command to change the netlist. VerilogA blocks and switches can be used to perform algorithms, connect or disconnect parts. Ngspice also supports TCLspice, and circuit optimization, the manual has examples.
@oblomov
@mathias
https://ngspice.sourceforge.io/
Is the only open source I knew of, but looking here I see quite a few https://en.wikipedia.org/wiki/List_of_free_electronics_circuit_simulators
I know LTspice is closed source but you can interface via python with pyltspice
Ngspice, the open source Spice circuit simulator - Intro

ngspice - the open source spice simulator for electronic circuits

@mathias Might be some tools that #hamradio hobbyists use.
@mathias depending on how complex your simulation needs to be, spice/qucs as many people have pointed out. For more simplified models of RLC circuits / idealized opamp configs, I had some pretty good success with modelica/systemmodeler (systemmodeler is proprietary and on the $$$ side, but modelica is free and pretty much identical in capabilities): https://blog.wolfram.com/2020/07/23/digital-vintage-sound-modeling-analog-synthesizers-with-the-wolfram-language-and-system-modeler/
Digital Vintage Sound Modeling Analog Synthesizers with the Wolfram Language and System Modeler—Wolfram Blog

How to build a virtual version of a modular synthesizer using the Wolfram Language and System Modeler, modeling and simulation environment.

@mathias

Start with https://en.wikipedia.org/wiki/SPICE

And follow the rabbit hole from there.

SPICE - Wikipedia

@mathias

Circuit emulators - classically SPICE, but there are many descendants from that - do what you want. A bunch are open source or free software. Getting (accurate) models for some components can be problematic, but searching the 'net will generally get you the clues you need to get there.

SPICE software is a big topic. Prepare to dive in...

#SPICE #CircuitEmulator