A very good question. I have spent some time looking into this, it’s been a struggle since
Anyway, here’s what I found:
For transistors and MOSFETs, even for the symbols in pspice.lib, you need to supply some additional info. If you don’t supply the info, you get an error like this:
UX Note: The error message scrolls out the window, so it is easy to miss. It just looks like it “didnt work” for no reason.
The extra info can be supplied in several ways:
- specify an ngspice
model
corresponding to the symbol value in a text comment. e.g. if the value is “qnpn”, you need to specify .model qnpn npn
Here is an example using symbols from pspice.lib after example #1 in the ngspice manual (Chapter 21. Example Circuits)
You can also specify more complex models using the same method (provided the model is compatible with ngspice), e.g.
Putting ngspice directives in the schematic had the advantage of being self-contained, but can bloat the schematic.
An alternative is to create a spice “library file”, containing the corresponding directives. For example, put the following lines into a plain text file using a text editor (not a word processor) and save it somewhere:
*
* Generic models for ngspice
*
.model qnpn npn
.model qpnp pnp
.model npn npn
.model pnp pnp
.model nmos nmos
.model pmos pmos
*ZETEX BC108 Spice model Last Revision 23/3/00
*
* (C) 1991 ZETEX PLC
*
* The copyright in this model and the design embodied belong to
* Zetex PLC ("Zetex"). It is supplied free of charge by Zetex for
* the purpose of research and design and may be used or copied
* intact (including this notice) for that purpose only. All other
* rights are reserved. The model is believed accurate but no
* condition or warranty as to its merchantability or fitness for
* purpose is given and no liability in respect of any use is
* accepted by Zetex PLC, its distributors or agent.
*
* Zetex PLC, Fields New Road, Chadderton, Oldham OL9 8NP
*
.MODEL BC108 NPN IS =1.8E-14 ISE=5.0E-14 NF =.9955 NE =1.46 BF =400
+ BR =35.5 IKF=.14 IKR=.03 ISC=1.72E-13 NC =1.27 NR =1.005
+ RB =.56 RE =.6 RC =.25 VAF=80 VAR=12.5
+ CJE=13E-12 CJC=4E-12 VJC=.54 MJC=.33
+ TF =.64E-9 TR =50.72E-9
The Zetex model is reproduced according to license.
Now you have more options. You can include the library file directly in the schematic:
OR edit the symbol and associate the model to the symbol.
- Place the symbols like so (all from pspice.lib):
- click “Edit Properties” for Q1 then “Edit Spice Model”
- Click “Select file” and browse to the “library file” you created earlier:
- Select the model from dropdown. (You don’t have to use the same model as the symbol value)
- The symbol Q1 properties should now look like this. Note: the spice properties now override the “Value” field. For transistors, “Spice_Primitive” must be “Q”.
Over time, you will likely build up your own collection of ngspice models in your spice library file.
Note: examples tested with kicad Version: (5.0.0-rc2-dev-266-gbad462a22), debug build KICAD_SPICE=ON
Finally, here is a sample project as complete and simple as I can make it: ex1_trans_amp.zip (1.7 KB)
@Rene_Poschl @Joan_Sparky is this FAQ-worthy?