SPICE model file includes .LIB definition, LTSpice looking externally (?) - Page 1
Forum section: electronics / projects

author: 741
author_rank: Frequent Contributor
timestamp: September 02, 2022, 10:43:40 am
content: Diodes Inc provide a file (diodes-spice-models.txt) with lots of subcircuit models (http://www.diodes.com/spice/downloadall). Although it is possible to copy sections into LTSpice, I tried using this file via ".include diodes-spice-models.txt", then specifying the desired model using "CTRL+right-click" on a Zener symbol, entering a 'Value' of DI_BZX84C2V7.The simulation stops immediately with a messageFatal Error: Could not open library file "B540C"Insidediodes-spice-models.txtappears this:.LIB B540C*.MODEL B540C D (+LEVEL = 1 IS = 1.5672e-06 RS = 0.0209949+N = 1.01362 IBV = 0.0001 CJO = 8.98694e-10+VJ = 0.396195 MJ = 0.457747 FC = 0.5+XTI = 0.000352915 EG = 0.750278 TRS1 = 0.00406277+TRS2 = 2.17553e-07 BV = 50 TT = 0 )*.ENDL B540CThat looks like a self-contained definition (?). If it is self contained then why the error message? (Or, do I have to find a separate library file?)

author: moffy
author_rank: Super Contributor
timestamp: September 02, 2022, 11:48:09 am
content: Try commenting out the .LIB 540C by putting a * in front e.g. *.LIB 540C, it does appear to be self referencing, also comment out the .ENDL B540C

author: SiliconWizard
author_rank: Super Contributor
timestamp: September 02, 2022, 06:55:26 pm
content: Quote from: moffy on September 02, 2022, 11:48:09 amWell, in ngspice, .LIB/.ENDL statements are handled correctly for libraries. But then the library needs to be included with a '.lib' statement where you want to include the library, and not '.include'.Not sure LTSpice handles Spice libraries at all though.

author: 741
author_rank: Frequent Contributor
timestamp: September 06, 2022, 09:42:41 am
content: Out of interest, I tried using .lib (instead of .include). The error message from LTSpice is the same though.

author: moffy
author_rank: Super Contributor
timestamp: September 06, 2022, 10:31:41 am
content: The problem seems to be SPICEs use of the .LIB statement:1. Used to include an external library e.g. .LIB 540C.libor2. Used inside a library at the start:.LIB 540Cstatements.ENDL 540CThe second seems to have fallen out of use and that is what you seem to have encountered. They just copied a .lib file's text into this one large file but left the start and end statements, which are being misinterpreted as (1) not (2).This is from the NGSPICE user manual:2.8 .LIBGeneral form:.LIB filename libnameExamples:.LIB /users/spice/common/mosfets.lib mos1The .LIB statement allows including library descriptions into the input file. Inside the*.lib file a library libname will be selected. The statements of each library inside the*.lib file are enclosed in .LIB libname <...> .ENDL statements.If the compatibility mode (16.14) is set to ’ps’ by set ngbehavior=ps (17.7) in spinit(16.5) or .spiceinit (16.6), then a simplified syntax .LIB filename is available: a warningis issued and filename is simply included as described in Chapt. 2.7.

author: julian1
author_rank: Frequent Contributor
timestamp: September 06, 2022, 11:00:48 am
content: That file is unfortunately full of small syntax errors, that prevent importing cleanly into ltspice. I spent a couple of hours with sed, trying to clean it up, before giving up. It's easier to just copy the desired components across to a new file, rather than import it in full.

author: iMo
author_rank: Super Contributor
timestamp: September 06, 2022, 01:01:26 pm
content: Except that you have to change the prefix attribute in the standard diode to "x" such it recognizes the new model.The .inc and .lib should work then fine (try to create a file, like "MyLib.lib" with the BZX diode model only and do .inc or .lib).PS: I've also spent an hour with that file, there are some encrypted models inside, not sure ltspice can read it..

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: September 07, 2022, 01:13:50 am
content: Hi,I prefer to include the models on the LTspice schematic like this:I have put the diode in a test circuit to measure forward voltage versus current.By including the model on the schematic I can share a single file. If you use .lib the link to the file will be break if you try and share the .asc file with a friend.In this case the model is a diode, we can use the Diode, D, prefix. CTRL_RIGHT CLICK on a component to access the attribute editor.If the model is a subckt then use the 'X' prefix.I have attached the LTspice file.Regards,Jay_Diddy_BB540C.asc(0.86 kB - downloaded 42 times.)