Having trouble simulating in KiCAD?

Hi guys, I am a mature ‘distant learning’ electronic course student. I do most of my study at home.
I have been looking at Kicad (and Eagle) as a means of creating and simulating projects set by my tutor, so I can then present them.
I like Kicad a lot in every way except that I can’t get the simulator to work properly. Using symbols from both the pspice and simulation-spice .libs I have successfully simulated very basic circuits. However, I have problems simulating simple discreet and opamp circuits e.g I find using the npn in spice still requires a bias voltage applied to the vsource, even though I set it up using two resistors to set the base of the npn. It’s as if they weren’t in the circuit. Also using the pspice opamp as a non-inverting amp - whatever I do with the feedback loop I always get unity gain, as if the opamp wasn’t in the circuit at all.
These are just a couple of reason where spice modelling isn’t working for me. I have read lots about spice modelling in Kicad and even if I follow directions to the ‘T’ it just doesn’t work well for me. Which means I have nothing to present to my tutor.
Now - this may be entirely my fault, perhaps I am doing, or have set something wrong,.; I’m using the latest 5.2 version on a MAC. At the moment I am having to use Eagle which does produce the correct results, but I find it limiting and very clumsy - After trying both I much prefer Kicad if only I could get it to behave reliably.
Also, though I have put the ngspice.lib in my libraries directory it doesn’t appear in Kicad.
Friends, any useful suggestions or pointers would be gratefully received. BTW I have re-installed latest stable rendition of Kicad a couple of times to no effect.
I do notice that - looking at the symbols spice editor there is nothing in the device type fields. If I put something in or try to connect to a spice.lib ; when I try to simulate the circuit I get an error stating ‘simulation aborted’ stating ‘no subcircuit loaded’?
Sorry about running on, but I am pulling my hair out by the handful just now.
Thanks again.

The easiest way to help you out is either uploading your KiCad schematic and/or your SPICE netlist. Netlist can be generated by following the instructional image below:

Thanks heaps, I’ll knock something up and do this today.

Hi Ste, here are some screenshots that I produced this morning demonstrating my issue. I do hope this proves useful.
This first shows a simple voltage divider behaving as it should:

This two show a filter ladder as it should be:

result:

These show a BC546 BJT amp:

result:

Lastly an Op amp using all pspice symbols. Note the output an input are unity?? even though there should be a x10 gain in the circuit as I see it:

the result - in and out are on top of wach other?

What the pspice op amp spice editor looks like as it is shipped. I have BTW, tried loading several models, but the simulator aborts sitting, there was no subckt loaded?

I do hope this is useful and with a little help I can knuckle down with Kicad rather than having to resort to Eagle to produce demonstratable examples.

Thanks heaps.

Oh, I forgot to add the netlist. This is for the last ‘op amp’ circuit.
1.net (3.6 KB)

Please be cautious when stating your program version. Version 5.2 does not exist and AFAIK there is no plans for 5.2. There are two versions that start with a 5 and end with a 2, 5.0.2 and 5.1.2, and there are differences between the two. 5.1.2 is the more recent version with some UI changes, a bunch of bugs fixed, and (probably) it’s own collection of new bugs. (So goes software development…) :wink:

1 Like

You skipped a step in my instructions. Please click on the “Spice” tab (step #2) as shown in the screenshot, before you export the netlist. Can you also export the BJT circuit netlist too so I can see both?

The trouble with getting started with ngSpice in KiCad is that there are no spice models delivered with KiCad, which makes it a bit difficult to get anything going.

I have done a few experiments with ngSpice in KiCad.
I started with the Sallen-Key demo project (Which can be installed as a part of KiCad), and to get that working I had to install a newer version of ngSpice. There is a manual on Sourceforge to get ngSpice going with KiCad.

Also, have you read the Eeschema manual?
Chapter 16 deals with the interface between Eeschematics and ngSpice. Eeschema is primarily for schematic entry for PCB design, and opamp pins are numbered accordingly. In Spice models the pins are often numbered differently.
By looking at the pin numbering of a Spice model I found on Internet, I managed to connect a schematic symbol weirdly to get the simulation going:
image
This is of course pretty silly (but it works). Chapter 16 of the Eeschema manual explains how to do the pin mapping properly, but I have not experimented much with that aspect of Eeschema yet. I only discovered accidentally that the Eeschema manual has a chapter about Spice, after I got it working with the weird conection above (Silly me).

1 Like

@paulvdh makes a good point. KiCad simulation is a bit rough around the edges to get going. The SPICE talk from KiCon should be posted soon, but it’s hard to cover all the nuance within 25 minutes. There’s a reason the first half of the talk covers underlying SPICE concepts before digging into the KiCad interface because understanding those concepts is vital for navigating simulation in KiCad.

@monkshood Honestly, if you’re only goal is standalone simulation without real circuit construction you’re probably better off with something much more intuitive, like LTspice. You’re on Mac, so it has a native version available:
https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice-simulator.html

Here is a schematic snip which duplicates your opamp circuit. I also attached the .ASC file for it which will run in LTspice without any additional futzing around.

ltspice_opamp.asc (890 Bytes)

One last thing is your opamp circuit was kind of wrong. Your input was swinging from -1V to +1V and your opamp rails were going from 0V to 5V. This means the negative part of the sine wave would saturate and get distorted. The opamp model I used in the above example is an ideal one usually taught in early chapters of electronics textbooks, which ignores the power rails.

Thanks, sure I missed the 1 in 5.1.2 oops. I have the current mac 5.1.2 version.

Ta heaps.

Thanks for this ste. I can replicate this in LTspice exactly as you demonstrate and it works just as I would expect. When I transpose it into Kicad (5.1.2) however I get the same old result. I’m quite sure it’s something I’m not doing right. I need to explore more about: [.lib] [.include] and other spice related commands; also applying spice model files to symbols.

Much work to be done I reckon!

It’s gonna take a bit of time and effort to get used to simulating in KiCad. Please make sure you follow the intro guide first: http://ngspice.sourceforge.net/ngspice-eeschema.html

And here’s a KiCad project with the same opamp circuit used in the LTspice example. You should be able to analyze and play around with these two examples to get you more familiar with this stuff.

opamp_test.zip (2.3 KB)

It’s also gonna take a bit of time and effort to get KiCad used to interfacing with the user. :wink: Work in progress.

By Jove I think I’ve got it?

After 2 days of getting no where, this morning I loaded the pspice opamp symbol (again!), produced the same circuit as you and I successfully did in LT (which I did last night in Kicad again to no effect) This morning I downloaded the TI LM741.mod and LMV981.mod; added them (in turn) as modules, Used the ‘alternative node’ option and entered 1 2 4 5 3. Hazarh it work exactly as it says on the tin. So now I can present material to my tutor without having to mess around with gifferent simulation suites. Phew!!

1 Like

@hermit No worries. I know it’ll get there eventually.

@monkshood Nice Work! Hopefully it makes better sense now. Eventually, the KiCon talk would be posted so it can help other people in your shoes with similar issues getting started.

How odd, after a day of pulling my hair out trying to figure out why my subckt models would not function, suddenly, this evening I got them, well some of them, to function. I did this by ensuring the spice model was in the same directory as the project. Then those that did work seemed to do so consistently. Those, however, that I put in another directory (a spice model repository if you will) sometimes worked and at other times didn’t?. It’s as if kicad suddenly couldn’t find the directory I had stored them in (that had previously worked).

Sometimes when running a sim it would report ‘no subckt loaded simulation aborted’. Other times, with no alteration to the circuit, all would be well?

In summary, I now put any spice model I’m using in a circuit in the actual project directory. Which means I will have several occurrences of the same spice model scattered in different project directories. My OCD makes me think I would rather reference a spice model from a single central location rather than spreading copies of the same spice model throughout different project directories.

Hi, here are some observations on Mac with KiCad 5.1.2-1:
Adding a net label results in an error with ngspice.
The op-amp_test.zip from above does work fine, even if I add an LM324 model from TI.
But as soon as I using labels like ‘input’, ‘output’ etc. to find the signals easier, the simulation stops working!
Also using commas for rearranging the pins was new to me, but not the reason for problems I think.

Please try the following (tested with standard ngspice, not with KiCad):

in file .spiceinit (see http://ngspice.sourceforge.net/ngspice-eeschema.html#setting for reference) add the line

set sourcepath = ( . full-path-of-folder-with-all-my-model-libs )

Please note the . and the spaces between the brackets and the text.

what is simulator command?

In what context is that question being asked?

During generating spice netlist what to write in simulator command?