Installing and using ngspice - an opensource simulator

Member
Joined 2011
Paid Member
You don't need forth as I understand the perl script. The equations to calculate the missing parameters are already in native perl.


The only problem is the ".model" parser which isn't very sophisticated.

I would normalize a .model line into key/value pairs or similar. Needs some development/testing time.


Will have a look where I can find some spare time to convert e.g. your bjt model file...



BR, Toni
 
In case it helps any, here are some regular expressions you can use in a spreadsheet search/replace tool to convert the prefix multipliers to IEEE:

\b(([:digit:].*)?[:digit:])f\b -> $1e-15
\b(([:digit:].*)?[:digit:])p\b -> $1e-12
\b(([:digit:].*)?[:digit:])n\b -> $1e-9
\b(([:digit:].*)?[:digit:])u\b -> $1e-6
\b(([:digit:].*)?[:digit:])m\b -> $1e-3
\b(([:digit:].*)?[:digit:])k\b -> $1e+3
\b(([:digit:].*)?[:digit:])g\b -> $1e+9

Hmm, looks like I omitted meg for some reason.
 
Toni, and other ngspice experts as well,

I did follow this thread up to one month but got heavy in the head of all the scripting related posts... but as I am trying to slowly move over from Windows to Linux and also trying to learn to use KiCad I thought ngspice would be great to learn too, so my short question is, do one really have to engage so much with the scripting to get any spicing done or am I ok using the GUI only or will it limitate considerably from using all the capabilities ngspice can offer?

Regards Michael
 
Member
Joined 2011
Paid Member
... so my short question is, do one really have to engage so much with the scripting to get any spicing done or am I ok using the GUI only or will it limitate considerably from using all the capabilities ngspice can offer?
...
Dear Michael,


of course you can use ngspice as it is integrated in KiCAD. Just wanted to show the power of scripting ngspice.
With scripting you can do all simulations in one task like distortion analyse, tian plots for stability analysis, psrr...
You could even do a "brute force" stepping to get the best parameters for e.g. TMC compensation, current limiter ...


BR, Toni
 
Some help for starting with ngspice in KiCad: KiCad Eeschema as GUI for ngspice, tutorial for setting up the simulation (I have done this under Windows, but should be similar with Linux)

The KiCad/ngspice manual is here: Eeschema | KiCad Docs

Some demos are coming with KiCad in folder share/kicad/demos/simulation. You may just start them and tinker around with the circuits.

And have a look at the discussion threads in Simulation (Ngspice) - KiCad.info Forums

Questions for ngspice (not KiCad) may be answered quickly here: ngspice / Discussion / Forums

And last but not least, the ngspice manual: Download ngspice from SourceForge.net
 
Last edited:
Next issue then is the model parameter extraction.

The most recent MEXTRAM (505) model has about 120 parameters. Same with VBIC. You will need a lot of measurements, and probably a parameter extraction software. I fear that data sheets are not that helpful anymore.

VBIC is implemented in ngspice, so one has to look for adequate model parameters.

Today I searched something about phase comparators in one of Ulrich Rohde's books and stumbled over abt. half a page on MEXTRAM. He stated that one of the advantages of the Most Exquisite TRAnsistor Model is that it has only 5 internal nodes while other competing models need 7, and that it internally contains 3 transistors, so parameter extraction would be a lot of fun. (his wording)

If there is interest, I can scan/photo the two quarter pages.

Oh, it is good for intermodulation, but small signal only. So it won't work for things like "power added efficiency", as he noted.

Methinks , that is for microwaves and people who can afford ADS, not for the audio community.

cheers,
Gerhard

ps. 5 vs. 7 nodes can make a huge runtime difference when the simulator starts inverting matrices. When the circuit is already large, the effort to solve that explodes with size.
 
Last edited:
of course you can use ngspice as it is integrated in KiCAD. Just wanted to show the power of scripting ngspice.
With scripting you can do all simulations in one task like distortion analyse, tian plots for stability analysis, psrr...
You could even do a "brute force" stepping to get the best parameters for e.g. TMC compensation, current limiter ...

Thanks Toni for clearing up the picture, should reduce me from getting entangled.
 
For reference, if I upgrade all my models to VBIC it would be very helpful to have any of the following data:

RF emitter impedance measurements as the datasheet Ft graphs aren't enough to model HF behavior. MUST include the manufacturer of the transistor otherwise it's useless.
High-voltage Ic vs Vce data to model voltage gain behavior as per Samuel Groner's PDF.
Base step response in quasi-saturation for tuning the Qco parameter.

These are most of the major frontiers left for BJT models for audio use.
 
Member
Joined 2011
Paid Member
Dear keantoken,

attached a perl script which allows you to convert your big kean9 model txt file to vbic. The input file can contain one or more npn/pnp sgp model files which will be converted to vbic.

The sgp2vbic script is incorporated into this script - see text in source code.

Completely untested. Let me know, if you like/dislike the results.

BR, Toni

P.S.: an example result:

Code:
.model D45H11_D PNP ( level=4
+ rcx=0 rci=0 rbx=2.5 rbi=0 re=0 is=6.246e-13
+ nf=9.6736e-01 nr=1 fc=5.0e-01 cje=1.65e-09 pe=3.50637e-01 me=3.21191e-01
+ cjc=3.7189e-10 cjep=0 pc=6.393911e-01 mc=3.952624e-01 cjcp=0 ps=7.5e-01
+ ms=0 ibei=4.559124e-15 nei=9.6736e-01 iben=3.06e-09 nen=2.7 ibci=1.5615e-13
+ nci=1 ibcn=0 ncn=2 vef=7.047879e+01 ver=9.66244312 ikf=1.15e+01
+ ikr=1.05 tf=1.62e-09 xtf=800 vtf=40 itf=200 tr=0
+ td=0 ea=1.11 eaie=1.11 eaic=1.11 eane=1.11 eanc=1.11
+ xis=3 xii=3 xin=3 kfn=0 afn=1 icrating=8
+ mfg=ON vceo=80
+ )
 

Attachments

  • convert_sgp_modelfile_to_vbic.zip
    4.4 KB · Views: 82
Last edited:
Some words to the usage of the modified perl script are appreciated.
This comes to stdout if call the script with a sgp model file.
Code:
$ perl convert_sgp_modelfile_to_vbic.pl bfs17.mod
        device BFS17 NPN: af=1.000
        device BFS17 NPN: bf=99.655
        device BFS17 NPN: br=38.400
        device BFS17 NPN: cjc=1.050p
        device BFS17 NPN: cje=1.325p
        device BFS17 NPN: eg=1.110
        device BFS17 NPN: fc=0.890
        device BFS17 NPN: ikf=0.190
        device BFS17 NPN: ikr=93.200m
        device BFS17 NPN: irb=0.100m
=== WARNING - device BFS17 NPN: IRB parameter is not supported in vbic
=== WARNING - device BFS17 NPN: parameter irb is not supported in vbic
        device BFS17 NPN: is=0.4f
        device BFS17 NPN: isc=0.200f
        device BFS17 NPN: ise=7.490f
        device BFS17 NPN: itf=0.700
        device BFS17 NPN: kf=1.000f
        device BFS17 NPN: level=1
        device BFS17 NPN: mjc=0.240
        device BFS17 NPN: mje=0.220
        device BFS17 NPN: nc=1.042
        device BFS17 NPN: ne=1.762
        device BFS17 NPN: nf=1.008
        device BFS17 NPN: nr=1.010
        device BFS17 NPN: ptf=21.000
        device BFS17 NPN: rb=1.500
        device BFS17 NPN: rbm=1.200
        device BFS17 NPN: rc=2.680
        device BFS17 NPN: re=0.500
        device BFS17 NPN: tf=56.940p
        device BFS17 NPN: tr=1.000N
        device BFS17 NPN: vaf=90.000
        device BFS17 NPN: var=7.000
        device BFS17 NPN: vjc=0.610
        device BFS17 NPN: vje=0.700
        device BFS17 NPN: vtf=0.600
        device BFS17 NPN: xcjc=0.400
        device BFS17 NPN: xtb=1.600
        device BFS17 NPN: xtf=68.398
        device BFS17 NPN: xti=3.000
QCDEPL:         0.6, 0.700, 0.220, 0.890
QCDEPL:         -1.9, 0.610, 0.240, 0.890
QCDEPL:         -2, 0.700, 0.220, 0.890
QCDEPL:         0.5, 0.610, 0.240, 0.890
.model BFS17 NPN ( level=4
+ rcx=2.68 rci=0 rbx=1.2 rbi=3.0e-01 re=5.0e-01 is=4.0e-01
+ nf=1.008 nr=1.01 fc=8.9e-01 cje=1.325 pe=7.0e-01 me=2.2e-01
+ cjc=4.2e-01 cjep=6.3e-01 pc=6.1e-01 mc=2.4e-01 cjcp=0 ps=7.5e-01
+ ms=0 ibei=4.013848e-03 nei=1.008 iben=2.996 nen=1.762 ibci=1.041667e-02
+ nci=1.01 ibcn=2.0e-01 ncn=1.042 vef=5.668458e+01 ver=8.2482664 ikf=1.9e-01
+ ikr=9.32e+01 tf=5.694e+01 xtf=6.8398e+01 vtf=6.0e-01 itf=7.0e-01 tr=1.000N
+ td=2.08696e+01 ea=1.11 eaie=1.11 eaic=1.11 eane=1.11 eanc=1.11
+ xis=3 xii=1.4 xin=1.808e-01 kfn=1.000f afn=1
+ )

It seems correct but there is no file written. I must grep it from stdout.

BTW - I aggree with Holger: VBIC is more important for integrated circuit design with the high impact of substrate and is supported meanwhile by Foundries like x-fab and tsmc.

The onlyest exception is the Kull extension for Quasi-Saturation which is implemented in VBIC.
But the Question is, which devices in diy practice suffer from this missed feature in SGP. I think not the hundreds of small signal devices. Can somebody provide examples for power bjt's with QS effect.

Kind Regards,
Dietmar
 
Thanks ASTX! I will take a look. If you don't already know, you should be aware that there is no direct conversion for Vaf in VBIC. So all the models converted this way need to have Vef manually fitted and so are unfinished. Your DCA curve tracer results are sufficient for this though. The final steps are much easier with DCA curves.

I think I will change the parameter output order so that you can see the important parameters first in the LTspice model selector. Is it possible to leave Ibei and Ibci as expressions in the model:

Ibei=100f/350

Because 350 would be Beta in the SGP model and without this there is no way to tell Hfe from the model line.


BTW - I aggree with Holger: VBIC is more important for integrated circuit design with the high impact of substrate and is supported meanwhile by Foundries like x-fab and tsmc.

The onlyest exception is the Kull extension for Quasi-Saturation which is implemented in VBIC.
But the Question is, which devices in diy practice suffer from this missed feature in SGP. I think not the hundreds of small signal devices. Can somebody provide examples for power bjt's with QS effect.

Kind Regards,
Dietmar


Every power BJT used in power amplifiers suffers from quasi-saturation near clipping, and this can be a stumbling block if it makes a LDO regulator or class G amp unworkable.

When high voltage transistors are used in a current mirror quasi-saturation can cause increased distortion. It's true that some modern 2SC/2SA type transistors have been re-masked to reduce quasi-saturation. But even a small amount of quasi-saturation can reduce current mirror performance depending on the VAS used.

I don't think there is any BJT that has no quasi-saturation. You can use a BJT in a region below the currents where it becomes significant. However what you find is that if you choose transistors this way you end up with slower transistors with lower Hfe or higher Vaf that are not necessarily optimal for your application.

The LTspice VBIC model uses the same quasi-saturation model as the modified SGP model. What is different in VBIC is that Early effect is no longer modeled as a straight line, which Samuel Groner has shown is of crucial importance to the linearity of common-emitter BJTs.

Are you by any chance related to the Dietmar who was responsible for the inclusion of VBIC in LTspice?
 
I can see some problems. IRB is mentioned twice as not being compatible, which could be a symptom of code problems.

I think Ibc/Ibe might be convertable to VBIC, IIRC they are just a different solution for the already existing parameters. But I don't know where the reference is.

Gamma, Rco and Vo are indeed supported in the LTspice level=4/9 VBIC v1.2. I am making some changes to the script to see if I can update it without breaking it.

Code:
$ perl convert_sgp_modelfile_to_vbic.pl -v 1.txt
	device KSC1845F_kq npn: bf=355
	device KSC1845F_kq npn: br=13.565
	device KSC1845F_kq npn: cjc=4.525739E-12
	device KSC1845F_kq npn: cje=18p
	device KSC1845F_kq npn: eg=1.1809
	device KSC1845F_kq npn: fc=0.5
	device KSC1845F_kq npn: gamma=10u
=== WARNING - device KSC1845F_kq npn: parameter gamma is not supported in vbic
	device KSC1845F_kq npn: ibc=600f
=== WARNING - device KSC1845F_kq npn: parameter ibc is not supported in vbic
	device KSC1845F_kq npn: icrating=50m
=== WARNING - device KSC1845F_kq npn: parameter icrating is not supported in vbic
	device KSC1845F_kq npn: ikf=300m
	device KSC1845F_kq npn: ikr=0.0190546
	device KSC1845F_kq npn: irb=1.258925E-6
=== WARNING - device KSC1845F_kq npn: IRB parameter is not supported in vbic
=== WARNING - device KSC1845F_kq npn: parameter irb is not supported in vbic
	device KSC1845F_kq npn: is=1.075431E-13
	device KSC1845F_kq npn: isc=22f
	device KSC1845F_kq npn: ise=1000f
	device KSC1845F_kq npn: itf=20m
	device KSC1845F_kq npn: mfg=Fairchild
=== WARNING - device KSC1845F_kq npn: parameter mfg is not supported in vbic
	device KSC1845F_kq npn: mjc=0.3659045
	device KSC1845F_kq npn: mje=0.3619943
	device KSC1845F_kq npn: nc=1.5
	device KSC1845F_kq npn: ne=2
	device KSC1845F_kq npn: nf=1
	device KSC1845F_kq npn: nk=0.66
=== WARNING - device KSC1845F_kq npn: parameter nk is not supported in vbic
	device KSC1845F_kq npn: nr=1
	device KSC1845F_kq npn: rb=157
	device KSC1845F_kq npn: rbm=12.092
	device KSC1845F_kq npn: rc=1
	device KSC1845F_kq npn: rco=150
=== WARNING - device KSC1845F_kq npn: parameter rco is not supported in vbic
	device KSC1845F_kq npn: re=1.5
	device KSC1845F_kq npn: tf=420p
	device KSC1845F_kq npn: vaf=400
	device KSC1845F_kq npn: var=20.6691
	device KSC1845F_kq npn: vceo=120
=== WARNING - device KSC1845F_kq npn: parameter vceo is not supported in vbic
	device KSC1845F_kq npn: vjc=0.5
	device KSC1845F_kq npn: vje=0.7300286
	device KSC1845F_kq npn: vo=9
=== WARNING - device KSC1845F_kq npn: parameter vo is not supported in vbic
	device KSC1845F_kq npn: xtb=1.7281
	device KSC1845F_kq npn: xtf=1
	device KSC1845F_kq npn: xti=3[/quote]
 
Maybe Dave Zan won't be required here.

When Ibe and Ibc aren't specified, Ibe=Ibc=Is. When one or both Ibe or Ibc are specified, they are used separately for the emitter and collector currents, and if one is missing Is is used for that one. If both are specified, then Is is ignored.

So in models with Ibc or Ibe specified,

Ibei=Ibe/Bf OR Is/Bf
Ibci=Ibc/Br OR Is/Br


Also, If I understand correctly the LTspice VBIC implementation has the parameter switch Qbm which reverts to the SGP formulation which uses Irb. So the conversion script should keep Irb and default to Qbm=1. I will experiment to make sure if this is the case.
 
The LTspice VBIC model uses the same quasi-saturation model as the modified SGP model. What is different in VBIC is that Early effect is no longer modeled as a straight line, which Samuel Groner has shown is of crucial importance to the linearity of common-emitter BJTs.

Are you by any chance related to the Dietmar who was responsible for the inclusion of VBIC in LTspice?
I read the Groner paper and agree. But I am missing quantitative statements about the non-linearities in output characteristic and their contribution to the considered amplifier distortion.

Yes, I am the implementer (not the author) of the vbic in ngspice which was resumed by Mike afterwards. So I can only speak to the ngspice implementation because code is open source.

BTW: We just revise the vdmos model in ngspice including mobility reduction, subthreshold range and self heating effect. The git development branch is vdmos-thermal with simple dcdc converter, wingspread and audio amplifier examples. Any hint is appreciated.

Regards,
Dietmar
 
Looks excellent, thanks.
Looks like you don't need any help!

Best wishes
David

I would appreciate it if you check it for correctness if you can.

It works like this:

Ibei=Ibe/Bf OR Is/Bf
Ibci=Ibc/Br OR Is/Br
Is = Ibe OR Is

The OR expressions are second preference. If both Ibc and Ibe are defined, Is is ignored just like the SGP model. This gets me a good conversion for my KSC1845F model which uses Ibc.


But, now I'm stalled because this exposed a bug in the prefix multiplier code which also affects Rb.


BUG:

Rbm is handled differently from the other parameters, which means it's unit conversion fails. So if I use 1k for Rb, Rbm in the output model will just be 1. The same occurs to Ibe and Ibc for some reason, before they are divided by Bf and Br.

The workaround is to use IEEE format to specify Ibe, Ibc and Rb in the input model. I think I am out of my depth as to fixing this in the code however.


Also, VBIC in LTspice doesn't support icrating, Vceo or mfg, so I would prefer those are placed after a semicolon in the output model.

Attached is the code. Lines 409-416 bypass the unit conversion causing the bug.
 

Attachments

  • sgp2vbic12-beta.txt
    15.5 KB · Views: 83
Last edited: