# LTspice: un-include library?

#### ebeowulf17

Joined Aug 12, 2014
3,275
So, I've failed miserably at finding answers to this through google. I have an LTspice file that worked with a library inclusion. I later realized the need for a library for just one part was annoying and started including component info as spice directives, and thought I had everything working. When I copied the file to another computer, it wouldn't run sims, saying it couldn't find the library file. It shouldn't need the library file, but I can't figure out how to un-include it.

If I view the netlist, I can see a .lib reference, but I can't edit it. If I export the netlist and remove the library reference, I can simulate successfully, so I know the file would work without the library, if I could just make it exist. But, when I export the netlist, I can't figure out how to make a visible schematic out of it again. Surely there's a way to manually edit the netlist and still have it associated with a schematic, right?

Alternately, if I could just remove the .lib reference without going into the netlist directly, I'd be fine with that too. Any advice? Here's the netlist:
Code:
* C:\Users\Synesso\Documents\LTspice-local\Triac-SSR_EBS_09c-Synesso.asc
V1 U1_MT1 N010 SINE(0 240 60)
V2 N002 0 PULSE(0 5 0.0055 0 0 0.05 0.2 1)
R1 N005 N007 100
R2 N004 N002 330
R6 0 N010 500m
R7 N003 N002 330
R3 N008 N009 500
R4 U1_MT1 0 500m
R5 U1_gate N001 500
R8 U1_MT2 N006 100
XU3 N007 N009 N010 Q6025P5
XU1 U1_MT2 U1_gate U1_MT1 Q6025P5
C2 N006 N007 0.1µ
L1 U1_MT2 N005 75m Rser=0
XU2 N003 0 N001 U1_MT2 MOC3022
XU4 N004 0 N007 N008 MOC3022
.SUBCKT S6040R     1  2             3
*       TERMINALS: A  G             K
Qpnp    6          4  1             Pfor      OFF
Qnpn    4          6  5             Nfor      OFF
Rfor    6          4  500MEG
Rrev    1          4  500MEG
Rshort  6          5  15
Rlat    2          6  2.64
Ron     3          5  6.1m
Dfor    6          4  Zbrk
Drev    1          4  Zbrk
Dgate   6          5  Zgate
.MODEL  Zbrk       D  (IS=10F       IBV=1U    BV=600)
.MODEL  Zgate      D  (IS=10F       IBV=100U  BV=10      VJ=0.3)
.MODEL  Pfor       PNP(IS=10P       BF=3.5    CJE=200p   CJC=200p   TF=0.3U)
.MODEL  Nfor       NPN(IS=10P       ISE=1E-9  BF=100.0   RC=13.6M   CJE=1000p   CJC=200p    TF=0.3U)
.ENDS
.tran 0 .1 0 0.1
.SUBCKT MOC3022 1 2 3 4
* OPTO TRIAC
* Helmut Sennewald  8/10/2004
* MOC3022   I_trig=5mA
*  D+  D-  MT2  MT1
.PARAM Itrig=5m
.PARAM RH1=20k
.PARAM RH2=20k
.PARAM RH3=16.7k
Q2 vb1 vb1p vd1 0 PNP1
Q1 vb1p vb1 4 0 NPN1
R3 vb1 4 {RH2}
D1 1 2 DL
R1 ctrl1 4 1
C1 ctrl1 4 10µ
R2 ctrl1 vb1 {RH1}
R4 vd1 vb1p {RH3}
B1 ctrl1 4 I=-500*I(D1)*3m/Itrig
R6 vd2 vb2 {RH2}
D3 vd2 3 D1
Q3 vb2 vb2p 4 0 PNP1
Q4 vb2p vb2 vd2 0 NPN1
E1 vd2 N001 ctrl1 4 -1
R5 N001 vb2 {RH1}
R7 vb2p 4 {RH3}
D2 3 vd1 D1
R34 3 4 100MEG
.MODEL PNP1 PNP(Is=1e-15 BF=10 Cjc=10p Cje=20p Tf=0.1u Ise=1e-12)
.MODEL NPN1 NPN(Is=1e-15 BF=10 Cjc=10p Cje=20p Tf=0.1u Ise=1e-12)
.MODEL D1 D(Is=0.1u Rs=2 Cj0=50p)
.MODEL DL D(Is=1e-20 Rs=5)
.ENDS
.SUBCKT Q6025P5    1    2         3
*       TERMINALS: MT2  G         MT1
Qnpn1   5          4    3         NoutF   OFF
Qpnp1   4          5    7         PoutF   OFF
Qnpn2   11         6    7         NoutR   OFF
Qpnp2   6          11   3         PoutR   OFF
Dfor    4          5    DZ        OFF
Drev    6          11   DZ        OFF
Rfor    4          6    12MEG
Ron     1          7    10m
Rhold   7          6    50
RGP     8          3    13
RG      2          8    5.8
RS      8          4    100
DN      9          2    DIN       OFF
RN      9          3    6.12
GNN     6          7    9         3       1.1
GNP     4          5    9         3       0.521
DP      2          10   DIP       OFF
RP      10         3    3.56
GP      7          6    10        3       0.1
.MODEL  DIN        D    (IS=382F)
.MODEL  DIP        D    (IS=382F  N=1.19)
.MODEL  DZ         D    (IS=382F  N=1.5   IBV=50U  BV=600)
.MODEL  PoutF      PNP  (IS=382F  BF=1    CJE=380p TF=0.3U)
.MODEL  NoutF      NPN  (IS=382F  BF=3    CJE=380p CJC=76p  TF=0.3U)
.MODEL  PoutR      PNP  (IS=382F  BF=5    CJE=380p TF=0.3U)
.MODEL  NoutR      NPN  (IS=382F  BF=0.5  CJE=380p CJC=76p  TF=0.3U)
.ENDS
.SUBCKT Q6040KH6   1    2         3
*       TERMINALS: MT2  G         MT1
Qnpn1   5          4    3         NoutF   OFF
Qpnp1   4          5    7         PoutF   OFF
Qnpn2   11         6    7         NoutR   OFF
Qpnp2   6          11   3         PoutR   OFF
Dfor    4          5    DZ        OFF
Drev    6          11   DZ        OFF
Rfor    4          6    12MEG
Ron     1          7    10m
Rhold   7          6    50
RGP     8          3    12
RG      2          8    5.8
RS      8          4    100
DN      9          2    DIN       OFF
RN      9          3    4
GNN     6          7    9         3       0.1
GNP     4          5    9         3       0.1
DP      2          10   DIP       OFF
RP      10         3    3.56
.MODEL  DIN        D    (IS=382F)
.MODEL  DIP        D    (IS=382F  N=1.19)
.MODEL  DZ         D    (IS=382F  N=1.5   IBV=50U  BV=600)
.MODEL  PoutF      PNP  (IS=382F  BF=0.5  CJE=380p TF=0.3U)
.MODEL  NoutF      NPN  (IS=382F  BF=3    CJE=380p CJC=76p  TF=0.3U)
.MODEL  PoutR      PNP  (IS=382F  BF=3    CJE=380p TF=0.3U)
.MODEL  NoutR      NPN  (IS=382F  BF=0.5  CJE=380p CJC=76p  TF=0.3U)
.ENDS
.lib Z:\LTspice\OPTO TRIAC.txt
.backanno
.end
All I need to do is remove the line ".lib Z:\LTspice\OPTO TRIAC.txt" a few lines from the end without separating it from the schematic. Surely this is a trivial task and I'm just missing something obvious, right?

#### ebeowulf17

Joined Aug 12, 2014
3,275
Oh, and I did already find where there was an auto-library inclusion in the custom component itself, and I deleted that. As I said, even after that, it runs the sim just fine from the netlist without the library. I just can't figure out how to make this change to a schematic (or edit a netlist and still end up with a schematic.)

#### eetech00

Joined Jun 8, 2013
2,274
It's not clear from your post but...
Do you have a schematic? Or only a netlist?

Last edited:

#### ebeowulf17

Joined Aug 12, 2014
3,275
I have the schematic. Just couldn't figure out how to remove the library reference from it.

I think I've figured out now that it's being included based on the presence of a custom opto symbol assembly, despite the fact that I removed the auto-include parameter from that part. I don't have access to the files right now, but I'll dig in deeper again tomorrow. I'm wondering if I can just assign the necessary spice model to a totally generic assembly so that no external files, library or otherwise, are required. I'd like to make the .asc file totally portable if I can do so without too much trouble. This file already includes a generic triac symbol assembly linked to a custom triac spice model, and that part works great, so I imagine all I need is a generic symbol with 4 or more pins that I can assign my opto model to. I realize that means it won't have an appropriate symbol for the opto, but I'm ok with that.

If that sounds wrong let me know. Otherwise I'll try that tomorrow and see how it goes. Also tomorrow I can upload the .asc file if it helps. Thanks!

#### eetech00

Joined Jun 8, 2013
2,274
So...there is no ".lib Z:\LTspice\OPTO TRIAC.txt" statement on the schematic?
Judging by the .lib statement position in the netlist, it looks to be on the schematic instead of embedded in a symbol. If so, you should be able to just delete the statement from the schematic.
But I'm guessing you already tried that.

Otherwise, you can test if the reference is in the symbol like this:

1. View the netlist (View->spice netlist)
You should see the .lib statement in the listing.
2. Delete the suspect Symbol from the schematic, but don't save.
This should remove the symbol and .lib reference from the listing
3. View the netlist again (View->spice netlist)
The .lib statement should be gone.

If the .lib statement is still in the netlist after the above test, then the reference statement is somewhere else.
Maybe embedded in another symbol?

You can extract just the .subckt you need from the library and save it to its own file.
Then reference the .subckt name in the desired symbol file provided the pin mapping is correct.

You can also place the .subckt statement right on the schematic, but it does clutter the schematic.

Also, If you edit the attributes of a symbol file (that is, using the symbol editor to edit the .asy file) the existing symbol(s) used in the schematic are not updated. You have to delete each of them and add them back in.

#### ebeowulf17

Joined Aug 12, 2014
3,275
Thanks for the detailed, excellent feedback!
If so, you should be able to just delete the statement from the schematic.
But I'm guessing you already tried that.

Otherwise, you can test if the reference is in the symbol like this:
There was no such .lib statement directly on the schematic. I tried the test you described, and the .lib reference in the netlist goes away when I delete the two relevant symbols.

You can also place the .subckt statement right on the schematic, but it does clutter the schematic.
I had already copied the relevant .subckt statement into the schematic, so it's ready to go - I just didn't realize right away that the .lib inclusion had lingered!
Also, If you edit the attributes of a symbol file (that is, using the symbol editor to edit the .asy file) the existing symbol(s) used in the schematic are not updated. You have to delete each of them and add them back in.
I strongly suspect that this is where I went wrong. My earlier version of this schematic included a library reference in the symbol. I went into the symbol editor and removed the reference, but I didn't erase and replace the symbols on the schematic. I'll try that tomorrow. Thanks so much for your help. I'll let you know what I find.

#### ebeowulf17

Joined Aug 12, 2014
3,275
I was able to get it working with one of the generic symbols - it's an 8DIP, which is 4 pins more than I need, but it's working the way I want now. Thanks so much for the help. I've included the file and an image in case your interested. I would've liked to make a single-file, portable version of this that had a symbol that looked more like an opto, but as far as I can tell, you would need at least one additional file for the custom symbol. The symbol is not a high priority, so I'm just glad I've got the simulation working and portable now.

#### Attachments

• 6 KB Views: 10

#### eetech00

Joined Jun 8, 2013
2,274
Hi

I'll make a symbol and post in a couple of days.

Am I understanding correctly that you don't want to use an .inc statement on your schematic to point to a file containing your subckt definitions?

Just curious...

#### ebeowulf17

Joined Aug 12, 2014
3,275
Hi

I'll make a symbol and post in a couple of days.

Am I understanding correctly that you don't want to use an .inc statement on your schematic to point to a file containing your subckt definitions?

Just curious...
In my dream world, I would have just one file (.asc) that was all inclusive. In reality, maybe it would be worth compromising on that to have meaningful symbols and a cleaner schematic.

Here's my issue, the reason I prefer the one file approach: I end up running spice on a variety of computers at work and at home, for both work and play. The computers don't all have consistent file/folder structures. I'd like to be able to move files, whether through email, cloud services, jump drives, or shared servers, and easily open any file on any computer without too many struggles. I've worked with other pieces of software that handled all file references in absolute terms instead of relative paths (something like c:\user\documents\ltspice\myfile.lib instead of just myfile.lib.) This means that if you copy the file to a different computer, you have to edit the paths for all external references.

If I can include files with relative references, such that LTspice will just look for associated files in whatever folder the .asc file is in, that wouldn't be so bad. That would just mean I'd need to remember to copy/backup a few extra related files to match up with my .asc file. If they're all in the same folder and LTspice can find them without me holding its hand the whole time, that'd probably be worth it. But if every time I want to use a file on a different computer it requires a bunch of installation/configuration, it's probably not worth it. I want this to be portable and fairly easy.

#### eetech00

Joined Jun 8, 2013
2,274
If I can include files with relative references, such that LTspice will just look for associated files in whatever folder the .asc file is in, that wouldn't be so bad. That would just mean I'd need to remember to copy/backup a few extra related files to match up with my .asc file. If they're all in the same folder and LTspice can find them without me holding its hand the whole time, that'd probably be worth it. But if every time I want to use a file on a different computer it requires a bunch of installation/configuration, it's probably not worth it. I want this to be portable and fairly easy.
But that's the way it works.
As long as you have all related (custom) files in the same folder as the schematic, and you haven't used paths in your include statements or symbols, LTspice will search the schematic folder for them.

In other words, if your include statement looks like this:

.inc myfile.txt

LTspice will look in the schematic folder for the file.

#### ebeowulf17

Joined Aug 12, 2014
3,275
But that's the way it works.
As long as you have all related (custom) files in the same folder as the schematic, and you haven't used paths in your include statements or symbols, LTspice will search the schematic folder for them.

In other words, if your include statement looks like this:

.inc myfile.txt

LTspice will look in the schematic folder for the file.
Sounds great! Not sure how I got headed down the wrong path. When I looked for info on this stuff before, I ended up watching a video from LT which led me to using new symbols that had attached .lib file references with an absolute path address. I think maybe their recommendations make life a little more convenient if you're only working on one system and never sharing files. I'm not sure - either way it definitely didn't work well for me! I'll see what I can do tomorrow with including custom symbols and maybe spice directives too. Thanks again for your help!

#### eetech00

Joined Jun 8, 2013
2,274
Hi
If you can post your original "problem" files, I might be able to figure out what the problem was.
Can you post?

#### ebeowulf17

Joined Aug 12, 2014
3,275
Ok, I think I've got a version working which relies on a few extra files. I'm sharing a zip with those files, and also the original troublesome one. Let me know what you think of my solution, and also if there's a better way I could've fixed the original. Thanks for all your help!

While I've got your brains, a few other spice questions:
1) When I first tried to run this, I just made the AC source without a ground reference and nothing worked. I was advised that I could add super-high value resistors to ground to satisfy LTspice, and I ended up using a pair so that the AC moves around ground instead of above it. It recently occurred to me that it might make more sense to use two separate AC voltage sources, with ground in the center. Does that seem better or worse in any way? Does it matter?
2) I also didn't realize till I had been playing with this for a while that I set the AC voltage as 240, but that's 240 peak to peak, and I'm really using 240 RMS. This is sort of convenient in the sense that it allows me to read other numbers as if they're the RMS equivalent (a 3A peak current really represents 3A RMS, etc.) instead of doing conversions on all the numbers I see. On the other hand, it means any instaneous measurement, and perhaps the subtleties of timing for TRIAC activation and other such things, would be off. Should I be setting my voltage at 339VAC (peak to peak) so that it truly behaves like 240 RMS? Is there a standard way people handle such things? Does it vary on a case by case basis?

Thanks!

#### Attachments

• 6.6 KB Views: 7
• 2.8 KB Views: 9

#### eetech00

Joined Jun 8, 2013
2,274
Ok, I think I've got a version working which relies on a few extra files. I'm sharing a zip with those files, and also the original troublesome one. Let me know what you think of my solution, and also if there's a better way I could've fixed the original. Thanks for all your help!
The circuit in the zip file works fine. The other asc file (I assume that's the problem "original" one) doesn't have the symbol files with it, so can't check. I prefer the way you did the schematic in the zip file, much cleaner.

While I've got your brains, a few other spice questions:
1) When I first tried to run this, I just made the AC source without a ground reference and nothing worked. I was advised that I could add super-high value resistors to ground to satisfy LTspice, and I ended up using a pair so that the AC moves around ground instead of above it. It recently occurred to me that it might make more sense to use two separate AC voltage sources, with ground in the center. Does that seem better or worse in any way? Does it matter?
I don't know why you would want multiple AC sources. LTspice just needs a return to ground to function. What you have should be OK. In reality, your circuit really only has one AC voltage source, right? I would have probably used a transformer driven by the AC voltage source, but what you have is OK.
Remember, because both sides of the AC voltage source is basically floating, you'll need to click U1_MT1 then drag the probe over to U2_MT1 and release to get the full AC reading. Otherwise, you'll just read half the voltage.

2) I also didn't realize till I had been playing with this for a while that I set the AC voltage as 240, but that's 240 peak to peak, and I'm really using 240 RMS. This is sort of convenient in the sense that it allows me to read other numbers as if they're the RMS equivalent (a 3A peak current really represents 3A RMS, etc.) instead of doing conversions on all the numbers I see. On the other hand, it means any instaneous measurement, and perhaps the subtleties of timing for TRIAC activation and other such things, would be off. Should I be setting my voltage at 339VAC (peak to peak) so that it truly behaves like 240 RMS? Is there a standard way people handle such things? Does it vary on a case by case basis?

Thanks!
Yes. I would convert 240 RMS to volts pk-to-pk and use that value in the voltage source. That way you can let LTspice do the calc work for you. You'll be able to ctl-click on a waveform and get a direct RMS reading.
Whenever I work with AC voltages, I always convert the signal to an RMS value. Just helps keep my measurements straight. But it should be handled on a case by case basis.

hope this helps

Last edited: