Installing and using ngspice - an opensource simulator

Actually what you want is the imaginary part of the collector impedance:

Xc=im(Vbc/Ic)

The previous one is residual memory from my abortive attempts at .meas statements...

Note that imaginary includes inductance as well as delay, so the junction Tf and Td or P parameters could perhaps be turned off just for capacitance measurement if that ends up being a problem.
 
Member
Joined 2011
Paid Member
I use this formula to calculate the capacitive reactance:

Xc = 1 / 2*PI*f*C

Using rms values from current and voltage measurements I calculate the capacitance using above formula. Is that wrong? Forgive me my rudimentary math knowledge...
The intention is to check the real life measurement setup to be correct.
BTW: I have ordered a professional LCR meter which can measure capacitance with as low as 10mv test signal.
 
Last edited:
Member
Joined 2011
Paid Member
ngspice control code:
Code:
                * measure capacitance using rms current and rms voltage at capacitor by frequency
                * R=U/I
                * get voltage between B and C junction and remove DC
                let dcoffset=@v2[dc]
                let vi1=abs(dcoffset-v(jb,jc))
                let ii1=abs(@r1[i])
                meas tran vi2 rms vi1
                meas tran ii2 rms ii1
                let ri1=vi2/ii2
                * add current flow to our measurement data
                let {$c}.ytab2[idx]=ii2

                * calculate capacitance using rms current and voltages at given frequency
                let cbccap1=1/(2*pi*$freq*ri1)
                print cbccap1
                echo "feed array element # $&idx for ytab1: $&cbccap1"
                let {$c}.ytab1[idx]=cbccap1
BR, Toni
 
Member
Joined 2011
Paid Member
Using my smart tweezer to measure Cbc capacitance I have used this schematic. Verified with simulation of the above circuit.

The results at -9V vBC (via a 100k resistor) for

  • 2SC6145AY: 325pF
  • 2SA2223AY: 540pF
The predicted/simulated value is about 306p from simulation for the 2SC6145. IMHO a very good match with real life measurement!
My smart-tweezer ST5 uses a 10k frequency and 0.25Vrms test signal



BR, Toni
 

Attachments

  • sgp_vbic_cbc_measurements_using_dmm.png
    sgp_vbic_cbc_measurements_using_dmm.png
    156.5 KB · Views: 138
Last edited:
Found this thread, reading with interest. What about tubes?

To my understanding two things are needed:

- the schematic editor must provede appropriate symbols to create a valid netlist
- the spice itself needs to be able to import models (ltspice or maybe pscice)

and cice to have: the schatic editor is able to import .asc files from ltspice

(is there any text of the kind of "ngspice + Xcircuit/gschem/Kicad for dummies" where dummie means semi experienced ltspice users like me)
 
Member
Joined 2011
Paid Member
Dear Bea,


about tubes: should work with ngspice. Maybe you post an ".asc" file of a simple tube circuit (oscillator?) using a triode so we could try to convert it to be ngspice compatible. Don't forget to attach the triode models.

  • ngspice is only the simulator, it provides no symbols nor an schematic editor.
  • ngspice works using netlists so you can use every schematic editor which is able to export ng-spice compatible netlists. Even ltspice generates a temporary ".net" file which you could try to import and run with ngspice.
  • The ltspice ".asc" files cannot be directly used. AFAIK there is no converter available.
  • Many models working with ltspice can be used in ngspice. The ngspice manual has a section about special switches to be more ltspice compatible. (e.g.: "set ngbehavior=ltpsa")

I personally prefer gschem (from gEDA) as schematic editor but KiCAD has a good integration with ngspice.

Have fun, Toni
 
Hi Bea and astx,

Bea,There is an JAES article, 1995 March by Marshall Leach. It has sub circuits for tubes and pspice netlists for both singe stage and an amplifier as well as some theory.

astx, I have installed ngspice v30 and gscheme from fedora29. Just have had time to run your example in #10 but it's a great showcase, thanks.

Aside from schematic editor have you compared pcb to kicad?

/örjan
 
Last edited:
Member
Joined 2011
Paid Member
Tubeamp - this one?

http://leachlegacy.ece.gatech.edu/papers/tubeamp/tubeamp.pdf
I haven't used KiCAD because it heavily depends on wx widgets which was years ago a nightmare to get it running. This has bettered significant because all major linux distributions support the wx widgets.
In the meantime I have written many small helper scripts around gEDA tools which help me saving time like exporting pdf schematics, pcb gerbers, symbol generators ...

BR, Toni
 
Member
Joined 2011
Paid Member
TUBE simulation example

Thx! Based on the above pdf I have created this simulation. Tubes are no problem here ...
I have created a triode symbol for gschem - it takes just a few minutes to understand, where to place the correct pin numbers to get the subcircuits working. To design a pentode or whatever symbol should be even no problem. I have seen some subckt's with integrated heater simulation too...

BR, Toni
 

Attachments

  • tube_preamp.png
    tube_preamp.png
    218 KB · Views: 104
  • ngspice_tubesim.zip
    4.5 KB · Views: 46
Last edited:
Member
Joined 2011
Paid Member
Have a look on this environment variables ("man ngspice")
SPICE_LIB_DIR
SPICE_EDITOR
SPICE_SCRIPTS default $SPICE_LIB_DIR/scripts
SPICE_PATH default $SPICE_EXEC_DIR/ngspice


There exists no file "standard.bjt" like in LTSpice but of course many of this and other spice libraries are useable in ngspice too.


BR, Toni
 
Use the folder where your circuit.cir resides.


The search path for circuit.cir (aka filename) is:


Infile_Path/<path/filename>

(Infile_Path is the path of the input file *.sp containing the netlist)


NGSPICE_INPUT_DIR/<path/filename>

(where an additional path is set by the environmental variable)


<path/filename> (where the search is relative to the current directory (OS dependent))


Maybe that this will require a bit of clean-up (at least some more flexibility with .inc and .lib may be beneficial).
 
Member
Joined 2006
Paid Member
I only get node voltages, not something like this in LTSpice:

Name: q18 q17 q6 q5 q23
Model: ksc2690 ksa1220 bc560c bc550c q2sa1943
Ib: 1.55e-04 -5.45e-05 -2.59e-06 2.27e-06 -1.41e-02
Ic: 1.97e-02 -1.72e-02 -1.34e-03 1.21e-03 -1.25e+00
Vbe: 6.64e-01 -6.34e-01 -6.17e-01 6.21e-01 -5.99e-01
Vbc: -2.21e+01 2.21e+01 2.27e+01 -2.27e+01 2.28e+01
Vce: 2.28e+01 -2.27e+01 -2.33e+01 2.33e+01 -2.34e+01
BetaDC: 1.27e+02 3.15e+02 5.17e+02 5.32e+02 8.92e+01
Gm: 7.61e-01 6.63e-01 5.15e-02 4.67e-02 4.11e+01
 
Member
Joined 2011
Paid Member
Example after "op" command (netlist must be loaded)

Code:
ngspice 8894 -> show r68
  Resistor: Simple linear resistor
     device                   r68
      model                     R
 resistance                   0.1
         ac                   0.1
      dtemp                     0
     bv_max                 1e+99
      noisy                     1
          i            -0.0119918
          p           1.43803e-05
"show" shows all devices.
Note: if you want current values you need to set

Code:
.options savecurrents
BR, Toni
 
Member
Joined 2006
Paid Member
What with KiCad?

Example after "op" command (netlist must be loaded)

Code:
ngspice 8894 -> show r68
  Resistor: Simple linear resistor
     device                   r68
      model                     R
 resistance                   0.1
         ac                   0.1
      dtemp                     0
     bv_max                 1e+99
      noisy                     1
          i            -0.0119918
          p           1.43803e-05
"show" shows all devices.
Note: if you want current values you need to set

Code:
.options savecurrents
BR, Toni

But when running spice from KiCad, I cannot do that?
 
Dear Toni,

after shutting down part of my business the last days, i think i can continue with this topic.

[*]ngspice works using netlists so you can use every schematic editor which is able to export ng-spice compatible netlists. Even ltspice generates a temporary ".net" file which you could try to import and run with ngspice.
[*]The ltspice ".asc" files cannot be directly used. AFAIK there is no converter available.
I just found that: simulation - Is there a way to open/import gschem .sch file in qucs? - Electrical Engineering Stack Exchange

Otherwise that would mean we have to redraw the schematics? Or is there any tool to set up some kind of schematics from a netlist?

I personally prefer gschem (from gEDA) as schematic editor but KiCAD has a good integration with ngspice.

It is probably mostly a matter of getting used to a software interface. Do You or someone else have any idea which of the schematics editors is "closest" to that of LTSpice - in terms of operations, keyboard shortcuts and so - it is just about ease of migration.