There’s an FSOURCE (current-controlled current source) in the PSPICE library but not in the Simulation_Spice library.
The PSPICE library is more or less deprecated, and the symbols are kind of ugly, but it has some things that aren’t in the Simulation_Spice library. The Simulation_Spice library is newer and nicer, but missing some symbols, namely the dependent sources.
I think you might have to mess with the model parameters when you use a symbol from the pspice library. Namely you’ll have to set the spice_primitive to F and the spice_model to whatever gain you want, e.g. 1 for 1 A / A
Thanks @gkeeth, l think just rename the “current dependent of voltage” by F** will do…
I will have the current status of the complete KiCad Spice library. I am also having the issue with the capacitors and missing others spice primitives (Laplace, sum, and so on).
For the capacitor, you need to change the value from 1n1 to 1.1n. ngspice doesn’t understand RKM notation.
For the opamp, you need to provide a model for it, there is no built-in spice model. You can models for specific opamps from manufacturers. For playing around, I tend to use @ste’s handy universal opamp model from here: Universal Opamp SPICE Macromodels
Download that file and put it somewhere safe (I have a spice model library folder).
Go to U1 -> Properties -> SPICE Model… and go to the model tab
select the library you downloaded
In the model dropdown, you can choose between lvl1 and lvl2. Level 1 does not have power rails, it just has the two inputs and the outputs. Your symbol has power rails so I would choose lvl2, which models clipping to the rails.
Check alternate node sequence: the symbol has pins 1: noninverting input, 2: inverting input, 3: Vout, 4: VCC, 5: VEE. For the spice model, pins 1 and 2 are the same, but 3-5 do not match the symbol. So we use the alternate node sequence “1 2 4 5 3” to remap them.
ngspice doesn’t understand the gsource. The quick way to fix this is to change the value from GSOURCE to your desired transconductance gain, for example 1 to get 1A/V. If you do this, it will work because ngspice/kicad guesses that a symbol called G1 is a gsource and uses its value field as the spice parameter. Another way to fix this which is a little more explicit, would be to add 3 fields to the symbol: Spice_Primitive:G, Spice_Model:1, and Spice_Netlist_Enabled:Y. This does the same thing but kicad/ngspice doesn’t have to make any guesses.
ngspice doesn’t understand the vsource V1. same thing, either change the value from VSOURCE to your dc value, or add the explicit fields.
ngspice doesn’t know what a .trans simulation is. You probably meant to write .tran.
Ngspice thinks your test point TP1 is a transmission line and is upset it doesn’t have a model. You can fix this by deleting the test point (unlike some other software, you don’t use a testpoint to probe a symbol in kicad/ngspice, you can just plot the signal).
I manage to run voltage/current sources controlled by voltage but I am failing on the controlled by current ones. Is H* and F* sources not available on NGSpice v31?
Circuit: KiCad schematic
Error on line 9 :
h1 net-_h1-pad1_ 0 net-_f1-pad4_ net-_h1-pad4_ 1
unknown parameter (-_f1)
Error on line 10 :
f1 net-_f1-pad1_ 0 net-_e1-pad3_ net-_f1-pad4_ 1
unknown parameter (-_e1)
Background thread stopped with timeout = 0
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Fatal error: f1: unknown controlling source net
doAnalyses: no such parameter on this device
run simulation(s) aborted
I am attaching my proposed symbols (I planned to submit to the official library). Could someone have a look? test.kicad_sch (38.9 KB)
I am just using 31 because of native package on Ubuntu 20.04. Is there some PPA for most recent NGSpice? I want want to compile by my self or create libraries compatible with version that not expert users could install.
I don’t think that’s the right format for an FSOURCE. I’m looking at the ngspice manual here which indicates that you specify a gain and the name of the controlling voltage source, so you should add an external voltage source of 0 volts that acts as an ammeter. Like this, where V2 is the controlling voltage source:
However I get this error when I try it, so I must be doing something wrong. Perhaps @holger can help.
Circuit: KiCad schematic
Error on line 0 :
a$poly$h1 %vnam [ net-_h1-pad3_ ] %vd ( net-_h1-pad1_ 0 ) a$poly$h1
MIF-ERROR - model: a$poly$h1 - Bad real value
Background thread stopped with timeout = 0
Error: circuit not parsed.
Thanks, I understood: the symbol F*/H* will the measurement part to the controlled source. I just have to dig and understand a better way to put this on the KiCad fields formats (the two parameters needed).
Someone knows if is possible to fix SPICE text line model for a symbol. For example: H1 Net-Pin1 Net-Pin2 SOUCE GAIN but want want the SOURCE and GAIN be fields of my symbol instead of only Value.
The issue was that there was no current path through the H source, because ngspice has no way to know the ammeter pins are shorted, unless you write a subcircuit model like holger describes.
I don’t know much about spice in KiCad, but I would prefer smaller symbols, about the same height as a normal resistor in KiCad. Especially the rotated square looks extremely big compared with the rest of KiCads symbols.
The old and big symbols have to be maintained for the exising userbase even though they do not fit well in the current KLC
Work on libraries is also suspended for quite a long time already:
That way it’s set up as a G-source with a gain of 1, and the gain is easily editable.
You can get the Spice* fields added automatically by clicking Spice Model… and then setting it to a voltage source or really any other kind of source. Then you can just edit the values.
For the H- and F-sources which require you to pick a controlling voltage source… that’s harder. There is no default value that will definitely work. I would probably choose V1 as a good default, so the Spice_Model field would be V1 1.