Kicad NGSpice - Pls check my 741 OpAmp Simulation

I’m just learning Spice and Kicad NGSpice. Please check my simple DC Amplifier Circuit using a 741 OpAmp.

The simulation seems to be working but I’ve got some questions as I’m low on the learning curve and just feeling my way along right now …

Question 1 - Searched for 741 OpAmp Model and downloaded from the TI site. Unzipped & got the files & folders below …

library LM741-PSpiceFiles lm741.dsn lm741.lib lm741.libsig lm741.opj Do I need all these or just the .lib file?

Question 2 - I put the folder with the stuff shown above in the project folder so they were easy to find BUT … Where would Models (.mod files) and Library files like the above be normally stored on a typical system?
I would think they would all be in the same folder somewhere instead of scattered all over the hard drive … But how do you do it to keep things organized?

Question 3 - I’ve attached an image of the schematic and 741’s Spice Model Editor …
Do things look correct? Did I populate the Spice Model Dialog correctly?

Question 4 - I didn’t see a Integrated Circuit “Type” so I chose “Subcircuit” as opposed to “Code Model”
Was that the right choice? And for future reference how would I know which one to pic? For instane if the model were a partname.mod file or whatever.

Thanks for double checking me and for any help and comments.

  1. You only need the lm741.lib file.
  2. I’d suggest storing your Spice models in your project. There’s no Spice library management system at the moment, this is something we’ll be working on.
  3. Looks good to me.
  4. Code models are a work-in-progress feature in the nightly builds. These models are available through the XSPICE Ngspice extension and allow for behavioral analog or event-driven modeling through C code. At the moment you are very unlikely to encounter them when doing simulations. Op amp Spice models are almost always subcircuits, so your choice is right. A model is a subcircuit if its definition starts with .SUBCKT (case-insensitive).

Please note that since you are using the nightly builds you may encounter bugs, crashes, and data loss. Unless you’re feeling adventurous, or want to test the latest features, it’s advised to use the latest stable version.

Are you sure your alternate pin sequence work?

From what I know you have to turn it around, you take the pin numbers in KiCad, and you list to what spice pins they are mapped. In your case it would be more like:

xxx 2 1 50 xxx 28 99

But the xxx replaced with something else. Pins 1 and 5 of the KiCad symbol are not mapped into the spice model, but I do not know how to put that in the node sequence.

It’s also only a visual thing, but I would flip almost the whole schematic in the Y direction, so positive voltages are at the top and voltages toward the bottom get lower.

I do not have much experience with ngSpice in KiCad, or even Spice in general.

Thinking it would be simple, I started using Kicad for simulation, only to discover two important things:

  1. I did Not have a full grasp on the scheme-of-things, regarding simulations

  2. I was starting out with a ‘Too-difficult’ circuit

I solved my lack of knowledge by:

• Using LTspice (verrrry simple, powerful and complete libraries)

• Read some basic tutorials

Once I had a firm-grip on the process/details, I re-did the circuit in Kicad.
Some issues came up that and, after successfully solving them, it became clear to me there were too many problems to Consistently rely on simulations in Kicad without a lot of baby-sitting (that was in v5).

I decided to use NGspice stand-alone. No problems. But, after that dust settled, I pledged to stick with LTspice.

And, I was able to set LTspice as the Simulator program that gets called/run by Kicad.

And, can build the circuit in Kicad, generate Netlist and use the Netlist for LTspice (no fussing…)

Clean/Simple Tutorial: Link To Gosh NGspice Tutorial

Example screenshots below (not the same circuits but, you get the idea…):



Kicad panel to Run LTspice

Helpful resource:

I’ve not yet done much with ngSpice in KiCad, mostly due to focusing and concentration problems, but I would not easily go to using an external simulator.

ngSpice itself is quite mature and decent.
There is a learning curve involved, that much is sure. And the lack of included (and compatible) spice models is quite a big stumbling block for beginners.

I do recommend to start with very simple circuits such as the LED with series resistor posted by BlackCoffee. A blinking LED project is a good way to start with the basics. Whether it’s your first breadboard, your first uC program or a Spice simulation.

If you can get your LED to Blink in ngSpice, then you know you’ve set up your voltage sources and model for the LED properly, and also the simulation parameters. With such a simple circuit as an LED you can also concentrate on whatever that’s needed to setup the simulation, and only later expand on that by adding an opamp, passives or other stuff.

Studying working examples is another resource to exploit.
There are some built in examples in KiCad (if the Demo’s are installed), which among other things have a Sallen-Key filter with an opamp. There are also some examples gathered in:

Search for the book BlackCoffe mentioned:

I encourage using the Tutorial I referenced above (very clear and concise and, perhaps the best one I found to get started from. Goes from 1+1=2 to Calculus (so to speak) in just a few pages.

Once understanding it, building circuits for simulation is straight-forward (but, note, many issues with Kicad’s spice models. One reason to ensure knowledge via doing it outside of Kicad).

Screenshot of a Chirp simulation (common stuff for Noob’s) Done in Kicad and Kicad’s NG simulator…

I find what you did very interesting, but I see that there is no LTSpice for Linux. :frowning:

I think it actually worked under WINE for awhile but it’s been years since I’ve tried it.

Try using PlayOnLinux. I use PlayOnMac to run windows apps on mac.

I discovered this nice, up-to-date LTSpice tutorial (from MIT)

paulvdh… regarding the alternative pin sequence you mentioned …

I took the pin numbers in the sequence shown in the TI Model and mapped them to the pin numbers shown in Kicad for an LM741 … like this

Pin Name TI Pin # Kicad Pin #
Non-inverting Input 1 3
Inverting Input 2 2
Positive Power Supply 99 5
Negative Power Supply 50 7
Output 28 6

And then just lined the Kicad Pin # Sequence in the Alternate node Sequence field …
using a space as a delimiter.

And it seems to work as the calculated circuit gain = R(2)/R(1) = 2
And the Simulation shows V(out) = negative 10 volts, which is double the 5 volt input to the circuit.

I also did the same circuit as an integrator and that seems to work as well…
So, hopefully I got the Alternate pin Sequence correct …
Or, I was just darn lucky :slight_smile:

Wadda you think?


I’ve been using the build below since Feb 15 and have had no trouble.
I started using 6.99 for some feature I thought I wanted but now… duh… I can’t even remember wat it was.
Any estimates when the next stable version will be released?

And, thanks for your response to my OP. Very helpful!

My 6.99 version is shown below …

Application: KiCad (64-bit)

Version: (6.99.0-942-g3129f96686), release build

wxWidgets 3.1.5
FreeType 2.11.1
libcurl/7.78.0-DEV Schannel zlib/1.2.11

Platform: Windows 10 (build 19043), 64-bit edition, 64 bit, Little endian, wxMSW

Build Info:
Date: Feb 15 2022 03:53:16
wxWidgets: 3.1.5 (wchar_t,wx containers)
Boost: 1.76.0
OCC: 7.6.0
Curl: 7.78.0-DEV
ngspice: 36
Compiler: Visual C++ 1928 without C++ ABI

Build settings:

I’ve thought about switching to LTSpice after viewing some LTSpice tutorials… and have even downloaded it and installed it … but so far I’ve been able to get Kicad’s implementation of NGSpice to work for me … even though I understand the issues you referenced.
I’m considering your suggestion about getting LTSpice to run as the default Kicad simulator … even though someone later in the thread discouraged such. I’ll study the matter.
Thanks for your input on this thread.
Very helpful!

Worth mentioning, if you don’t already know… LTSpice is produced by Analog Devices, one of the worlds large semiconductor companies… with $7 Billion in revenue

I would start by using a sine wave as input for the amplifier. That gives much more confidence it works then a DC signal.

Can you zip and upload that project? then I’ll have a look at it. For me it’s a method to get to know ngSpice in KiCad a little bit better.

I’ve attached the project as you asked but I went ahead and modified the signal source to AC.
Sorry, it is in v6.99. Let me me know if that is a problem and I’ll do it over in v6.0.

I setup the AC signal source for …
0v DC offset
1v Amplitude
1k Frequency
blank Delay
blank Damping Factor

When I run the simulation looking at the Input, and the Output I see a sine wave …
Input 1v peak, 2v peak to peak AC
Output 2v peak, 4v peak to peak AC

However when I run the simulation I also see this …
Warning: v3: no DC value, transient time 0 value used

Should I ignore the warning or do I have somethin setup incorrectly?

Thanks for the help.
741 Op Amp Ckt (31.0 KB)

It was something to do with new graphics’ capabilities introduced in 6.99.
I remember mentioning 6.99, with all the appropriate warnings, of course. :slightly_smiling_face:

jmk, yes, I think that was it … new graphics’ capabilities introduced in 6.99.
Any idea when the next stable release may occur?

It’s purported to be an annual occasion, which means next January, maybe, but don’t hold your breath!

I’d better let you get back to your “Spicy” thread. :slightly_smiling_face:

This post should probably be ignored.
It’s quite long and contains too many inaccuracies and faults.
I almost deleted it completely myself.

---- 8<------- 8<------- 8<------- 8<------- 8<------- 8<------- 8<------- 8<------- 8<—

So I installed KiCad:


First trouble was it could not find your model for the LM741, so I changed the path name to:

Then I changed V3 from an “amplitude modulated source”, to a sine wave source, and added a “dc 0”.


changing the source itself does not matter much for spice because it just get’s it’s parameter inputs from the text strings.

And I added a text window in the schematic for which spice analysis to run:
.tran 1u 10m

After that I get the simulation output below. It’s almost a DC voltage at -13.9V

I do not know how to skip some pis in the “alternate node sequence”, and to circumvent that I changed the library symbol of your LM741 with the “Simulation_Spice/Opamp” library symbol, so I do not have to mess with the offset adjustment pin numbers.

And I changed the alternate node sequence to what I think it should be:

After that the simulation stopped working completely. The simulation output only says:

Error: there is no circuit loaded.
Circuit: KiCad schematic
Too few parameters for subcircuit type “lm741” (instance: xxu1)
Error: there aren’t any circuits loaded.

Now I’ve got a nice sinewave output 1.6V above the power supply voltage:

And still a bunch of spice error messages:

Error: there is no circuit loaded.
Circuit: KiCad schematic
Error on line 0 :
a$poly$e.xu1.eos %vd [ xu1.16 xu1.49 ] %vd ( xu1.7 0 ) a$poly$e.xu1.eos
MIF-ERROR - unable to find definition of model a$poly$e.xu1.eos
Warning: Model issue on line 0 :
.model a$poly$e.xu1.eos spice2poly coef = [ 1e-3 1 ] …
Unknown model type spice2poly - ignored
Error on line 0 :
a$poly$f.xu1.f6 %vnam [ v.xu1.v6 ] %id ( /+vcc /output ) a$poly$f.xu1.f6
MIF-ERROR - unable to find definition of model a$poly$f.xu1.f6
Warning: Model issue on line 0 :
.model a$poly$f.xu1.f6 spice2poly coef = [ 450u 1 ] …
Unknown model type spice2poly - ignored
Reducing trtol to 1 for xspice ‘A’ devices
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

I did a search for “spice2poly” and found:

Which helps me nothing.
And after having spend more then an hour on this I give up.
For what it’s worth, my end result:

741 Op Amp Ckt (28.7 KB)

do you hear something? Something like a faint whisper saying, “LTSpice…LTSpice…LTSpice…never a problem…” :wink: