I thought it was time to post updates to the things I have noticed while testing the ngspice simulation called directly from within EEschema.
I have posted about this before, but I am updating my notes as I find new quirks.
Spice assumes pins in its models to be:
MOSFET: m[name] [drain] [gate] [source] [substrate]
JFET: j[name] [drain] [gate] [source] [model]
BJT: q[name] [collector] [base] [emitter] [model]
DIODE: d[name] [anode] [cathode]
MESFET: ZXXXXXXX ND NG NS
Many models in KiCAD libs are not designed for use with ngspice
and hence the pin numbers are not in accordance with the assumptions
in ngspice listed above. Even Diodes differ.
Use ‘alternate pin’-field in spice settings. In practice this
means ‘alternate pin’ configurations are used for almost all
Parts that are not relevant for the simulation, like
connectors or heatsinks, must be disabled
for simulation in edit/spice model.
Otherwise results are unpredictable
(like >130kA flowing out of connector
It is possible to use models that are downloaded from manufacturers, but most manufacturers do offer models for pspice. There are slight differences, see below.
Some models are implemented using SUBCKT. In the Spice settings, the ‘Spice primitive’ must be set to ‘X’.
Model or subckt names should not contain ‘-’.
From the ngspice manual: “A name
field must begin with a letter (A through Z) and cannot contain any delimiters.”
In practice, many spice models downloaded from manufacturers, written for pspice,
will have to be adapted to follow the ngspice naming conventions.
Ngspice does not seem to fully follow the rules above. It does allow some delimiters, such as the hyphen, but be aware of the naming conventions and check in case of difficulties.
Comments start with '* ’ so ‘*#’ is not ok. (this is probably a bug in ngspice)
This is another reason why downloaded pspice models need to be adapted before
use with ngspice.
@hermit made the remark that on some part models, the pins are not numbered but named. He used the 7805 voltage regulator as an example.
"The pins in the symbol are in the correct order but they are not numbered. "
The spice model, however, uses pin numbers. For instance (first two lines op 7805 subckt):
.SUBCKT LM7805 1 2 3
- In GND Out
I have not found an7805 without pin numbers in the recent libraries, but I suppose that cases like this can be solved by using the ‘Alternate node sequence’ field in the Spice settings.
Alternate node sequence IN,GND,OUT
Watch the spice results for unexpected results like enormous currents because they can be a clue that something in the pin ordering is wrong.
@hermit also added the following hint:
One hint you might add is, “Do your plots look upside down?” It was the key to my realizing the diodes were backwards. Took too long. I was so used to seeing examples of fully rectified AC as positive peaks I didn’t immediately recognize I had the right graph.
Please feel free to comment or add to this.
N.B.: I am offering a download as an example schematic that illustrates most of the points mentioned above, but note that the libraries are currently under reorganisation. You might need to tweak the library settings a bit to get to all parts in the example.
CurrentsourceKiCAD-NGspice03.zip (7.0 KB)