Eeschema, simulator and libraries

Seems to me that in the simulator included in Kicad (ngspice) the passive components (resistors, capacitors and inductors) have an ideal model and can not be modeled using an equivalent series/paralle circuit giving the possibility to change the values of the parasitic R, L and C values.

This possibility is very important designing switching power supplies and other circuits where they are part of switching circuits. Am I wrong? Any way to solve the problem?

I would like to have my personal library fitted also with the fields needed by the simulator so I am checking/investigating how everything works. It would be great if the library fields may be OK also to export a netlist to LTSpice.
Every answer and suggestion will be very appreciate.

1 Like

The idea is to replace the fixed value reistor by a subcircuit resistor. Inside the subcircuit you may add all parasitic components.

Say you have a resistor from PSPICE library in your circuit, its name R1, its value 1k.

Add a subcircuit in file res_mod.lib to the project folder containing the *.sch file:

* resistor subcircuit model
* file res_mod.lib
.subckt Resis n1 n2
  R1 n1 n_int 1k
  L1 n_int n2 2n
  C1 n1 n2 100p

Double click onto the resistor symbol.
–> Edit Spice model --> Model --> Select File
Select the file res_mod.lib
–> Type --> Subcircuit --> ok --> ok
–> Tools --> Simulator --> Run simulation

1 Like

Massimo, generic spice simulators like ngspice have always used ideal components. Mike Englehardt with LTspice did build in a more complicated capacitor model that allows series and parallel L’s and R’s in the model to simulate switchers a little more easily. (He also did significant work on the simulation engine to make switcher analysis more robust.) This isn’t a very satisfying answer, but you can achieve the same by building a subcircuit for the capacitor. Feel free to add this to the bug list as a wishlist.

ngspice offers various models for resistors, capacitors, inductors. Please have a look at chapt. 3.2.1 of the manual:

Ideal component (may include a temperature dependency model and noise):
R1 n1 n2 1k

A semiconductor resistor (may not be of importance here)

A behavioral resistor, depending on temperature and voltage/current values of other nodes/branches:

R2 r2 rr r = {5k + 50*TEMPER}

.param rp1 = 20
R3 no1 no2 r = ’5k * rp1’ noisy=1

and of course the subcircuit resistor (a subcircuit with two nodes, where you may place whatever contents inside, as described above)

1 Like

Holger, will do. Thanks - it was on my to-do list…

I am a user and fan of LTSpice also if I don’tu se it very very often. At the moment I am thinking how to organiza a set of Kicad linked libraries taking care of schamtic, simulator, and pcb fabrication needs to see if it is possible to use Kicad for my production needs.

Thanks for the answers, I made a trial and it is ok for me, it works. There are still a couple of points for which I did not find an answer so any help will be apprecaited.

  1. Is there a way to pass a parameter from Kicad GUI to the .subckt. For instance tha Value of the resistor may be passed to .subckt trough a variable/place holder or anything else?
  2. Not using the .subckt strategy, Kicad paases the Value field to the Value field in Edit Spice Model/Passive/Value that is a good idea but in eeschema the Value field is linked to the Symbol Name so for instance if you organiza your library to have a symbol for each passive component (I mainly mean resitors, capacitors and inductors) you have to manually adjust the Value on the Spice tab. Is there a way to unlink the eeschema symbol Value from the symbol name? IT should be very useful.

Mmmm… I have some limited experience using PSpice and more using LTSpice, in both cases the syntax of passive components is quite more complex, at least they provide 2 temperature coefficients for the resistors and a lot more for capacitors. For general uses the provided “optional” parameters are not very useful (at least they are set with default values under the hood) but working with switching power suplies and switching circuits require them especially for capacitors and inductors.

Hi Massimo, I’ve been thinking about my use of PCB layout and simulation, and I’ve come to several conclusions. One is that the schematic I use for PCB layout is unsuited for simulation. For example: what level of behavioral abstraction do you use for opamps? Ideal?. Ideal with slew-rate? Ideal with slew-rate and output clamping? Detailed transistor-level? In reality I want to switch between all of them and trade off accuracy vs simulation time depending on what I am simulating. It feels like I want a switch or some sort of selector in the schematic symbol to change between model levels / complexity.

An open conversation about schematics and spice would be interesting to get perspectives.

Why not select an OpAmp and use the model offered by the device manufacturer (PSPICE- or TINA-compatible will do)? These are not transistor-level models, but sort of lumped-element models, and often the model description tells you what is modelled and what not.

If you do for example a transient simulation, you may have in the eeschema circuit editor window a line
.tran 1u 10m
or similar in a text box. You may edit this text box by double clicking into it.

Try adding a line
R1 n1 n2 'val'
to the subcircuit and add a line
.param val=1k
to the text box mentioned above.

1 Like

Hi Holger, asked from the perspective of an old analog guy that wrote my own spice3/xspice c-code models 30+ years ago, what happens when things don’t converge? Do the manufacturers provide support? Or do you have to figure it out for yourself?

That is a reasonable attitude. In practice, I suspect that most design engineers use opamp models based on the “macromodel” concept published by Boyle, Graeme, Cohn et al in 1974 (and subsequently enhanced circa 1990 by engineers at several of the prominent analog IC manufacturers of that era). The IC manufacturers typically publish this type of model for their products; individuals and other organizations may also publish opamp macromodels. A search engine will often uncover several different models for a particular opamp type. I have created quite useful SPICE models using a Datasheet and Analog Devices’ AN-138.

In all cases (including manufacturer-provided models), “Caveat Emptor” applies. A typical opamp datasheet lists dozens of characteristics; each one has a tolerance band, each one has some dependency on temperature and supply voltage, and a particular model may, or may not, even attempt to model a particular characteristic. The majority of these characteristics and their dependencies probably aren’t significant in your particular application, but this varies from one design to another.

Transistor-level models are not generally available for IC opamps designed after about 1970. The other options you mentioned are useful for crude first-cut investigations when more complete models are simply not available. In some cases they are actually “too ideal” for SPICE and will create convergence problems or extend computation time.


Hi Dale, thanks! Good comments.

Then, after the behavioral analog stuff, what do you do for logic / mixed signal models?


I’m trying to get comments from other interested parties.

I haven’t gone very far down that road. I think you get a (usually proprietary) “mixed-signal simulation program”, or study up on the SPICE “extensions” available on some of the no-charge SPICE simulators (including, if I recall correctly, NGSPICE).


Dale, Holger, or Massimo, if you were at KiCon, my apologies for not meeting you. I was one of the people behind the bar serving breakfast/lunch and servicing the drink cooler.

Yep - for quickie logic simulations as well as power supply sims I go to LTSpice. I’d love to go to Kicad… That is what I’m working on.

Unfortunately, I was NOT at KiCON. I certainly wanted to be there, not only to support Chris’ initiative and express some appreciation for all of his work, but also to attach some faces and voices to ID’s here on this Forum. But even though Chicago is an easy train ride from St Louis, KiCON didn’t fit into the budget for the Working Poor.


P.S. - I’d like to say, “I’ll be there next year”, but my wife’s medical situation will probably keep me on a pretty short leash for the next few years.

Dale, I understand your situation.

Yep, I appreciate Wayne, Chris, and all of the developer’s efforts. And want to give back in my own way. I use this program a lot in my daily job.

You may have a look at