Spice simulation via KiCAD


#5

I am normally running the nightlies, hermit. I have had small problems, but in general it is solved the next day or so. It happened last, oh, months ago. First Q of 2017, if I remember correctly, so I would not worry too much about stability.
If your flavour of Linux is Ubuntu, there is a repository (ppa), so you need not compile from source yourself, if you do not want to.


#6

Steves asked for an example.
I would like to propose using this schematic as an example. It is not very useful as a device, but it does demonstrate a couple of things to note when using ngspice from EEschema. See also the attached zip below.

Comments are welcome, as usual.
CurrentsourceKiCAD-NGspice03.zip (7.0 KB)


#7

Well, that is my ‘getting started’ problem. I am running Debian. It is a little behind the times. I’ll probably spin up a VM with Ubuntu for this. I ran Mandrake (Mandriva ) for years because it was the Ubuntu of Redhat. When that disappeared I went for ‘stable’.


#8

Yep, I like debian as well, but there is much more to do yourself than there is with ubuntu. A 'buntu VM sounds a reasonable compromise. I personally prefer the Gnomebuntu variant, because running Gnome in both environments is easier for compatibility.
Good luck.


#9

I was wrong in my remark that SUBCKT is currently not supported by the gui.
It is.
I have changed my demo project accordingly and fixed the download above. If you have installed the previous version, please add the new version (with the number 02 in the filename) as well.


#10

Thank you for posting this. I have downloaded and will try it out.


#11

Thanks for the example file! I was having issues running simulations components not included in the spice library and your model helped me realize the requirement for the .lib model for each part.

Where did you get these files or learn to write them. I learned how to use LTspice just last night to test my circuit but would like to contain this step in KiCad.

Could you otherwise point me towards a resource that would help me find or generate or download these models. I was looking around for a KiCad or ngspice mode library (something that contains the .lib files referenced in the “edit spice model > model > select file…” dialogue. This is something i feel would have been answered in a tutorial but I can’t seem find any that go beyond using standard components (R, C, L).


#12

Here is a tutorial: http://ngspice.sourceforge.net/ngspice-eeschema.html


#13

I think the great drama here is to have the “MODELS”…

That is the tricky part…

And once you have them collected… where do you put them all
so as the system can trace the pile of stuff you collect…


#14

The general topic of “Spice Models” is about an order of magnitude more complicated than the topic of “Footprints”. There is some discussion about the complexity in old threads on this Forum. Just for starters, the various companies who have implemented Spice-based simulators often have their own extensions and improvements to the Spice syntax. In most cases it isn’t difficult to convert a model designed for one version of Spice to run on another version.

Some manufacturers supply Spice models for their components. A few individuals have developed libraries of Spice models and make them available online. Also join the Yahoo User’s Group for LTSpice at LTSpice Group . There are many models in their “Files” area, and examples in the discussion threads.

Dale


#15

As dchisholm and PKTKS have pointed out, the difficulty is in the models. They are absolutely correct.

While it is true that manufacturers supply models for some of their parts, they’re often made for some specific spice implementation, such as Pspice, for example. Pspice does have a number of built-in’s that are not in ngspice, which explains why some of the models that were written for Pspice do not work in ngspice and are not easily portable either.

It is all a bloody mess and a great nuisance, but, I fear, the thinking behind all this is closed source minded. LTspice is offered for free, but it is closed source and it assumes you are doing all work in LTspice itself. Openness is not a priority.

It would be very efficient if all the effort in adding built-ins, making models etc. would all be directed towards one single open source version of spice, but at the moment that has proven to be a step too far for the closed source mindedness.

We will have to live with that for the time being. I hope that, one day, we will see that the Pspice and LTspice people offer their efforts to the open source community. In the mean time, I will keep on dreaming :wink:

That said, it would be neat if the kicad community would be able to share a collection of spice models to go with ngspice, but it will hardly be complete, I fear. If such a collection exists already, I would love to get a pointer to it, because I have missed it.

Also, spice models are usually intended to be used for a specific purpose and sometimes do not accurately model the real life behaviour of the part. Many models model the behaviour of a part that is behaving as intended under normal circumstances, but do not accurately model the part when it is used beyond its limits, for instance. Things like failure modes, noise modelling, lockups, power supply rejection, etc. are not always modelled accurately in the models that are supplied for free.

Hence it is prudent to acquire the skills to write models yourself, which would be perfect in combination with some sort of shared collection within our community. At the very least, in my view, one should be able to judge the quality of supplied models.

m


#16

As an example of how complicated accurate modelling can be, this article will serve as an illustration.
I have been looking into accurately modelling loudspeakers myself, but it is no mean feat.
See: Article by Jürgen Micka about spice modelling loudspeakers.
m


#17

This is not correct any more!

ngspice-28 well reads PSPICE model files and does the translation from PSPICE to ngspice syntax automatically. All of the manufacturers’ PSPICE models are now available for ngspice, in addition to TINA ones. If something is missing or does not work, just give a hint here or at the ngspice user forum.

The only issues we cannot solve are encrypted models. Encryption and Open Source are diametrically opposed , so I am not aware of any solution.

In addition ngspice-28 now contains the VDMOS model that has been famous in LTSPICE to model MOS power transistors.

The KiCad developers however decided to stick to ngspice-26 for the upcoming release. Therefore I will give a short explanation on how to switch from ngspice-26 to 28 in my tutorial.


#18

This is wonderful news.

EDIT: Omitted needles blahblah

I will certainly give Pspice models another go, because if Pspice models work, that would solve a lot of trouble for me. Thanks holger.

m


#19

That would be most welcome. Appreciated!

EDIT: Couldn’t wait. Found this thread:

m


#20

Testing libngspice 28. It seems to be working from eesched.
Is there any way I can easily verify which version of libngspice is being loaded by eesched?
Do you have a quick setup that would work in 28 but not in 26?

m


#21

A small VDMOS output file with power transistor.

With ngspice-28 you will get some 56 A output current (Id(M1)), with ngspice-26 a default model is used, resulting in an error message
Error on line 3 :
m1 /drain /gate 0 0 ixth80n20l
Unable to find definition of model ixth80n20l - default assumed
and an output current of a mere 500µA.

start-test.7z (1.0 KB)


#22

Thanks.
And succes! My eesched is using 28.

Now where did I store my jfet models…

m


#23

The next one (non-inverting amplifier with OpAmp) is for checking if the PSPICE option is available
(remember setting

set ngbehavior=ps

in .spiceinit)

You have to download the OPA171 model from TI at
http://www.ti.com/lit/zip/sbom440

The input file: OpAmp_ps.sch (3.9 KB)

If ps compatibility is not enabled, a bunch of errors will be shown. If o.k., watch V(/in) and V(/out).


Mosfet simulation ends with error [SOLVED]
#24

Continuing the saga.
I implemented a small model for potentiometers, inspired by this page from pspice.com.

I have the ‘ngbehavior=ps’ set, so I was assuming my pots.lib should be in PSpice lingo.

The following two definitions are in my pots.lib:

.SUBCKT LINPOT (top, tap, bottom) PARAMS: R=1k SET=0.5
RTOP top tap {R*(1-SET)+0.001}
RBOT tap bottom {R*SET+0.001}
.ENDS LINPOT

and

.SUBCKT LOGPOT (top, tap, bottom) PARAMS: R=1k RANGE=1000 SET=0.5
RTOP top tap {R-(R/RANGE)*PWR(RANGE,SET)}
RBOT tap bottom {(R/RANGE)*PWR(RANGE,SET)}
.ENDS LOGPOT

Now I needed to pass the extra parameters to my model via the gui and to do that I added the parameters to the ‘Spice_Models’ field in the gui. This usage is not documented, as far as I could tell, but it is working, and I hope this functionality will stay. It is very convenient.

As an example, in the schematic I have used the symbol for a pot, annotated it as ‘X1’, in the spice gui I used the ‘Models’ tab and set the ‘Spice_Model’ field to

LINPOT PARAMS: R=47k SET=0.1

As another example, for a logarithmic potentiometer I set the ‘Spice_Model’ field to:

LOGPOT PARAMS: R=20k RANGE=1000 SET=0.5

This is all working fine and behaves like intended.
I have not seen any documentation about this use of parameters via the gui, though.
Any comments?
m