Common Issues Encountered By New Users

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
[wiki=Main Page]return to diyAudio Wiki Main Page[/wiki]
[wiki=LTSpice and What the New User Should Know]back up[/wiki]

(content from original article by keantoken, formatted and edited by mighydub)

[h=Numbers]%2[/h]
Numbers can be expressed in Spice using the familiar engineering multipliers, i.e. K (1e3), m (1e-3), u (1e-6), etc. However, these are NOT case sensitive! So 1M is not 1e6, it is 1e-3. Use 1000K, or 1Meg instead.

See the LTspice Help file, LTspice>General Structure and Conventions for the complete list and details.

[h=Compression]%2[/h]
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 off by including the parameter ".options plotwinsize=0" in your schematic.

[h=Timestep]%2[/h]
If no maximum timestep is specified, LTSpice varies the timestep on-demand so as to smooth 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 height 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.

[h=THD measurement]%2[/h]
The .four statement runs a fourier analysis on the node of interest and computes the THD. To view the results of this analysis, look at the Spice error log through the "view" menu.

Syntax: .four <frequency> [Nharmonics] [Nperiods] <data trace1> [<data trace2> ...]

To get an accurate result from the .four command, it is important to have compression turned off and the time step set properly, and for simulation to stop on an exact integer number of cycles. I also find that I get more consistent results by doing the FFT over multiple periods.

You can include spice directives on your schematic to automatically set the simulation time and timestep, and also the frequency of the input stimulus based on a single parameter. This way you only have to edit one line in the spice directives to change the input frequency, simulation time, and timestep. For example:
;turn off compression and use double precision
.options plotwinsize=0
.options numdgt=8

;set frequency and timestep
.param freq 1k
.param num_fft_pts 4096
.param timestep {1/{ {freq} * {num_fft_pts}} }

;perform FFT out to 9th harmonic over last 8 cycles
.four {freq} 9 8 V(ampOut)
For the simulation command, enter the following (modify as desired):
Stop time: {20/freq}
Maximum Timestep: {timestep}
For the voltage source driving the input, enter {freq} for the frequency.

So whatever frequency you choose, the simulation will run for 20 cycles with the appropriate timestep and input frequency.

If the THD result changes depending on how long you run the simulation before the .four command is executed, that typically means there is DC drift in the circuit. See Slanted FFT below for causes and workarounds.

[h=Slanted FFT]%2[/h]
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.

[h=Ground Paths]%2[/h]
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.

I most often get that with series-connected capacitors. The solution is just to add a (very) large resistor across one of them or from the junction to earth. Similarly, with parallel-connected inductors - a small resistor in series with one of them cures the problem.

[h=Models]%2[/h]
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

For information on where to find models and how to add them, see [wiki=Models and Modeling Aids]%[/wiki]

If you have user made models you can contribute that you know to be accurate, please put them in [wiki=Spice Models - diyAudio Contributions]%[/wiki].

[h=Switch-on / switch-off behavior]%2[/h]
Probably good to check with other circuits too, but especially the kind of amp that runs off a single supply rail.

With pencil-and-paper design, guesstimates and a bit of calculation, I can get a fair idea of what kind of performance to expect ito output power, distortion, noise etc. Trying to figure out what exactly happens when you switch the thing on (or worse - off) just makes my head hurt, though.

I find modeling that really useful. The results can be scary, but at least you know how bad a problem you have to sort out.

You can simulate power-on behavior two ways - by controlling the Voltage primitives using the Advanced button, or by checking the "Start DC supplies at 0" on the simulation command

[h=Keeping it real - Power supplies]%2[/h]
Easy pitfall - you model an amp running off, say a +30V dc power supply. Results may be great in the sim, but real life's not like that.

What happens to your biasing, dc offsets etc if the supply droops to 26V or rises to 33V? Add some series resistance, say 1 ohm to your DC source and see what happens.

And what about hum? Try adding a couple of volts of 100 or 120 hz garbage to the power supply voltage and see what you get at the output.

[h=Real components]%2[/h]
I've been modeling more radio-frequency stuff than audio lately, and had to be really careful with this.

For example, CircuitMaker thinks all capacitors are "ideal" capacitors, but they're not. So where I'm using e.g. a 33uF electrolytic for supply decoupling, I'll add half an ohm of series resistance in the model to make it more realistic.

Similarly, those little axial inductors that almost look like resistors are self-resonant at a couple of MHz, so to model it properly you have to add a few pF of capacitance in parallel.

LTSpice uses perfect resistors and capacitors by default (inductors by default have 1mohm ESR), so if you want your circuits to be realistic (ESPECIALLY power supplies), add appropriate ESL and ESR to capacitors, ESR to batteries, capacitance to inductors, etc. (tip: ESL for electrolytics is approximately 1-2nF per mm of pin spacing). To change ESR, ESL, etc, right clikc on the component.

With audio circuitry, probably the biggest problem is that spice programs tend to think all transistors (of a given type) are identical, where in fact key parameters like Vbe and Hfe vary between individual devices and also depending on the weather.

That kind of thing probably isn't worth trying to figure out in the spice model. I tend to head back to pencil-and-paper, asking myself questions like: "If the two transistors in the input-stage LTP have HFE's of 200 and 300, how bad is the DC offset gonna be?" or "How bad is this current mirror if the Vbe of the two transistors is different by 100mV - and what size emitter resistors do I need to get it reasonable?".
 
Last edited:
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.