diyAudio

diyAudio (http://www.diyaudio.com/forums/)
-   Software Tools (http://www.diyaudio.com/forums/software-tools/)
-   -   Things you should know about LTSpice (http://www.diyaudio.com/forums/software-tools/150272-things-you-should-know-about-ltspice.html)

keantoken 29th August 2009 11:09 PM

Things you should know about LTSpice
 
Hello all.

I'm writing this so that new users to LTSpice will have a place to refer to in order to get "up to speed" quickly without too many hangups while they are acclimating to the program.

My intent in this thread is to provide a quick reference where a person can learn how to use LTSpice effectively and avoid any inherent pitfalls. Thus, if you need help for a specific problem, I ask that you go to the Yahoo group or post in another thread (maybe someone should post the "LTSpice Help" thread). To avoid clutter, I wish to address (1) common hangups, (2) tips that apply broadly, (3) good practice in using the simulator.

If the solution to your problem is not here, you should try the LTSpice Yahoo group which was specifically made to give support for LTSpice:

http://tech.groups.yahoo.com/group/LTspice/

Contents:
Most common issues, in order of discovery
Models and their affect on accuracy
FAQ

Here are the problems I ran into in sequential order:

1: Compression.
2: Timestep.
3: Ground paths.
4: Slanted FFT.

1: This causes strange looking traces and things like chopped off transients because some samples are deleted to make more room. It is easiest to turn this of by including the parameter ".options plotwinsize=0" in your schematic.

2: If no maximum timestep is specified, LTSpice varies the timestep on-demand so as to smoothen out processor usage. This produces weird errors on the FFT and results in chopped off transients. For example, I made a saw oscillator that discharged a capacitor very fast once a threshold voltage was reached. I looked at the capacitor current and noticed that the discharges had seemingly random peaks that weren't constant. This fooled me into thinking my circuit was somehow not reliable. After changing the timestep to 100nS though, all transients were the same hight and the circuit performed perfectly. Also, if your circuit is oscillating and you can't get it to stop, try lowering the timestep. Sometimes oscillation can be triggered by a too high timestep by a simulator fault.

For THD and amplifier work, I find that I get the best accuracy with fast simulations if I make the timestep at least the wavelength of my input signal divided by 10,000. Any less samples and THD measurements aren't accurate. So the .tran statement usually looks like this:

.param Freq=10k
.tran 0 {14/Freq} {4/Freq} {14/Freq/10000}
.four {Freq} V(Vout) 5 5

This causes the simulator to run for four cycles to warm up the circuit, and then it starts saving data for 10 more cycles. The timestep is set to give 10000 samples per cycle. All I need to do to change the input frequency is change Freq.

Since distortion measurement is all about the FFT, someone suggested to me that I only needed to use as many samples as was needed by the FFT window. So if my FFT is set to use 16384 samples, I do this:

.param Freq=10k
.param FFT=16384
.tran 0 {14/Freq} {4/Freq} {14/Freq/FFT}
.four {Freq} V(Vout) 5 5

This is supposed to reduce the errors drastically since there is no need to interpolate samples. Alas, I forget to do it.
The .four statement runs a fourier (THD) analysis on the Vout node. To view the results of this analysis, look at the error log through the "view" button.

3: LTSpice does not allow for floating nodes. Presumably, this is because it needs a default reference point for the probe whenever you click on a node. So, if you have an isolation transformer, and the output end has no conductive path to ground, you will get an error.

4: The FFT in LTSpice is strange in that if there is DC drift in your circuit, there will be a large slant in the noise floor that will obscure low-level harmonics and cause faulty THD measurements. The first solution people seem to think of is to run the simulation for a few cycles before they measure. This works, but is inefficient and it will take forever if you have too much drift. What causes this is usually large capacitors in the feedback and signal paths of an amplifier, which aren't computed perfectly for the initial operating point solution. My solution to this problem is to record the voltages across these capacitors, and replace them with voltage sources. It won't model frequency response realistically, but now your FFT will be more honest.

Models:

After everything above has been sorted out, there is another thing you should know. This is that many (most?) of the models available in troves from the common semiconductor suppliers are inaccurate and in many cases don't behave much like the actual device at all. This means that if you are using false models, your circuit will probably behave significantly different in the simulator than it does in real life.

A few members here on DIYAudio have tried their hands at making adequate models for the common devices used in audio, such as the MJL3281a/1302a, and the 2SC4793/A1837 provided by Andy_C.

If you need accuracy, models are what you should be worrying about first. Models can be verified by obtaining their characteristic curves in the simulator and comparing them to the datasheet curves/values. The page below shows a circuit that will do this:

http://andyc.diy-audio-engineering.org/spice_models_3.xhtml

NOTE: I eventually want to attach to this post this mentioned circuit and a .txt file full of models that match the datasheets well. If you have models you can contribute, please post them or send them to me. I also plan on including more general helpful files in the attachments.

FAQ:

1: Can I export a simulation trace in audio format?

A: Yes, by using the .wav command. Refer to the help file for syntax and usage.

2: How do I get subcircuits to work?

A: I have no clue. They can be made to work, but if you are having problems you should go to the Yahoo group and ask there. Maybe someone else can write up an explanation of how LTSpice handles subcircuits?

PS: I'm sure everything here is accurate, but if I am wrong please correct me.

Good luck,
- keantoken

To mods: If you will, please allow me to edit this post indefinitely so I can add useful information if it shows up in discussion or I stumble across it somewhere.

iko 30th August 2009 02:01 AM

Nice, thanks for putting it all together in one place. I use ltspice quite a bit too, and had to deal with some of these issues. Model inaccuracy is something I dread, but did nothing about it so far, so I'll definitely welcome your contribution.

Perhaps a wiki page would be more suited to this kind of post?

keantoken 30th August 2009 02:11 AM

You're welcome. :)

I thought about a wiki page, but I think here is more suitable. Not many people are versed in wiki, and I think there is more of a chance I'll get constructive criticism here. I think that if it's here, more people are likely to see it.

- keantoken

BudP 30th August 2009 02:25 AM

Not sure if you are interested in tubes and transformers, for models in this thread, but Steve Bench and Dave Slagle have put together a very useful group of models here.

http://www.intactaudio.com/forum/vie...09b3e4dd6280ba

Bud

keantoken 30th August 2009 02:35 AM

Thank you for the link.

Mostly I was concerned about semiconductor models, since they are mass-produced. I don't know if you could find a tube model that wasn't at least a good approximation of the actual device performance.

It might be useful to have some models for power transformers, so someone could perhaps simulate their amp with a presumably realistic power supply.

- keantoken

keantoken 30th August 2009 02:53 AM

Okay, I have a problem.

Look at the difference in Hfe curves for the fairchild and ONSemi datasheets for the BCxxx series:

http://www.fairchildsemi.com/ds/BC/BC547.pdf
http://www.datasheetcatalog.org/data...xohlhq11wy.pdf

By gut instinct I feel I should trust the ONSemi curves because in comparison it looks like Fairchild is very optimistic. Which one do I choose? I am trying to verify my BCxxx models.

- keantoken

deandob 30th August 2009 02:59 AM

As a new user I find LTSpice fairly easy to use. However it would be easier if could work with dynamic voltage sources and component values (eg. potentiometers) so that when you changed the value on the fly the simulation automatically updates. This may be possible but I have not been able to work it out.

kenpeter 30th August 2009 03:09 AM

I'm sure it depends more who made the part, and on what day,
than who published the spec sheet, or fudged the curves...

Maybe more important to upgrade models with the quirky stuff (like
variable gate capacitance) than obsess to exactly match DC curves
to a specific sample in hand that may be different next week.

I would kill for a potentiometer.
Can you at least define a resistance to a .param variable?
Is there a way to access and modify variables while the sim runs?

andy_c 30th August 2009 03:20 AM

Quote:

Originally Posted by kenpeter (Post 1910107)
I would kill for a potentiometer.
Can you at least define a resistance to a .param variable?
Is there a way to access and modify variables while the sim runs?

Try this:
.param Rpot 20k
.param x 0.5
or
.step param x 0.1 0.9 0.1

Now make the pot from two series resistors, say R1 and R2. Set R1 to a value {Rpot*(1-x)} and R2 to the value {Rpot*x} . Note that these two add up to Rpot. Be sure to use curly braces to define the values, because they are .params. See the documentation for .step for more options, like:

.step param x list 0.1 0.13 0.8 0.95

...and so on.

Edit: For an example of a simulation that uses tons of .param statements for component values, see this post. That example doesn't use .step though, if I recall correctly.

deandob 30th August 2009 03:28 AM

I just worked out the potentiometer - there are example sym & sub files available in the library on the yahoo groups link in the first post, similar to what Andy has posted.

Is there any way to adjust a component value (eg. potentiometer) while the simulation is running and see it automatically update the sim results? Seems like an obvious feature missing, and I'm assuming is a noob question but I can't find an answer.


All times are GMT. The time now is 10:50 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio


Content Relevant URLs by vBSEO 3.3.2