Things you should know about LTSpice

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
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.
 
Last edited:

iko

Ex-Moderator
Joined 2008
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?
 
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
 
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
 
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.
 
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?
 
Last edited:
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.
 
Last edited:
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.
 
Ah - you can use .step to change the value over a timeline I gather. Not as useful as dynamic but still helpful.

Is there an alternative sim package (freeware) that does real time run updates?

Not sure what you mean by "over a timeline"? If you use .step for a single parameter with N values, N simulations will be performed, and N curves will be shown on the output graph. Tuning is only useful IMO when the time duration of a simulation is very short, like AC analysis. Transient can take a while, which makes tuning clumsy. I worked as a developer on a simulation tool that had tuning, so I'm familiar with its uses. I'm not aware of any freeware that has it.
 
Might be easier if I explain what I'm doing. I have an opamp constant current source that is varied by the voltage on its non-inverting input. I want to model the current through the load output by varying a potentiometer on the non-inverting input. I started out varying the value of the resistive elements of the pot and plotting on a paper graph the load current but was thinking there must be an easier way to do this with such a basic circuit / simulation.

The step does work as it gives me various curves, except its difficult to work out what curves (flat DC current lines actually) relate to what values.

Sorry for the noob questions, I guess I got to spend more time playing, reading and learning....
 
Okay, here is the trick from the Yahoo LTspice group (thanks to the moderator, Helmut Sennewald). He's talking about the up/down arrow keys below.

Make the waveform window active.

Click on the label you are interested. It's the text near the top
of the waveform window, e.g. V(out).

Now you have a cursor attached to the curve.

You can step up/down with the cursor keys.

Move the cursor near the cross hair. When you see the "1" then
click the right mouse button. A small status window appear.

Cursor Step Information
Cursor 1: Val=2 (Run: 3/5)


There is also a selection in the Plot settings menu.
Plot Settings -> Select Steps

Best regards,
Helmut
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.