Using Spice/PSpice (Vishay optocoupler) models in LTSpice

I am trying to use the Vishay-provided spice models of the 6N137 high-speed optocoupler in LTSpice. (Source: http://www.vishay.com/optocouplers/list/product-84732/)

Both the "PSpice" model and the "Spice" model fail however.

With the "PSpice" model:

WARNING: Can't resolve .param dpwr=$g_dpwr WARNING: Can't resolve .param dgnd=$g_dgnd
Fatal Error: Port(pin) count mismatch between the definition of subcircuit "and2" and instance: "xx1:u2"
The instance has more connection terminals than the definition.


With the "Spice" model:

Too few nodes: au1.a [1] [du1.a] adc_a


What do I need to do to make either of these work in LTSpice?

• Is it by any chance already included in ltwiki.org/files/LargeCollection.zip, from ltwiki.org/?title=Components_Library_and_Circuits. It's a very good resource. Otherwise, can you build your component from the ground up, define your ports, give them names and add your model, as per zen22142.zen.co.uk/ltspice/newsymbols.htm? – winny May 24 '16 at 8:00
• can you post the schematic – ElectronS May 25 '16 at 9:12
• @CL Thanks for offering a bounty for my question! Please feel free to edit the question if you have any ideas to make it better fit your own requirements. – ARF May 25 '16 at 11:49
• @ElectronS Which schematic? I am trying to use the model files you can download on the page linked in the question. – ARF May 25 '16 at 11:50

Indeed, the model is not appropriate for LTSpice (as usual...).

Here is the tweaked 6N137 model. What was wrong was the use of the internal AND gate that combines the enable and the opto input. It was using PSpice syntax. Also, there was a Td (delay) specified for the internal opto switch, and this is unsupported by LTspice on the ISWITCH model.

So, basically, I redefined a new AND2 subcircuit to replace the existing one (using a basic IF function and the & operator), and added a DELAY20n subcircuit to simulate the missing delay from the switch (using a small RC filter). I had to slightly modify the main subcircuit according to this, of course.

Now, I can't guarantee the new model behaves exactly as the original one (actually, I can guarantee it does not behave exactly as the original one), but I think the deviations are minor. I checked the various delays with a test circuit, and they seem to be within spec.

Here you go:

************************************************
**  enable- high, NMOS output
**  --  6N137,VO2601/2611, VO0600/0601/0611 ---
************************************************
** test conditions:VCC=5V, RL=350, CL=15pF, IF=10mA
** characteristics: VF=1.4V, ITH=5mA, VEH=2V, VEL=0.8V
** VOL=0.6V, tpLH=TpHL=70nS, tr=22nS, tf=17nS
**
** Model Node - Symbol - Pin
** 1 (DA)       A         2
** 2 (DK)       K         3
** 3 (GND)    GND         5
** 4 (VO)      VO         6
** 5 (VE)      VE         7
** 6 (VCC)    VCC         8
**
*$.SUBCKT 6N137 DA DK GND VO VE VCC dD1 DA 6 DEMIT vV1 6 DK DC 0 wW1 VCC 7 vV1 I_SW1 rR3 GND 7 1K xU3 7 7delay GND DELAY20n xU2 7delay VE 8 VCC GND AND2 rR4 8 9 5K rR5 VCC VE 100K MQ1 VO 9 GND GND MOST1 W=9.7M L=2U ;NMOS OUTPUT .MODEL DEMIT D +IS=1.69341E-12 RS=2.5 N=2.4 XTI=4 +EG=1.52436 CJO=1.80001E-11 VJ=0.75 M=0.5 FC=0.5 .MODEL MOST1 NMOS (LEVEL=3 KP=25U VTO=2 RD=45) .MODEL I_SW1 ISWITCH (Roff=1e6 Ron=1 IT=4.9m IH=0.1m) .ENDS *$

***-------------------------------------------------------------------------
* 2 INPUT AND GATE
*
.SUBCKT AND2 A B Y VCC GND
ETHRS   THRS GND VALUE {1.5} ; Logic level threshold
EGATE   YINT GND VALUE {IF(V(A) > V(THRS) & V(B) > V(THRS), V(VCC), V(GND))}
RINT YINT Y 1
CINT Y 0 10p
.ENDS

***------------------------
* DELAY
*
.SUBCKT DELAY20n IN OUT GND
E IN2 GND VALUE {V(IN)}
Rdelay IN2 OUT 10k
Cdelay OUT GND 2p
.ENDS


And as a bonus, a simple asy symbol file that can be used with it:

Version 4
SymbolType BLOCK
RECTANGLE Normal 64 64 -64 -64
SYMATTR Prefix X
SYMATTR Value 6N137
PIN -64 -32 LEFT 8
PINATTR PinName A
PINATTR SpiceOrder 1
PIN -64 32 LEFT 8
PINATTR PinName K
PINATTR SpiceOrder 2
PIN 64 48 RIGHT 8
PINATTR PinName GND
PINATTR SpiceOrder 3
PIN 64 16 RIGHT 8
PINATTR PinName VO
PINATTR SpiceOrder 4
PIN 64 -16 RIGHT 8
PINATTR PinName VE
PINATTR SpiceOrder 5
PIN 64 -48 RIGHT 8
PINATTR PinName VCC
PINATTR SpiceOrder 6


For the LTSpice users that don't know how to use the whole thing (because it's not straightforward): copy/paste the asy symbol file contents in a file named 6N137.ASY and copy/paste the whole spice model details from above in a file called 6N137.LIB. Then, from you schematic, place the 6N137 component (from the ASY file). Also add a .include 6N137.lib directive somewhere in your schematic. You're done. Just note that all files must be located in the same folder.

I also tried to use (and uncovered) the same problems with the Vishay model for the 6N137. I then tried the solution provided by Dim, without good success (sorry, but there it is.) So this left me with either spending time fixing the errors (there are a few areas that got my attention and curiosity, but I wasn't sure about) or else checking in with the Yahoo Groups site for LTspice. I decided to start there and was able to find a nice symbol and a model that worked for me.

I then made a few small changes related to how the symbol specifies the library. (The symbol can specify it so that one does not need to use a .include on the schematic to find it.) I also set it up so that it is possible to place multiple models (similar ones, anyway) into the same model file and LTspice will automatically provide a drop-down selection list. (This uses an undocumented 'feature' of LTspice.)

Here is the symbol, to start. Copy and paste it into a file located in the ../lib/sym folder (or in any other directory you please.) Use the filename 6N137.ASY when saving it.

Version 4
SymbolType CELL
LINE Normal -96 -48 -56 -48
LINE Normal -56 -16 -56 -48
LINE Normal -56 16 -56 48
LINE Normal -96 48 -56 48
LINE Normal -80 -16 -32 -16
LINE Normal -56 16 -32 -16
LINE Normal -56 16 -80 -16
LINE Normal -80 16 -32 16
LINE Normal 128 -32 112 -32
LINE Normal 24 0 12 -4
LINE Normal 24 0 20 -12
LINE Normal 20 -4 24 0
LINE Normal 112 49 128 49
LINE Normal 112 16 112 49
LINE Normal 96 16 112 16
LINE Normal 96 -23 96 25
LINE Normal 112 -16 96 -16
LINE Normal 112 -32 112 -16
LINE Normal 91 25 91 -23
LINE Normal 80 0 91 0
LINE Normal 55 25 55 -23
LINE Normal 44 1 55 1
LINE Normal 44 -64 44 1
LINE Normal 128 -64 44 -64
LINE Normal 64 -22 64 -96
LINE Normal 102 12 108 16
LINE Normal 102 20 108 16
RECTANGLE Normal -96 -96 128 64
ARC Normal -4 12 20 -12 16 -4 -4 0
ARC Normal -28 12 -4 -12 -28 4 -4 0
ARC Normal 34 -23 80 25 55 25 55 -23
TEXT 105 -77 Left 2 E
TEXT 28 -77 Left 2 V+
WINDOW 0 -32 -112 Left 2
WINDOW 38 -16 80 Left 2
SYMATTR SpiceModel 6N137
SYMATTR Description High Speed Photocoupler
SYMATTR Prefix X
SYMATTR ModelFile 6N137.SUB
PIN -96 -48 NONE 0
PINATTR PinName A
PINATTR SpiceOrder 1
PIN -96 48 NONE 0
PINATTR PinName K
PINATTR SpiceOrder 2
PIN 128 48 NONE 0
PINATTR PinName S
PINATTR SpiceOrder 3
PIN 128 -32 NONE 0
PINATTR PinName C
PINATTR SpiceOrder 4
PIN 64 -96 NONE 8
PINATTR PinName V
PINATTR SpiceOrder 5
PIN 128 -64 NONE 8
PINATTR PinName E
PINATTR SpiceOrder 6


Also note that I've used CELL and not BLOCK, above. This is how a symbol should be set up, nominally. (The BLOCK type is for times when the symbol represents another page of a hierarchical schematic.)

Now for the model file. But just for a moment, first, go up and take a look for a line that says SYMATTR ModelFile 6N137.SUB and note the same there. That's the name of the file you need to use for the model file, when saving it. If you want to use a different name, you will need to modify that line in the above symbol file so that it matches up. That said, here is the model file:

.subckt 6N137 A K S C V E
D1 A N001 LED
C1 A K 1p
V1 N001 K 0
R2 ta S 100
C2 ta S 200p
B2 S ta I=TABLE(I(V1), 0,0,2.5m,50m,15m, 55m)
C10 A C 0.1p
C11 K S 0.1p
M1 C ga S S NMOS1
C5 C ga 10p
De1 E V Dd1
R6 V E 6k
R7 E S 100k
B4 0 en I=TABLE(V(E,S), 0,0,1.4,0,1.5, 1m)
R4 en 0 1k
R5 V S 1.5k
C6 C S 10p
C4 en 0 10p
B3 S ga I=V(ta,s)*V(en)*10m
R3 ga S 100
C3 ga S 20p
.model LED D(Is=1e-17 Rs=4 N=1.5 Eg=1.7 CJO=5p Tt=5n)
.model NMOS1 NMOS(Vt0=2 Kp=0.03 Rs=5 Rd=5 lambda=0.02)
.model Dd1 D(Is=1e-7 Rs=10 Cjo=5p Tt=5n)
.ends


Save that file in the .../lib/sub folder (or in any other directory you please... though you may need to use the full file specification in the symbol file unless LTspice has otherwise been informed about the folder.)

The above should work with LTspice.

If you want to have several related models (ones that use the same symbol without confusion, but perhaps have either different approaches or else somewhat different behaviors), you can add them to the model file above. Just paste them above or below (or between) other .SUBCKT/.ENDS subcircuits. Make sure they are named differently, of course! If you do this, LTspice will provide a drop-down on the symbol that will the user to select the device from a list. Which is nice.

Typically, this means the symbol name must be placed on the SYMATTR SpiceModel line in the symbol and not on the SYMATTR Value line. (The SYMATTR Value line needs to be blank, I think.) And this means the symbol itself probably needs to be edited so that the SpiceModel is shown and not the Value.

Just a few notes about creating symbols with lists that LTspice can handle in a drop-down.

I wish I'd been able to get Dim's stuff working quickly. But it went badly enough that only a cursory glance then convinced me to start with something that had been thoroughly tested by LTspice aficionados. And it just worked. Which is nice.

• Strange, I really tested that exhaustively at the time. Anyway, +1. – dim Jul 22 '17 at 16:16
• @dim I'm using it in a particular way that perhaps led to my difficulties. I also saw the E types being used in AND2 and these don't simulate as reliably as other approaches. So I decided to look further and went to the Yahoo group for it. (Helmut does a yeoman's job over there managing and contributing to the group -- the best unpaid support money cannot buy.) The one I posted here "just worked." So I thought I'd add it. – jonk Jul 22 '17 at 17:58

As it says, your schematic symbol does not match the model file. Easiest and fastest way to fix this is generating automagically the schematic symbol from the model file.

Read ltpsice help FAQ for 3rd party models, which links to the schematic symbol creation. Basically you will open the text file inside ltspice and rightclick on the model name. Afterwards you'll find the new component in autogenerated folder when adding new parts.

It is possible to repurpose the opto symbol to use 3rd party model but it's a little bit more complicated process. You have to have a separate symbol for each model unless it's something really basic like a transistor or a diode.

• I had already tried that. The error message is the same. It is not the top-level model that is the problem but a sub-model that the model uses. – ARF May 24 '16 at 22:09
• @ARF Okay, I see the problem here. Pspice/orcad can do some digital "stuff" as well as global g_dpwr / g_dgnd nodes. Ltspice does not implement the pspice digital side. In short, the model is not compatible and you'd have to modify it to work around missing "and" function. All I can suggest is the yahoo ltspice group where you can find working 6n137 model and symbol. Obviously not quite the same as the vishay model but at least you could change the mosfet/led parameters to match. Instead of "and" he's using a voltage controlled current source. – Barleyman May 25 '16 at 9:58