Support of "iswitch" in NGSpice

I ran into a problem with ngspice when trying to simulate a circuit which includes a THS4551 from TI.
I obtained the PSpice model for the TI amplifier from the TI website [1].

I am currently using Kicad 5.1.6 with a self compiled version of ngspice-32 on Debian.

In order to make the PSpice model of the TI amplifier work, I set up my ~/.spiceinit as follows:

* user provided init file
set ngbehavior=ps

This made most of the initial errors in my ngspice simulation disappear.

But now I have a problem with a very specific part of the THS4551 PSPice model:

.SUBCKT 08_OP_AMP_COMPLETE_W2_THS4551 1 2 3 4  
VW_W2         1 2 DC 0V

There are two parts which use an ISWITCH model as pasted above. ISWITCH is a purely PSpice model and does not directly exist in ngspice.
I would have assumed, that the PSpice compatibility mode of ngspice would translate this to an equivalent ngspice model, but this does not seem to be the case.

The ngspice-32 manual [2] in section shows, how the related VSWITCH model is translated from PSpice to ngspice:

The VSwitch

S1 2 3 11 0 SW

may become

a1 %v(11) %gd(2 3) sw
.MODEL SW aswitch(cntl_off=0.0 cntl_on=5.0 r_off=1e5+ r_on=0.1 log=TRUE)

but for the ISWITCH no such substitution is documented.

I tried to implement a similar substitution for the case of the ISWITCH model, as follows:

.SUBCKT 08_OP_AMP_COMPLETE_W2_THS4551 1 2 3 4  
a_W2         %id(1 2) %gd(3 4) _W2
.MODEL         _W2 aswitch(r_off=10MEG r_on=1 cntl_off=5U cntl_on=7U)

by making use of a aswitch ngspice model. But I am not sure if this is correct, and my circuit does not seem to simulate properly.

Does anybody have any experience, in how to model a ISWITCH PSpice mode in ngspice?


Ps: This is a pure ngspice issue, so if somebody knows a good ngspice forum where to post this question, please let me know :slight_smile:

Hey, hey. First off, I think you put the wrong link for the model. You accidentally linked to the TINA one. Here’s what I think you meant:

Anyway, there is a native current controlled switch (CSW) in ngspice/SPICE3/LTspice. See 3.3.15 of the ngspice manual for reference.

I attempted to convert the ISWITCH to CSW and this is what I came up with. I set IT equal to the average of ION and IOFF, and then IH to half the difference of ION and IOFF. So for one of them in your THS4551 LIB file:

.SUBCKT 08_OP_AMP_COMPLETE_W2_THS4551 1 2 3 4  
W_W2         3 4 VW_W2 _W2
VW_W2         1 2 0V
.MODEL         _W2 CSW ROFF=10MEG RON=1 IT=6U IH=1U

I then built the application circuit of Figure 80 in the datasheet. It seems to run correctly. I attached it here: (8.3 KB)

Might be good to add a feature request for ngspice to do an auto-convert like with the VSWITCH. Actually, scratch that. Make it a bug request, since all my feature requests have been sitting in limbo while feature-requests submitted as bugs have already been resolved:


Hey Ste,

thank you for your answer. I sadly had not time yet to try it out myself but it looks very convincing :slight_smile: .
I’ll get back to you, as soon as I found some time.

The ISWITCH is now avalable in ngspice (git branch pre-master) and may be invoked by setting

set ngbehavior=ps

in .spiceinit.


That’s awesome news. Thanks, man!

Hey Ste,

so I finally got around to spend a bit more time on this. And indeed, your approach correctly simulates no also in my circuit.
Thanks a lot for your help.

1 Like

Sure. Thanks to you too for making this thread, since it resulted in improvements to the ngspice engine.