Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to use LM317 LTspice Model

Status
Not open for further replies.

wealth210

New Member
Hello
My problem is that I download LM317 Spice model from yahoo,when I copy this model to another circuit which a simple voltage regulator and simulate this circuit,but there show belowing error:
unkown subcircuti called in:
xu2 n001 n002 vout LM317

I use yahoo itself LM317 test circuit for simulating,and the reasult is right.so just wonder why my circuit will happen error,how to use this LM317 spice model.show me the detail and easily understand step.thank you very much.
 
You need four things to make it work.

First, the attribute on the symbol has to match the modelName/subscircuitName.

Second, you have to have a .Include statement somewhere on the schematic which has the file name of the library containing the model/subscircuit netlist.

Third, the file containing the model/subscircuit netlist must be copied to the same subdirectory where the circuit file resides.

Fourth, the library file has to contain a .Model or .Subcircuit entry line and netlist with a name that matches what is on the symbol in your schematic.
 
I think there may be several ways to make it work, but here's what I have:

Symbol file:
Code:
Version 4
SymbolType CELL
RECTANGLE Normal 64 48 -64 -32
SYMATTR Value LM317
SYMATTR Prefix X
SYMATTR Value2 LM317
SYMATTR Description LM317 voltage regulator
SYMATTR ModelFile LM317.sub
PIN -64 0 LEFT 8
PINATTR PinName I
PINATTR SpiceOrder 1
PIN 0 48 BOTTOM 8
PINATTR PinName ADJ
PINATTR SpiceOrder 2
PIN 64 0 RIGHT 8
PINATTR PinName O
PINATTR SpiceOrder 3
Model file:
Code:
*LM317 TI voltage regulator - pin order: In, Adj, Out
*TI adjustable voltage regulator pkg:TO-3
.SUBCKT LM317 1 2 3 **Changes my be required on this line**
J1 1 3 4 JN
Q2 5 5 6 QPL .1
Q3 5 8 9 QNL .2
Q4 8 5 7 QPL .1
Q5 81 8 3 QNL .2
Q6 3 81 10 QPL .2
Q7 12 81 13 QNL .2
Q8 10 5 11 QPL .2
Q9 14 12 10 QPL .2
Q10 16 5 17 QPL .2
Q11 16 14 15 QNL .2
Q12 3 20 16 QPL .2
Q13 1 19 20 QNL .2
Q14 19 5 18 QPL .2
Q15 3 21 19 QPL .2
Q16 21 22 16 QPL .2
Q17 21 3 24 QNL .2
Q18 22 22 16 QPL .2
Q19 22 3 241 QNL 2
Q20 3 25 16 QPL .2
Q21 25 26 3 QNL .2
Q22A 35 35 1 QPL 2
Q22B 16 35 1 QPL 2
Q23 35 16 30 QNL 2
Q24A 27 40 29 QNL .2
Q24B 27 40 28 QNL .2
Q25 1 31 41 QNL 5
Q26 1 41 32 QNL 50
D1 3 4 DZ
D2 33 1 DZ
D3 29 34 DZ
R1 1 6 310
R2 1 7 310
R3 1 11 190
R4 1 17 82
R5 1 18 5.6K
R6 4 8 100K
R7 8 81 130
R8 10 12 12.4K
R9 9 3 180
R10 13 3 4.1K
R11 14 3 5.8K
R12 15 3 72
R13 20 3 5.1K
R14 2 24 12K
R15 24 241 2.4K
R16 16 25 6.7K
R17 16 40 12K
R18 30 41 130
R19 16 31 370
R20 26 27 13K
R21 27 40 400
R22 3 41 160
R23 33 34 18K
R24 28 29 160
R25 28 32 3
R26 32 3 .1
C1 21 3 30PF
C2 21 2 30PF
C3 25 26 5PF
CBS1 5 3 2PF
CBS2 35 3 1PF
CBS3 22 3 1PF
.MODEL JN NJF(BETA=1E-4 VTO=-7)
.MODEL DZ D(BV=6.3)
.MODEL QNL NPN(EG=1.22 BF=80 RB=100 CCS=1.5PF TF=.3NS TR=6NS CJE=2PF
+ CJC=1PF VAF=100)
.MODEL QPL PNP(BF=40 RB=20 TF=.6NS TR=10NS CJE=1.5PF CJC=1PF VAF=50)
.ENDS LM317 **changes may be required on this line**

Save symbol file as LM317.asy, in lib\sym\misc
Save model file as LM317.sub, in lib\sub

This is definitely working, I've been using it this past week, and it seems to be a good likeness of a 317 too.
 
Last edited:
Hello
Still not solve my problem,though do what your indication.Maybe I'm a not clever man and not understand your meaing completely,I just want to let LM317 LTspice Model work.what should do?Give me your detail step?Thank you.
 
Trust me, it works.
it doesn't get much easier, but it can get a bit easier if I attach files directly. You'll still have to copy them to where they need to go. Put the first one in the symbol library directory (files ending in .asy), ideally in subdirectory called misc. Put the second one in the .sub files directory.

Then select the symbol in the schematic editor. it will work because all the internal references are correct.

I think if you copied my earlier text correctly and saved it, you are using a text editor that is saving in Unicode, not plain text. Take care of that, you need to be very sure you use plain text when saving programming code of any type.
 

Attachments

  • LM317 LTspice Model.zip
    1.1 KB · Views: 7,029
Hello
Thank you very much,zoodlewurdle.You are right,Just trust you,then I succeed to use LM317 LTspice Model on my circuit and the simulation is right.But,I need to know one thing?
what's your meaning"you are using a text editor that is saving in Unicode, not plain text. Take care of that, you need to be very sure you use plain text when saving programming code of any type.
"
I often copy these files on text editor .txt and then save as it LM317.asy,what's wrong with me?Pls correct me.
 
Unicode is a way to store all the charaters used in maths symbols and other written languages. Computers used to use 'code pages' that stored only 256 characters. People neede dmore than that so code page swapping was needed. That didn't work well for many people so Unicode was made to store all the characters in one huge scheme that addresses up to 65536 possible characters. To do that it takes 2 bytes, not just 1 as ASCII does.

What that means is that if you have a new machine with a new operating system, there's a good chance it's storing a 'plain' text file in Unicode, not ASCII, and not telling you. So a variable 'A' in a computer language will be expressed as two bytes to a system that expects A as a single byte value 65. Chaos results. Or usually something just doesn't work.

If you're ever in doubt, get a hex editor like HxD (truly awesome tool, and free), that will show you EXACTLY what's really inside your files.
 
317 spice model

This is the first one i have tried to add and after a few hours I think it's time to ask for help. For some reason I could not uzip the zipped files so I copied the code from the 2 windows above and pasted into word pad. I then saved into lib\sym\misc as lm317.asy (text file) Same with the model into lib\sub as a text file. When i click on the 317 under misc it blinks but no symbol. It all seems pretty complicated but i think I'm close.
 
zoodlewurdle - Don't know if you're still around - I've only just registered. Just like to thank you for the code listings for the LM317, which worked first time with LTspiceIV (I've just updated from the old SwitcherCAD III, not having needed to do any simulation for some time).

Could you please let me know where the model code originated?
 
Last edited:
zoodlewurdle - Don't know if you're still around - I've only just registered. Just like to thank you for the code listings for the LM317, which worked first time with LTspiceIV (I've just updated from the old SwitcherCAD III, not having needed to do any simulation for some time).

Could you please let me know where the model code originated?

hi,
I would suggest you join the yahoo LTspice user group, lots of info.
Look down the link for LM317

**broken link removed**
 
have i done something wrong?

i implemented the LM317 into some of my circuits and it made them act erratic, so i tried it in it most simple form and it doesn't work as it should, could anyone explain what i have done wrong
 

Attachments

  • Untitled.png
    Untitled.png
    140.3 KB · Views: 1,860
Last edited:
You may want to read this thread where the LM317 is well covered. Also, I don't quite understand your resistor values? However, read the linked thread.

Ron
 
Why simulate a simple voltage regulator?
If you make it like described in its datasheet then it works perfectly.

Your sketch had very odd very low value resistors and was missing an input and an output capacitor so it will problably mess-up.
The SIM program probably hasn't seen such a mess so it won't know what to show.
 
I ran your sim out of curiosity. It will run, even as you drew it, with correct resistor values. Make R1 for example 240R and R2 something reasonable (read the data sheet) and it should run. Use the GND as mentioned. Keep in mind that you will need caps as AG points out in an actual circuit. You should have gotten a ground error when you tried to run it.

Ron
 
hello anybody have mcp6002 model for LT spice, i just want to use it in my project but i didnt find it on LT spice library.
i would appriciate if someone attache me the model file.
thanks
 
You have hijacked an ancient thread :)
Join the Yahoo LTspice User Group and you can download free all sorts of models.
 
hi,
Its in Yahoo.

This is it
E
 

Attachments

  • MCP6001_test.zip
    3.4 KB · Views: 606
There is a text editor in LTspice that shows all the text in the model. Notepad can sometime hide control characters that have been inserted when using Unicode. this will upset LTspice. Open the file in LTSpice and you should be able to see any control characters that are upsetting it
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top