I’m relatively new to simulating circuits in KiCad and ngspice, and I’m currently facing a challenge with modeling ferrite core inductors and transformers. Specifically, I’ve been attempting to use the ngspice Magnetic Core model and Inductive Coupling model to simulate saturation behavior. Here’s what I’ve done so far:
Ferrite Core Inductor:
I’ve created a model for a toroidal ferrite core inductor. However, it only seems to work properly when a current source is applied. When I attempt to simulate it with a voltage source, the simulation aborts due to an ‘unrecorded case’ error. Surprisingly, the same circuit simulation works perfectly in a separate ngspice simulation, regardless of whether a current or voltage source is used.
I1 VIN 0 SIN(-0.5 1 10000) R1 VIN MED 1 R2 MOT MKD 1 R3 MMF MAT 1 A1 MED 0 MMF 0 windings
*A2 MAT MOT iron_core *
.control run plot I(R2) .endc .end
Transformer:
Additionally, when I create a transformer model in KiCad, it consistently interrupts the simulation with the same error unless I connect a very high ohmic load (1GOhm) to the secondary side.
Has anyone else encountered a similar problem or can offer insights into what might be causing these issues in the KiCad simulation tool for both cases? I would greatly appreciate any guidance or suggestions you can provide.
If it is working in discrete ngspice, you may put all of the inductor circuitry into a subcircuit and attach this to the inductor symbol.
Simulating with a voltage source will only work if you have a series resistance in your inductor. Otherwise you cannot determine an operating point.
If you have a transformer, both the primary and the secondary side will need a dc path to ground. Otherwise ngspice (and all other spices) cannot determine which is the eletric potential of this floating part.
0 Ohm resistors are not allowed in spice, in ngspice they will be converted to 1 mOhm resistors.
I have now tried to combine both models of magnetic core and inductive coupling with all the additional circuitry into one subcircuit for KiCad. This is what it looks like now:
R6 SUP MED 1
R7 MOT 0 1
R8 MMF MAT 1
A1 MED RES MMF 0 windings
A2 MAT MOT iron_core
.ENDS Torodial_inductor
After adding the voltage source and the resistor in series with the inductor, the circuit still gives me the same error as before when used with the voltage source. With the current source it works as before with the same result, no errors.
Do you have any other insights as to why this might be occurring, or any alternative solutions?
I would love to, but the platform doesn’t allow new users to upload files, so I can’t upload it here. But I have created a wetransfer link, you can download the zip file with the project from there.
Either by platform usage or stray mod, you are now a basic user. You can edit the previous post with the file if you wish. Might be good for posterity as that link will probably disappear at some point.
does your transformer work in the latest kicad v8?
I get:
.model xm1:ferrocore core(h_array=[ 4.40000000000000036e+00 ] b_arr ...
Unknown model type core - ignored
Error on line 0 :
a.xm1.a1 net-_l1-pad3_ 0 xm1:ferrocore
MIF-ERROR - unable to find definition of model xm1:ferrocore
Warning: Model issue on line 0 :
.model xl1:coiloncore lcouple (num_turns 1.00000000000000000e+00 ) ...
Unknown model type lcouple - ignored
while running the same netlist from the command line works.
Found the issue, with upgrade to kicad8 the dependency of kicad v8 does not trigger the installation of the libngspice-kicad, in my case I had to install it manually and now it works:
$ sudo apt install libngspice-kicad
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libngspice0
The following NEW packages will be installed:
libngspice-kicad
@holger I would like to ask you if you can review ngspice merge request #15 now as kicad with ngspice is working better and better and so would really like kicad to replace the command line driven ngspice
Since the model provides smooth and monotonic function convergence is stable even in deep saturation, and time step can be bigger. I’ve added an example how to easily obtain ferromagnetic, or iron, …, material parameters: