Installing and using ngspice - an opensource simulator

I found the problem. The regular expressions weren't in Perl format. I seem to have succeeded in fixing them. It needs testing though, especially to make sure the units conversions work. New script attached.

I don't know if the expression for xin is correct. In the scripts it is

xin=xti-ne*xtb

Whereas in the VBIC PDF it is

xin=xti-xtb


On page 13 here, we see why we should use level=9 instead of level=4.

https://www.iee.et.tu-dresden.de/iee/eb/forsch/AK-Bipo/2005/AKB2005_Hammer_VBIC12_benchmarking.pdf


One last thing that might matter, in LTspice there is the option to use "3k3" syntax for 3.3k. The script might need to support this.
 

Attachments

  • sgp2vbic12-beta2.txt
    15.5 KB · Views: 53
Member
Joined 2011
Paid Member
I found the problem. The regular expressions weren't in Perl format. I seem to have succeeded in fixing them. It needs testing though, especially to make sure the units conversions work. New script attached.

I don't know if the expression for xin is correct. In the scripts it is

xin=xti-ne*xtb

Whereas in the VBIC PDF it is

xin=xti-xtb


On page 13 here, we see why we should use level=9 instead of level=4.

https://www.iee.et.tu-dresden.de/iee/eb/forsch/AK-Bipo/2005/AKB2005_Hammer_VBIC12_benchmarking.pdf


One last thing that might matter, in LTspice there is the option to use "3k3" syntax for 3.3k. The script might need to support this.


Dear keantoken,



In the code we have these 2 expressions:
Code:
        $r->{'xii'}     =       ($val->{'xti'} - $val->{'xtb'});
        $r->{'xin'}     =       ($val->{'xti'} - $val->{'ne'} * $val->{'xtb'});
xii is not xin. Which expression is wrong/ok?


To support "3k3" syntax needs some time. Maybe on weekend.
A few regex more ...
 
<snip>

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

Keantoken posted already about the relevance of the QS effect, to add further i think it is enlightning what the vbic web page stated as reasons to implement the VBIC model as an open source model implementation in comparison to the STGP:

Improved Early effect modeling
Quasi-saturation modeling
Parasitic substrate transistor modeling
Parasitic fixed (oxide) capacitance modeling
Includes an avalanche multiplication model
Improved temperature modeling
Base current is decoupled from collector current
Electrothermal modeling
Smooth, continuous model

While i agree that obviously two or three entries are mainly important for ICs, the others help to get better results for audio circuit simulations.
 
Member
Joined 2011
Paid Member
This is a good regular expressions test site. I used PCRE, which I think mean Perl.

Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript

Look at the conversion for xii here:

http://www.designers-guide.org/VBIC/documents/VbicText.pdf

I noticed the difference when I discovered xii was a negative value when I converted my KSC1845 model.


Code:
#------------------------------------------------------------------------------
sub normalize_units
#------------------------------------------------------------------------------
{
        my $val=shift;
        if ($debug) {
                print STDERR "normalize units:\t$val\t=>\t";
        }
        if    ($val=~/([\+\-\.0-9]+)f$/i)        {      $val=$1 * 1e-15;        }
        elsif ($val=~/([\+\-\.0-9]+)p$/i)        {      $val=$1 * 1e-12;        }
        elsif ($val=~/([\+\-\.0-9]+)n$/i)        {      $val=$1 * 1e-9;         }
        elsif ($val=~/([\+\-\.0-9]+)u$/i)        {      $val=$1 * 1e-6;         }
        elsif ($val=~/([\+\-\.0-9]+)m$/i)        {      $val=$1 * 1e-3;         }
        elsif ($val=~/([\+\-\.0-9]+)k$/i)        {      $val=$1 * 1e+3;         }
        elsif ($val=~/([\+\-\.0-9]+)meg$/i)      {      $val=$1 * 1e+6;         }
        elsif ($val=~/([\+\-\.0-9]+)g$/i)        {      $val=$1 * 1e+9;         }
        elsif ($val=~/([\+\-\.0-9]+)t$/i)        {      $val=$1 * 1e+12;        }

        if ($debug) {
                print STDERR "$val\n";
        }
        return $val;
}
Above regex should be ok. Here the "3k3" variant could be inserted too (next release).
Code:
        0.76f   =>      7.6e-16
        0.8569n =>      8.569e-10
        100f    =>      1e-13
        100m    =>      0.1
        101.1p  =>      1.011e-10
        105m    =>      0.105
        1.073u  =>      1.073e-06
        10n     =>      1e-08
        10p     =>      1e-11
        113.1p  =>      1.131e-10
        115p    =>      1.15e-10
        118.5p  =>      1.185e-10
        1.2f    =>      1.2e-15
        1.2n    =>      1.2e-09
        1.345p  =>      1.345e-12
        13.6p   =>      1.36e-11
        13p     =>      1.3e-11
        141.1p  =>      1.411e-10
        14.65n  =>      1.465e-08
        1.4f    =>      1.4e-15
        150f    =>      1.5e-13
        150m    =>      0.15
        1.588n  =>      1.588e-09
        15f     =>      1.5e-14
        1.5n    =>      1.5e-09
        166.7f  =>      1.667e-13
        188.8n  =>      1.888e-07
        18p     =>      1.8e-11
        1.9n    =>      1.9e-09
        1k      =>      1000
        1n      =>      1e-09
        200m    =>      0.2
        200n    =>      2e-07
        200p    =>      2e-10
        20m     =>      0.02
        22.03m  =>      0.02203
        227.6p  =>      2.276e-10
        22n     =>      2.2e-08
        230f    =>      2.3e-13
        250n    =>      2.5e-07
        255p    =>      2.55e-10
        2.65p   =>      2.65e-12
        2.77p   =>      2.77e-12
        2.83p   =>      2.83e-12
        28p     =>      2.8e-11
        293.5f  =>      2.935e-13
        295.4p  =>      2.954e-10
        2u      =>      2e-06
        300f    =>      3e-13
        300p    =>      3e-10
        30f     =>      3e-14
        31p     =>      3.1e-11
        330n    =>      3.3e-07
        33f     =>      3.3e-14
        3.5p    =>      3.5e-12
        380p    =>      3.8e-10
        4.033n  =>      4.033e-09
        420p    =>      4.2e-10
        4.2p    =>      4.2e-12
        4.5p    =>      4.5e-12
        4.948p  =>      4.948e-12
        4n      =>      4e-09
        500f    =>      5e-13
        500m    =>      0.5
        500p    =>      5e-10
        50m     =>      0.05
        5.26n   =>      5.26e-09
        550p    =>      5.5e-10
        55m     =>      0.055
        5n      =>      5e-09
        600f    =>      6e-13
        600m    =>      0.6
        6.1n    =>      6.1e-09
        620p    =>      6.2e-10
        62f     =>      6.2e-14
        6.2p    =>      6.2e-12
        6.3p    =>      6.3e-12
        6.4u    =>      6.4e-06
        650f    =>      6.5e-13
        72p     =>      7.2e-11
        750p    =>      7.5e-10
        800.3p  =>      8.003e-10
        800m    =>      0.8
        80p     =>      8e-11
        830p    =>      8.3e-10
        85n     =>      8.5e-08
        86.19m  =>      0.08619
        875p    =>      8.75e-10
        893.1f  =>      8.931e-13
        8n      =>      8e-09
        8p      =>      8e-12
        90m     =>      0.09
        939.8f  =>      9.398e-13
         970p    =>      9.7e-10
Above some conversions - hopefully ok.
Attached the mapping table you hopefully mean. I have inserted the corrected calculation in the script - see this changes here:


Code:
-               $val->{$key}=$value;
-               if ($key eq 'rbm') {$done->{'rbm'}='yes';}
                if (defined $keep->{$key}) {
-                       $r->{$key}=$value;
+                       # will become a comment only!
+                       $info->{$key}=$value;
+               } else {
+                       $val->{$key}=$value;
                }
+               if ($key eq 'rbm') {$done->{'rbm'}='yes';}
+               if ($key eq 'ibe') {$done->{'ibe'}='yes';}
+               if ($key eq 'ibc') {$done->{'ibc'}='yes';}
        }
        if (!defined($done->{'rbm'})) {
                $val->{'rbm'}=$val->{'rb'};
        }
-       if (!defined($val->{'ibe'})) {          # Prefer ibe to is, if it is available
+       if (!defined($done->{'ibe'})) {         # Prefer ibe to is, if it is available
                $val->{'ibe'}=$val->{'is'};
        }
-       if (!defined($val->{'ibc'})) {          # Prefer ibc to is, if it is available
+       if (!defined($done->{'ibc'})) {         # Prefer ibc to is, if it is available
                $val->{'ibc'}=$val->{'is'};
        }
        if ($val->{'ise'} > 1.0) {
@@ -517,13 +558,15 @@
        $r->{'eane'}    =       $val->{'eg'};
        $r->{'eanc'}    =       $val->{'eg'};
        $r->{'xis'}     =       $val->{'xti'};
+
        $r->{'xii'}     =       ($val->{'xti'} - $val->{'xtb'});
-       $r->{'xin'}     =       ($val->{'xti'} - $val->{'ne'} * $val->{'xtb'});
+       # $r->{'xin'}   =       ($val->{'xti'} - $val->{'ne'} * $val->{'xtb'});
+       $r->{'xin'}     =       ($val->{'xti'} - $val->{'xtb'});        # corrected according to the url: [URL]http://www.designers-guide.org/VBIC/documents/VbicText.pdf[/URL]
See revision ID: $Id: convert_sgp_modelfile_to_vbic.pl 1601 2019-02-22 17:38:47Z sta $

Now option '-o outfile' allows to output the results directly into file, not only on stdout. With option '-d' you get many debug lines to check.

BR, Toni
 

Attachments

  • sgp_vbic_mapping.png
    sgp_vbic_mapping.png
    55 KB · Views: 228
  • convert_sgp_modelfile_to_vbic.zip
    5.1 KB · Views: 55
Last edited:
There are two slashes in front:
#!//usr/bin/perl

and has not worked.

[CODE
Now option '-o outfile' allows to output the results directly into file, not only on stdout. With option '-d' you get many debug lines to check.

BR, Toni


Tried under msys:

$ ./convert_sgp_modelfile_to_vbic.pl bfs17.mod -o bfs17_vbic.mod
=== WARNING - device BFS17 NPN: IRB parameter is not supported in vbic
=== WARNING - device BFS17 NPN: parameter irb is not supported in vbic
* ------------------------------------------------------------------------------
* BFS17:
* ------------------------------------------------------------------------------
.model BFS17 NPN ( 1
+ rcx=2.68 rci=0 gamm=1.0e-11 vo=0 qco=0 rbx=1.2
+ rbi=3.0e-01 re=5.0e-01 is=4.8e-16 nf=1.008 nr=1.01 fc=8.9e-01
+ cje=1.325e-12 pe=7.0e-01 me=2.2e-01 cjc=4.2e-13 cjep=6.3e-13 pc=6.1e-01
+ mc=2.4e-01 cjcp=0 ps=7.5e-01 ms=0 ibei=4.816617e-18 nei=1.008
+ iben=7.49e-15 nen=1.762 ibci=1.25e-17 nci=1.01 ibcn=2.0e-16 ncn=1.042
+ vef=5.668458e+01 ver=8.2482664 ikf=1.9e-01 nkf=5.0e-01 ikr=9.32e-02 tf=5.694e-11
+ xtf=6.8398e+01 vtf=6.0e-01 itf=7.0e-01 tr=1.0e-09 td=2.08696e-11 ea=1.11
+ eaie=1.11 eaic=1.11 eane=1.11 eanc=1.11 xis=3 xii=1.4
+ xin=1.4 kfn=1.0e-15 afn=1
+ )
* ------------------------------------------------------------------------------
But the -o option has no file generated.


Same with
$ perl convert_sgp_modelfile_to_vbic.pl bfs17.mod -o bfs17_vbic.mod


Kind Regards,
Dietmar
 
I don't think we can decide which xin expression is correct without consulting an expert. Colin McAndrews wrote both the original script AND that PDF you used to correct the original script. Perhaps Colin knows which one is correct? That said, the default value is 3, so the PDF expression gives a closer value to the default.
 
Member
Joined 2011
Paid Member
Bugfixes!
Revision now:$Id: convert_sgp_modelfile_to_vbic.pl 1603 2019-02-23 11:07:48Z sta $


  • fix shebang
  • fix missing level parameter
BR, Toni

P.S.: example output:
Code:
* ------------------------------------------------------------------------------
* KSC1845E_kq: icrating=0.05 mfg=Fairchild vceo=120
* ------------------------------------------------------------------------------
.model KSC1845E_kq npn ( level=9
+ rcx=1 rci=250 gamm=2.0e-06 vo=500 qco=0 rbx=1.2092e+01
+ rbi=1.44908e+02 re=1.5 is=1.075431e-13 nf=1 nr=1 fc=5.0e-01
+ cje=1.8e-11 pe=7.300286e-01 me=3.619943e-01 cjc=4.525739e-12 cjep=0 pc=5.0e-01
+ mc=3.659045e-01 cjcp=0 ps=7.5e-01 ms=0 ibei=1.790296e-16 nei=1
+ iben=1.98107e-13 nen=2 ibci=7.927984e-15 nci=1 ibcn=1.8378e-11 ncn=1.5
+ vef=4.547994e+01 ver=1.527354e+01 ikf=5.5e-02 nkf=6.6e-01 ikr=1.90546e-02 tf=4.2e-10
+ xtf=1 vtf=0 itf=2.0e-02 tr=0 td=0 ea=1.1809
+ eaie=1.1809 eaic=1.1809 eane=1.1809 eanc=1.1809 xis=3 xii=1.2719
+ xin=1.2719 kfn=0 afn=1
+ )
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* KSA992F_kq: icrating=0.05 mfg=Fairchild vceo=120
* ------------------------------------------------------------------------------
.model KSA992F_kq pnp ( level=9
+ rcx=1.0e-01 rci=100 gamm=2.0e-07 vo=500 qco=0 rbx=1.6084e+01
+ rbi=1.23916e+02 re=3.0e-01 is=5.7544e-14 nf=1 nr=9.5e-01 fc=5.0e-01
+ cje=1.3e-11 pe=8.55e-01 me=4.104e-01 cjc=2.732866e-12 cjep=6.192234e-12 pc=5.0e-01
+ mc=3.497e-01 cjcp=0 ps=8.0e-01 ms=3.3e-01 ibei=1.653088e-16 nei=1
+ iben=5.7544e-15 nen=1.5 ibci=1.589613e-14 nci=9.5e-01 ibcn=1.8378e-14 ncn=1
+ vef=2.862935e+01 ver=1.250379e+01 ikf=2.98e-01 nkf=5.0e-01 ikr=5.25e-02 tf=4.2e-10
+ xtf=5.0e-01 vtf=0 itf=5 tr=0 td=0 ea=1.1603
+ eaie=1.1603 eaic=1.1603 eane=1.1603 eanc=1.1603 xis=3 xii=1.7151
+ xin=1.7151 kfn=0 afn=1
+ )
* ------------------------------------------------------------------------------
 

Attachments

  • convert_sgp_modelfile_to_vbic.zip
    5.1 KB · Views: 45
Member
Joined 2011
Paid Member
Dear keantoken,

have converted your kean9.lib.txt to VBIC models and tried to run a curve trace using all your npn/pnp devices included.
Attached the script to generate the files and results. To automatically generate the png files you need the ngspice gnuplot patch some posts before.

If you edit the resulting e.g. tmp_curve_trace.BC550C_C.inc file
Code:
*
.control
* --------- BJT specific values -------
        * ngspice-30 BUG: need a non numeric character and not +/- in front of the bjt name, otherwise the bjt name will be converted to a number
        set mybjt="_BC550C_C"
        set ibase1=( 2u 4u 6u 8u 10u 12u 14u 16u )
        set sweep1end=5
        set ibase2=( 0.2u 0.4u 0.6u 0.8u 1u 1.2u 1.4u 1.6u )
        set sweep2end=100
* --------- BJT specific values -------
.endc

Q1 net1 net2 0 0 BC550C_C
Vce net1 0 DC=0 AC=0
I1 0 net2 1u
.end
and define the steps and limits which corresponds to the datasheet, you can generate a plot which can be easily compared to the datasheet.

E.g. run the resulting inc file on console:
Code:
ngspice -i tmp_curve_trace.BC550C_C.inc curve_tracer.ngspice
BR, Toni
 

Attachments

  • step_vbic_models_results3.zip
    385 KB · Views: 52
  • step_vbic_models_results2.zip
    567.3 KB · Views: 58
  • step_vbic_models_results1.zip
    865.7 KB · Views: 48
  • step_vbic_models.zip
    77.5 KB · Views: 65
  • curve_ksc1845e_kq_trace2.png
    curve_ksc1845e_kq_trace2.png
    8.9 KB · Views: 224
  • curve_ksc1845e_kq_trace1.png
    curve_ksc1845e_kq_trace1.png
    7.7 KB · Views: 216
So now all those models are sitting there dead until someone can go through them. And we hope that person knows what they are doing. And without data, we don't even know if the converted models are better!

Think about it. The only metric we have for how good the converted models are is how well they fit the original SGP models. Which means that without basically reworking the models entirely with strong data, the conversion can only make them worse.
 
Member
Joined 2011
Paid Member
Don't understand your :eek:
Think the perl script will help you providing you a basic vbic conversion with the most parameters usable. And why not converting all models in one run?There are many versions of model library files out there using the same filename with different values, because no one uses the potential of a version control system on e.g. github. (Maybe due to the problems presenting a modified version using the original from big enterprise...)
So the example of the vbic conversion is only one more version of a file which may be incomplete/unusable or whatever.

Obviously you haven't seen the potential of ngspice + scripting + some tooling to help

  • checking and comparing SGP, VBIC ...
  • align the output exactly to datasheet values to easier see a difference.
It would be nice if you could add some testing circuits to get datasheet like plots of hFe vs frequency ...

BR, Toni
 
Member
Joined 2011
Paid Member
Dear Holger,


using the mass tools I found during sgp test run, that ltspice sgp models which have the model parameters

gamma, ibc,nk,qco,rco,vo
can not be used for ngspice.
Is there an update for the ngspice sgp model planned? Or is this simply ltspice specific?


BR, Toni
 
I think it is a waste of time to convert the models which we don't have Ic/Vce information for. I would only end up reworking them later when data became available. I will only bother converting the models that have good datasheets or curve tracer data.

Yes - this is what I meant before. The transformed model will not have more informations as the original sgp model.

The way can only be to identify (with the knowledge of this forum) the devices showing the effects which are covered by vbic like quasi-saturation, unsufficient accuracy in go or avalanching. Then using your script to generate a starting vbic model and manual fit the responsible parameters for this effect.

E.g. the attached heavy metal guy (and partly his pnp counterpart) show clear quasi-saturation. I am sure that is possible to tweak RCI, GAMM, VO, HRCF to get a more or less accurate mapping of this effect. Not to forget that some other parameter have to modified too.

BR
Dietmar
 

Attachments

  • MJL21194_output.gif
    MJL21194_output.gif
    15.6 KB · Views: 194
HRCF has no effect on my simulations. Qco also has no effect depending on what kind of analysis and the phase of the moon. It also complains that Qbm is not a parameter even though it is in the help file. I think these are bugs in the LTspice implementation. Do you have any suggestions?