I’ve been intending to do this for a while now, but haven’t really gotten the chance to figure it out until some recent toilet reading of this PDF: https://www.analog.com/media/en/technical-documentation/application-notes/AN-138.pdf
A while back, I posted a super simple opamp subcircuit which is purely linear and doesn’t take the voltage rails into account. I use this model frequently in my own work since it’s fast and gets you decent results as long as you are aware of the limitations. However, there are times where I need to consider saturation due to the voltage rails, mainly in comparator applications. I typically use LTspice and it has a handy built-in device called the “UniversalOpamp2” which has 4 different levels of models to pick from using a drop-down menu. The first two levels are the most practical, and I constantly use them. Level 1 is the same as the model I described above without voltage rail consideration. Level 2 adds quite a bit of functionality since it includes the voltage rails in the netlist.
Anyway, to get back on topic here, I wanted to create something similar to Level 2 which can be used in ngspice so people can use it in KiCad. Not only is this type of behavioral model faster and has less convergence issues than semiconductor-based models, it can also be used when no model is available from the opamp manufacturer. You just need to plug in a few datasheet values into the subcircuit parameters to get a rough approximation to the opamp you want to model.
I attached a library file of my own “Universal Opamp” models, which include both Level 1 and Level 2. The Level 2 is loosely based on the app note PDF I linked above. I removed all semiconductors and replaced all the diodes with voltage-controlled switches [EDIT (2019-12-11): v1.1 reverted back to semiconductors due to convergence issues]. I’ve tested both models in LTspice and KiCad 5.1.4 (for Windows). I structured the text such that it’s easier to read the comments and parameter descriptions when selecting the subcircuit model within Eeschema. The only parameter that’s missing between my version and the LTspice version is slew-rate, which I’m still not certain the best way to implement while retaining fast simulation speed. Maybe I’ll update it later along with a few other improvements, but I’m releasing this as is for now.
Below are a few screenshots of the models in action, particularly showing the GBW and Vrail parameters working. These models should work with any KiCad opamp symbol, provided the “Alternate node sequence” is properly mapped as defined in the library comments. Overriding the parameters from the defaults requires you to type them in after the model name. You can do this when selecting the model in the Spice Model Editor, or you can make the “Spice_Model” field visible on the schematic and edit the text like any other text. Although, if you use a lot of parameters with the text visible it could cause a bunch of clutter on the schematic.
uopamp_v1.1.lib (3.6 KB)