Add To Library Lt Spice

Importing a .txt library into LTSpice #moc3021

#117541

Hello All,
I downloaded a spice model of an MOV from LittleFuse. The file downloads as an MHTML that i put into a text file.
I attempted renaming the file with '.lib' and including it in 'Document>LTspiceXVII>lib>sub' folder with no luck.
Please help if you know how to best import this sort of library.
Heres the link for the file:
https://www.littelfuse.com/~/media/electronics_technical/spice_models/varistors/varistors_ml_spice_model_lib.mht
#117542

An MHTML file probably contains unprintable characters. You might do better to display the web page, then select and copy the text from the page. You may be able to use CTRL-a instead of 'selecting'.

But what do you mean by 'no luck'? What happened? Did your computer sprout little legs or did you get an error message?

toggle quoted messageShow quoted text
Hello All,
I downloaded a spice model of an MOV from LittleFuse. The file downloads as an MHTML that i put into a text file.
I attempted renaming the file with '.lib' and including it in 'Document>LTspiceXVII>lib>sub' folder with no luck.
Please help if you know how to best import this sort of library.
Heres the link for the file:
https://www.littelfuse.com/~/media/electronics_technical/spice_models/varistors/varistors_ml_spice_model_lib.mht
#117543

Agreed. An MHTML file is definitely wrong. I don't know why Littelfuse provides that kind of file, but it's wrong.
If you have a .txt model or library, as your subject line suggests, then it is a plain, readable text file that doesn't have HTML code, and then it should be good for LTspice. There is no need to 'import' a .txt library into LTspice, because it works as-is, as long as it is plain text.
For the .mht file that you referred to, do you have a different link to the model, something that doesn't go to that .mht file? Perhaps they have a copy of the model that is plain text? Alternatively, can you open the .mht file in Internet Explorer, then copy-and-paste the text from the IE screen? (I don't touch Internet Explorer anymore so I can't do that.)
Andy
#117544

The file is an MHT file and doesn't need IE to open it; Firefox works.

toggle quoted messageShow quoted text
Agreed. An MHTML file is definitely wrong. I don't know why Littelfuse provides that kind of file, but it's wrong.
If you have a .txt model or library, as your subject line suggests, then it is a plain, readable text file that doesn't have HTML code, and then it should be good for LTspice. There is no need to 'import' a .txt library into LTspice, because it works as-is, as long as it is plain text.
For the .mht file that you referred to, do you have a different link to the model, something that doesn't go to that .mht file? Perhaps they have a copy of the model that is plain text? Alternatively, can you open the .mht file in Internet Explorer, then copy-and-paste the text from the IE screen? (I don't touch Internet Explorer anymore so I can't do that.)
Andy
#117546

I won't use Firefox either. Sorry. Yes, I'm stubborn about some things.
Some versions of Microsoft Word also can open them, but they look odd.
What I'm saying is, hopefully Littelfuse has that model (those models) in another format, not only as an MHTML file. Try to find that other file. If they don't have it in a plain text file, respectfully ask that they make one available.
Andy
#117549

This was the only file type they had. I was able to open the MHTML file and save is as a text and attempted to put that in the library folder but i was unable to link a symbol to the library.
#117550

You don't need to 'link a symbol to the library.'
If you have the model as a text file, you can bring it into your LTspice simulation by adding this line anywhere to the schematic:
.lib filename.ext
where filename.ext is the actual filename of the text (library) file. If that file is in the folder with the schematic, or in LTspice's cmp library folder (being careful to use the right one!), then you don't need to include the 'path' (the directories) before the filename.
There are ways to make the library file included automatically without adding the above line, but it's not always straight-forward. What kind of device is this for, and what symbol are you using? What kind of model is it (.MODEL or .SUBCKT)? Is it a symbol you created, one you downloaded, or are you using one of LTspice's existing symbols?
Andy

#117551

Also, you do have the option of pasting the model itself directly onto your schematic, as a SPICE Directive. Then there is no need to use a '.lib' or '.inc' statement, or anything special in the symbol.
Clearly this works best when the model is not too large. A big model takes up a lot of space on the schematic.
Andy
#117552

Hello jfisher,
I have helped with this problem sometimes ago in another forum. At that time, I maually corrected the file.
Basically I had to remove all text strings 3D and =20 and I had to fix some line breaks and comments.
Heres the link for the file:
https://www.littelfuse.com/~/media/electronics_technical/spice_models/varistors/varistors_ml_spice_model_lib.mht
Today I tried with different browsers. The only good choice has been the Internet Explorer due to its capability to export this file as text.
Open this link with the IE. Then 'Save As' -> Text(*.txt) and select the Coding:West Europe.
You will get a correct text file in PSPICE-Format. Now only the exponent-character ^ has to replaced with ** .
I named this new file with the ending .lib to distinguish it from the file saved from the Internet Explorer.
I have uploaded an example to the folder Temp.
Varistor_test_ML-series.zip
Helmut
#117553

Helmut,
That all worked perfectly!
Thank you all for your help on this topic, I was really puzzled by this problem
#117569

Guess there still is an issue with something i am doing. I am running a lightning simulation for RTCA-DO160 purposes for an aerospace program.
My circuit design implements a TVS and an MOV for different power consumption, however it seems that the MOV Spice model is unable to handle the speeds of the lightning simulation,
When i simulate i get the following: 'Analysis: Time step too small; time =2.54083e-006, timestep = 1.25e-019: trouble with node u3:1:4:'
U3 is the MOV and i attempted to make i big time amount but was unable to go higher than what is listed above.
#117570
Edited

'Timestep too small' errors have nothing to do with inability to handle the speeds of the signals in the simulation. It is all about difficulty with convergence, often caused by regions where the equations describing the element are poorly defined (discontinuous functions or derivatives). When SPICE or LTspice encounters those problems, it backs up, makes the timestep smaller, and tries again. When it hits a really bad spot, it repeatedly does that without success, until the timestep is unreasonably small, and it aborts.
As you noticed, LTspice aborted once the timestep reached 0.0000000001 nanoseconds. Small enough?
The node or element that is called out in the error report usually has nothing to do with the problem. It's just that it was peripherally related to the detection of the problem.
Did you try the many suggestions that are in the 'FAQ' file? Look for the section about 'Timestep too small' errors.
Files > z_yahoo > FAQ > faq_17-2.txt
https://groups.io/g/LTspice/files/z_yahoo/FAQ/faq_17-2.txt
If following those instructions doesn't help, it may help to upload your simulation files (a .ZIP file containing the schematic and model files, and any symbol files that didn't come with LTspice; but NOT any of LTspice's output files) to the group's Temp folder. Don't upload pictures of schematics.
Regards,
Andy
#117598

Andy,
I attempted the steps you suggested but had no luck. I uploaded a .zip file which has the schematic as well as the model files for the varistor previously talked about.
Files>Temp>lightning testing.zip
Any help you can provide would be greatly appreciated.
Best,
Jeff
#117600

Different methods from the 'timestep two small' suggestions will probably work. In this case setting max timestep to 2ns helped. Simulation runs slow but finishes.
Frank


Adding Spice Models to LTspice

Adding Series 4000 CMOS library to LTSPICE Published by Fudgy McFarlen on June 25, 2015 June 25, 2015. SPICE Research Links. Instructions how to use the library files. LTspice IV supplies many device models to include discrete like transistors and MOSFET models. Nevertheless, there are also many third-party models from manufacturers that are available that you could add to your LTspice IV circuit simulations. These third-party SPICE models are described with a.MODEL and.SUBCKT statements.

This tutorial is going to cover adding custom Spice models into your LTspice simulations and library. While it is very easy once you know how to do it, there are a couple pitfalls that can cause serious headaches if you are unaware.

Finding and Downloading the Spice Model

It might seem obvious, but the first thing you need to do is find a suitable Spice model. This can usually be done in one of two ways. The easiest method is to simply Google the phrase “[part I am looking for] spice model”. If the part is popular enough and isn’t some incredibly complex part, your search will usually turn up some hits. The second method is to directly search the part manufacturer’s web page for the part. Sometimes you will have to switch tabs, or it will simply be link on their part’s web page such in the following screenshot:

An unfortunate characteristic of the Spice world is that over time it has become fairly fragmented. Different design tools use different versions of Spice, hence, part manufacturers will often have the Spice file for their part available in a couple different formats. The best format to use is the Spice3 model, however the PSpice model will usually work in LTspice as well.

Once you have found the model you want to use, you need to make sure it is in the correct format with the correct extension. A Spice model file is nothing more than a text file with a different extension. In the case of LTspice, if the model file contains only a single model, it should be named with the .sub extension. If the file contains multiple models, then the file should be named with the .lib extension.

I’m not going to go into depth on renaming text file extensions, however one method to do it is to first open up the model in notepad (in Windows 7, right click on the file > open with > notepad). Next, go to file > save as. Where you type the file name in the file name text box, type the exactly desired file name in quotes, and the program will name it exactly that. For example you could type 1N4148.sub. If you tried typing the file name without the quotes you would get 1N4148.sub.txt instead of the desired 1N4148.sub.

Adding the Spice Model to your LTspice Library

For this tutorial we will be using a Spice model for a made up diode called the 1NADAM, named after your beloved engineer, me! You can either download the file here (righ click on link > save as), or simply copy the code below, paste it into a text document, and save it with the .sub (or .lib) extension as explained in the previous section.

As you can see, inside of the file for the 1NADAM there are .SUBCKT and .MODEL statements. Most Spice models downloaded from the internet will have .SUBCKT statements, because often time a simple .MODEL statement will not sufficiently model the complex behavior of modern parts. I am assuming that the reader knows the difference between a .SUBCKT and .MODEL (explaining those thoroughly is a topic for another tutorial). In short, however, a .MODEL statement will provide the model for an existing Spice primitive (i.e. a capacitor, resistor, transistor, diode, and so on). While .MODEL statements will work for simple simulations and old parts, it will not be very accurate for newer, smaller parts. For example, transistors have become so small and non-ideal, that the equations which we all learned in textbooks do not provide sufficient accuracy for good simulation results.

This is one case where a .SUBCKT model becomes very useful. This allows a manufacturer or engineer to create a more complex model using more than a single Spice primitive, which will lead to better results. This also allows manufacturers and engineers to create models which take into account any peculiarities or quirks that the component might have. You will be hard pressed to find a model for a real part which uses a single .MODEL statement for the Spice model. Therefore this tutorial assumes a .SUBCKT type model but will point out the difference where applicable.

Once you have the Spice model on your computer, adding it to your LTspice library is very easy. Simply copy the file to your LTCLTspiceIVlibsub folder. Usually the full path to that directory will be either C:Program Files (x86)LTCLTspiceIVlibsub on a 64 bit Windows 7 installation or C:Program FilesLTCLTspiceIVlibsub on a 32 bit (x86) Windows installation.

Using the Spice Model in a Circuit

Now that the Spice model is in your library, there are a couple things you need to do. The first is make the circuit which will contain our part. For example, here is a simple half-wave rectifier I have tossed together.

The next is to let LTspice know that you will be using that the newly added file. You do this by placing a Spice directive (s shortcut key, or the .op button on the toolbar) onto the schematic containing .lib FILENAME, using the entire name of the file containing your model. Make sure to include the file extension! This is the first pitfall I was talking about. Here is an example of how to correctly add our new file:

Spices

.lib 1NADAM.sub

Library

While the above way is correct, below you can see a common mistake which will not work:

.lib 1NADAM

Here you can see some screenshots showing how to add the spice directive on to the schematic.

In case some of you are wondering what exactly this does, it includes any models included in the specified file into the Spice simulation file. You might also be wondering what the difference between the .LIB and .INC directives is. The .LIB directive will only add models from the specified file. If you had some other directives in there, for example a .TRAN statement, it would be discarded. The .INC directive will include everything in the specified file into your project, regardless if it is a model, directive, netlist, or anything else. So use .LIB just to be safe in case there is some other junk in there (even though there shouldn’t be).

Now that you have added the file, you can simply use any .MODEL or .SUBCKT included in the file as you would with any of the default components. Just right click on a component’s default model (in this case the D right next to the diode), and change its value to the name of the model inside of the file. Alternatively you can hold ctrl then right-click on the symbol and change the value in the Value row). Usually you have to look inside the file using a text editor to see what exactly the author of the Spice file called the model. For example the model for the 1N4148 diode might not actually be called 1N4148 inside of the file.

Add Spice Library To Ltspice

Here is also where the second major pitfall comes in.

If you are using a .SUBCKT type model for a Spice primitive, you need to change the Spice prefix on the component!.

What the Spice prefix does is tells LTspice what kind of model to expect for the part. For example, on a diode, the default will be a D because, well, the part is a diode so it expects a diode model. Remember however that we are not using a regular diode model for our diode; we are using a .SUBCKT model. This means that we need to change the Spice prefix to a subcircuit model instead of a diode model. To do this, hold ctrl and then right-click on the symbol in the schematic. Then just double click in the Value cell next to Prefix, and change the value to an X.

Add Library Ltspice

At this point the file should be ready to simulate and look like this:

Add To Library Lt Spices

Congratulations, everything should be working now! We can run a simulation to see what comes out. Keep in mind that this circuit not meant to be a good rectifier. I purposely chose the values to make it easy to see what this circuit is actually doing just by looking at the output. Here is the result:

Conclusion and tl;dr (too long;didn’t read)

This article was much longer than I initially expected, and probably more than was really needed. However, what inspired me to write this tutorial was that when I was just starting to learn LTspice, I would read instructions people posted on forums, but I didn’t exactly understand what all the steps meant or how to perform them. For example I had no idea what “change the Spice prefix to X” meant, and I had no idea that you had to hold ctrl then right-click on the symbol to do it. In summary, here is a quick tl;dr version for people who might already be familiar with Spice and LTspice, and just want the quick and concise procedure. This will also serve as a good recap for people who read the entire article!

Ltspice Add Library

  1. Download and rename the Spice model to something that makes sense
  2. Move the Spice model into the sub folder in your LTspice directory
  3. Add a .LIB FILENAME directive onto your schematic
  4. Change the Value field for your symbol to the name of the model inside of your Spice model file
  5. If you are using a .SUBCKT type model for a Spice primitive, hold ctrl then right-click on the symbol and change the Prefix field to X