LTspice: un-include library?

Discussion in 'Programmer's Corner' started by ebeowulf17, Feb 17, 2016.

  1. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    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 (Text):
    1. * C:\Users\Synesso\Documents\LTspice-local\Triac-SSR_EBS_09c-Synesso.asc
    2. V1 U1_MT1 N010 SINE(0 240 60)
    3. V2 N002 0 PULSE(0 5 0.0055 0 0 0.05 0.2 1)
    4. R1 N005 N007 100
    5. R2 N004 N002 330
    6. R6 0 N010 500m
    7. R7 N003 N002 330
    8. R3 N008 N009 500
    9. R4 U1_MT1 0 500m
    10. R5 U1_gate N001 500
    11. R8 U1_MT2 N006 100
    12. XU3 N007 N009 N010 Q6025P5
    13. XU1 U1_MT2 U1_gate U1_MT1 Q6025P5
    14. C2 N006 N007 0.1µ
    15. L1 U1_MT2 N005 75m Rser=0
    16. XU2 N003 0 N001 U1_MT2 MOC3022
    17. XU4 N004 0 N007 N008 MOC3022
    18. .SUBCKT S6040R     1  2             3
    19. *       TERMINALS: A  G             K
    20. Qpnp    6          4  1             Pfor      OFF
    21. Qnpn    4          6  5             Nfor      OFF
    22. Rfor    6          4  500MEG
    23. Rrev    1          4  500MEG
    24. Rshort  6          5  15
    25. Rlat    2          6  2.64
    26. Ron     3          5  6.1m
    27. Dfor    6          4  Zbrk
    28. Drev    1          4  Zbrk
    29. Dgate   6          5  Zgate
    30. .MODEL  Zbrk       D  (IS=10F       IBV=1U    BV=600)
    31. .MODEL  Zgate      D  (IS=10F       IBV=100U  BV=10      VJ=0.3)
    32. .MODEL  Pfor       PNP(IS=10P       BF=3.5    CJE=200p   CJC=200p   TF=0.3U)
    33. .MODEL  Nfor       NPN(IS=10P       ISE=1E-9  BF=100.0   RC=13.6M   CJE=1000p   CJC=200p    TF=0.3U)
    34. .ENDS
    35. .tran 0 .1 0 0.1
    36. .SUBCKT MOC3022 1 2 3 4
    37. * OPTO TRIAC
    38. * Helmut Sennewald  8/10/2004
    39. * MOC3022   I_trig=5mA
    40. *  D+  D-  MT2  MT1
    41. .PARAM Itrig=5m
    42. .PARAM RH1=20k
    43. .PARAM RH2=20k
    44. .PARAM RH3=16.7k
    45. Q2 vb1 vb1p vd1 0 PNP1
    46. Q1 vb1p vb1 4 0 NPN1
    47. R3 vb1 4 {RH2}
    48. D1 1 2 DL
    49. R1 ctrl1 4 1
    50. C1 ctrl1 4 10µ
    51. R2 ctrl1 vb1 {RH1}
    52. R4 vd1 vb1p {RH3}
    53. B1 ctrl1 4 I=-500*I(D1)*3m/Itrig
    54. R6 vd2 vb2 {RH2}
    55. D3 vd2 3 D1
    56. Q3 vb2 vb2p 4 0 PNP1
    57. Q4 vb2p vb2 vd2 0 NPN1
    58. E1 vd2 N001 ctrl1 4 -1
    59. R5 N001 vb2 {RH1}
    60. R7 vb2p 4 {RH3}
    61. D2 3 vd1 D1
    62. R34 3 4 100MEG
    63. .MODEL PNP1 PNP(Is=1e-15 BF=10 Cjc=10p Cje=20p Tf=0.1u Ise=1e-12)
    64. .MODEL NPN1 NPN(Is=1e-15 BF=10 Cjc=10p Cje=20p Tf=0.1u Ise=1e-12)
    65. .MODEL D1 D(Is=0.1u Rs=2 Cj0=50p)
    66. .MODEL DL D(Is=1e-20 Rs=5)
    67. .ENDS
    68. .SUBCKT Q6025P5    1    2         3
    69. *       TERMINALS: MT2  G         MT1
    70. Qnpn1   5          4    3         NoutF   OFF
    71. Qpnp1   4          5    7         PoutF   OFF
    72. Qnpn2   11         6    7         NoutR   OFF
    73. Qpnp2   6          11   3         PoutR   OFF
    74. Dfor    4          5    DZ        OFF
    75. Drev    6          11   DZ        OFF
    76. Rfor    4          6    12MEG
    77. Ron     1          7    10m
    78. Rhold   7          6    50
    79. RGP     8          3    13
    80. RG      2          8    5.8
    81. RS      8          4    100
    82. DN      9          2    DIN       OFF
    83. RN      9          3    6.12
    84. GNN     6          7    9         3       1.1
    85. GNP     4          5    9         3       0.521
    86. DP      2          10   DIP       OFF
    87. RP      10         3    3.56
    88. GP      7          6    10        3       0.1
    89. .MODEL  DIN        D    (IS=382F)
    90. .MODEL  DIP        D    (IS=382F  N=1.19)
    91. .MODEL  DZ         D    (IS=382F  N=1.5   IBV=50U  BV=600)
    92. .MODEL  PoutF      PNP  (IS=382F  BF=1    CJE=380p TF=0.3U)
    93. .MODEL  NoutF      NPN  (IS=382F  BF=3    CJE=380p CJC=76p  TF=0.3U)
    94. .MODEL  PoutR      PNP  (IS=382F  BF=5    CJE=380p TF=0.3U)
    95. .MODEL  NoutR      NPN  (IS=382F  BF=0.5  CJE=380p CJC=76p  TF=0.3U)
    96. .ENDS
    97. .SUBCKT Q6040KH6   1    2         3
    98. *       TERMINALS: MT2  G         MT1
    99. Qnpn1   5          4    3         NoutF   OFF
    100. Qpnp1   4          5    7         PoutF   OFF
    101. Qnpn2   11         6    7         NoutR   OFF
    102. Qpnp2   6          11   3         PoutR   OFF
    103. Dfor    4          5    DZ        OFF
    104. Drev    6          11   DZ        OFF
    105. Rfor    4          6    12MEG
    106. Ron     1          7    10m
    107. Rhold   7          6    50
    108. RGP     8          3    12
    109. RG      2          8    5.8
    110. RS      8          4    100
    111. DN      9          2    DIN       OFF
    112. RN      9          3    4
    113. GNN     6          7    9         3       0.1
    114. GNP     4          5    9         3       0.1
    115. DP      2          10   DIP       OFF
    116. RP      10         3    3.56
    117. .MODEL  DIN        D    (IS=382F)
    118. .MODEL  DIP        D    (IS=382F  N=1.19)
    119. .MODEL  DZ         D    (IS=382F  N=1.5   IBV=50U  BV=600)
    120. .MODEL  PoutF      PNP  (IS=382F  BF=0.5  CJE=380p TF=0.3U)
    121. .MODEL  NoutF      NPN  (IS=382F  BF=3    CJE=380p CJC=76p  TF=0.3U)
    122. .MODEL  PoutR      PNP  (IS=382F  BF=3    CJE=380p TF=0.3U)
    123. .MODEL  NoutR      NPN  (IS=382F  BF=0.5  CJE=380p CJC=76p  TF=0.3U)
    124. .ENDS
    125. .lib Z:\LTspice\OPTO TRIAC.txt
    126. .backanno
    127. .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?
  2. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    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.)
  3. eetech00

    Senior Member

    Jun 8, 2013
    It's not clear from your post but...
    Do you have a schematic? Or only a netlist?
    Last edited: Feb 17, 2016
  4. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    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!
  5. eetech00

    Senior Member

    Jun 8, 2013
    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.
  6. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    Thanks for the detailed, excellent feedback!
    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.

    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!
    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.
  7. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    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.
  8. eetech00

    Senior Member

    Jun 8, 2013

    Glad you got it working.:)
    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? o_O

    Just curious...
  9. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    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.
  10. eetech00

    Senior Member

    Jun 8, 2013
    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.
  11. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    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!
  12. eetech00

    Senior Member

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

    Thread Starter Distinguished Member

    Aug 12, 2014
    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?

  14. eetech00

    Senior Member

    Jun 8, 2013
    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.

    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.

    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: Feb 19, 2016
  15. ebeowulf17

    Thread Starter Distinguished Member

    Aug 12, 2014
    Thanks! Yeah, I'm pretty happy with where it's sitting now too. Of course, I still have a number of details to figure out about the circuit design itself, but I'm feeling much better about how I'm using the sim now. Thanks for the ctl-click tip! I didn't know about that one. Knowing that I can do that makes the use of proper peak to peak voltage definitions painless. That's fantastic!