Installing and using LTspice IV (now including LTXVII). From beginner to advanced.

Note that LTspice allows you to configure those key presses, which I've changed to suit my way of working. A gotcha is that a new version of the program will discard the changes made, at least it does with my way of installing a new version - something I haven't bothered to work out a proper solution for, so far ...
 
Last edited:
Administrator
Joined 2007
Paid Member
Squarewave Testing.

Lets take a quick look at how the amplifier handles a squarewave, not least because this throws up some anomalies in how you interpret the results.

Open the file and change the input and output capacitors back to 1uf. Lets test the amp at 100kHz. To do this we now set the input voltage to deliver a
squarewave, so right click the voltage source and set the following options. Why so many cycles ? You will see in a moment. Click OK to enter the settings on the simulation.



Lets just run through those settings. You will notice we have to tell LT how long each cycle lasts and how long the "on" part of the cycle is. To do this we now calculate the period of one cycle. So 100kHz has a period of 1/100,000 (reciprocal of 100k) which is 0.00001 or 0.01ms or 10us. Whichever you prefer, LT will accept any. That is the period. For a squarewave we want it to have a 50:50 duty cycle, so that means the "on" time must be half the period. That is the 10us (period) and 5us (on time) settings. The amplitude is set by Vinitial and Von. In other words the voltage of the bottom and top of the squarewave. Setting one as a - (minus) value and the other as a + (plus) value gives a symetrical waveform centred on zero. The rise and fall times areself explanatory. 100ns seems a reasonable value typical of a mid range function generator. Tdelay sets the point into the cycle the waveform appears. So zero means it starts at the begining of a cycle.

Now we have to set the simulation run time. Let us display only 5 cycles for clarity. The sim therefore needs to run for 10us (the period) times by 5. So 50us in total. Now open the <edit simulation> window and enter 50us as a stop time. We can't do distortion measurements on non sines so we can dispense with the maximum timestep.



Now run the simulation and probe the input and the output.



Do you see a problem ? or does it look OK.

Double click the input voltage (the circuit nodes/traces not the actual source) so it is in focus and the only trace showing. Look at the amplitudes. It should be nicely centred around zero. Now double click the output voltage and look at the scale. Its all negative going. Now I know if I built this for real and scoped it, the output would be centred around zero. What has gone wrong ? Well again, it is the caps and their time constants.

Remember all those cycles we added to the input voltage source. Well now change the transient tab (goto <edit simulation>) to 100ms and rerun the sim.

Do you see how the output DC shift rises. In fact 100ms isn't really enough but you get the idea and see the problem. I will leave it to you to experiment
with adding even more cycles and a longer run time (hint... just add a zero to both settings). If you run it long enough the output should settle to a symetric square centred around the zero line.



We can now demonstrate a new aspect of LT. If you now hover over a section of that solid green trace (must be above it in the black area) and left click
and hold and drag... you can pull an oblong box over the waveform. Just make the box a few mm wide and covering the top and bottom of the trace. When you release the left click that portion of the waveform is expanded and displayed. You can do it again and again to zoom in on any part. Want to get back to the original... simply right click and select "zoom to fit"



And finally for this section... I just learnt something new. Remember I mentioned about having enough cycles set to cover the run time you want. Well it seems if you leave the box blank it runs continuosly. So here is the output waveform settling to a value centred above and below ground as the sim is left to run for longer.



And expanding the last part of the trace as we outlined earlier, we can see that after 1 second the output is pretty much stabilised.

 

Attachments

  • SquareSettings.PNG
    SquareSettings.PNG
    31.7 KB · Views: 370
  • Centred.PNG
    Centred.PNG
    46.9 KB · Views: 358
  • AboveBelow.PNG
    AboveBelow.PNG
    35.8 KB · Views: 309
  • Expand.PNG
    Expand.PNG
    49.5 KB · Views: 324
  • TimeConstants.PNG
    TimeConstants.PNG
    50.4 KB · Views: 356
  • Square Run.PNG
    Square Run.PNG
    54.4 KB · Views: 366
  • EditSimSquare.PNG
    EditSimSquare.PNG
    15.2 KB · Views: 363
Now we need to set the all important "Timestep" and again I must credit Bob Cordell for his excellent explanation of this (Designing Audio Power Amplifiers). The timestep relates the length of time the sample runs for, together with the frequency or period of the signal of interest. So this number needs to be altered for testing at different frequencies. I'm going to start with LT's default number of sample points which is 262144. This will all make more sense as we progress and run the simulation.

So, we take our simulation run time which is 2.5ms and we divide that by 262144. The result, 0.00953674us is the value we enter for our "Maximum Timestep".

I've mentioned before there's no point in calculating precise t_max_step size for FFT - the solver takes as small and as oddly sized steps as necessary to meet the other accuracy settings
this means the raw is a string of varying time steps and Spice has to interpolate to an exact sampling interval for FFT
so really all you need is at least 2x the time resolution and you're fine - so I use even 1, 2, 5, 100... ns to us depending - but never actually calculate out multiple digits of precision

but you risk missing lots of issues if you don't run at time steps smaller than the fastest device 1/ft
once I see those working stably I might increase max step size for faster sims but still use >10 the resolution needed for the fft size

modern machines are ridiculously fast
 
Administrator
Joined 2007
Paid Member
Measuring AC voltages.

Now would probably be a good time to recap and clarify a few points because hopefully we have covered quite a lot of ground in these last few posts.

If you can go back to the basic circuit and set it up for a 4kHz sine input of 0.1 volts amplitude and also set the <transient> tab for a stop time of 5ms. Leave the "maximum timestep" box blank.

An non deliberate error has crept in to the screen shots of post #16 (AC Analysis)... anyone spotted it ? ... but we are going to replicate that error now in order to show how to gather useful information from the various traces. I say an error, it was actually me taking a screen shot of the frequency response (the AC Analysis) using the 2N3055 I asked you to revert back to use the 2N2222.

So can you now make sure you have the 2N3055 selected as the device to use. Set the <AC Analysis> tab for a "decade sweep", "ten points" per decade and start and stop frequencies of 1 and 1meg respectively. Click OK to bring the tab into focus on the diagram.





Now run the simulation and you should see the response like this.





What would be the -3db or the 10db points ? You can estimate just by looking at the graph but we'll go one better than that.

If you right click the trace label at the top (the V(vout) text) a window opens. Select 1st and 2nd from the drop down menu and click OK.





You should see this.





Now drag (by left clicking the vertical cursor lines) along the trace. The values relating to each are displayed in the window at the lower right. So by moving the cursor to midband and noting the level you can then move up or down the trace to find where for example the -3 or -10 db points might be. The midband gain is around 18.7db and so the -3 db point is at 15.7 db. You can see that here with the overlaying cursors. The window gives the frequency and amplitude of each cursor.





Now go back to the diagram and alter the simulation to run the <transient> sim and run it. Probe output and input voltages.





If you now hold the "CTRL" key and left click either of the two trace labels you will see the RMS voltages and other information displayed.





Remember how the source voltage settings in LT are peak voltages. We have it set to 0.1 volts which displays as a trace of -/+0.1 volts.

And the RMS value is Vpk/root 2 which is 0.07 volts RMS.

We can also use cursors on the waveform just as we did in the AC Analysis. You can either left click the trace label of interest and attach a single cursor or right click the label and attach more than one cursor. Again, all the relevant information opens in a new window.



 
Administrator
Joined 2007
Paid Member
I've mentioned before there's no point in calculating precise t_max_step size for FFT - the solver takes as small and as oddly sized steps as necessary to meet the other accuracy settings
this means the raw is a string of varying time steps and Spice has to interpolate to an exact sampling interval for FFT
so really all you need is at least 2x the time resolution and you're fine - so I use even 1, 2, 5, 100... ns to us depending - but never actually calculate out multiple digits of precision

but you risk missing lots of issues if you don't run at time steps smaller than the fastest device 1/ft
once I see those working stably I might increase max step size for faster sims but still use >10 the resolution needed for the fft size

modern machines are ridiculously fast

Thanks :)

That's something I would have to study and try (I don't doubt for a moment what you say :)) but I have found with LT that a blow by blow account is needed for newbies (like me :D)

I'll admit, I don't quite understand how you mean to enter that and the numbers you might use in relation to this example.

(And if anyone wants to post screen shots or anything then please do so :))
 
Administrator
Joined 2007
Paid Member
Setting up multiple signal sources and running two simulations in parallel.

Please explain the sine(0 1 1000 0 0 0 10) and similarly for pulse and others.
How do we supply two signals?
Can we change from one signal type to another and back again?
Can we gate a sine ON and OFF? and start at different parts of the waveform eg max +ve voltage, max -ve voltage, or zero voltage or some other?
same for a stream of pulses that needs repeating?

And a big Thank You !!!!

Lets have a look now at some more of the questions Andrew raised. The first we have covered, the second, changing from one signal to another......

What I tend to do for that is this. I set up the required inputs, say a sine at 1v and 1kHz, a sine at 10kHz and perhaps a squarewve as three separate voltage sources. I then use the scissors to cut and connect just the required source.



One neat trick with LT is that we can copy a circuit and run it in parallel to the original. Suppose we are optimising some aspect of a design, squarewave response for example. This is one way to do it.

Open the sim and set it all up for the appropriate simulation to run. Now zoom out the circuit to make it smaller.



Now click the "Move" symbol.



Place the hand at the top left of the circuit such that you can drag a box around all the circuit and commands because that is what will happen when you left click. You will find you can place a box around all the circuit and its commands. Make sure you cover everything (or that bit will get left behind). Drag the circuit to the left of the screen and drop it down with a left click.



Now use the <copy> tool and again draw around the circuit and drag a copy over to the right and then drop it down on the workspace.



As it now stands the circuit won't run because there are duplicated commands and voltage sources. So it needs a quick tidy. Actually, its just the now paralled Vin tags that are the problem. We can cut them out, or relabel them. I've relabeled them as Vin1 and Vin2 and also relabeled Vout in a similar fashion. You could also run both circuits from one source and one supply. Remember to use the "zoom to fit" option to centre it all on the screen again (right click workspace). I've now altered the right hand circuit, changed a resistor and added a cap to make them perform very differently.

Now run the <transient> simulation and you can probe both circuits... great if you examining minor changes, one vs another.



So there is huge potential with that trick.
 

Attachments

  • Two Sources.PNG
    Two Sources.PNG
    41.4 KB · Views: 294
  • Zoom Out.PNG
    Zoom Out.PNG
    29 KB · Views: 254
  • Move.PNG
    Move.PNG
    13.3 KB · Views: 271
  • Copy.png
    Copy.png
    123.7 KB · Views: 280
  • Copied run.PNG
    Copied run.PNG
    58.5 KB · Views: 300
Administrator
Joined 2007
Paid Member
Using the <move> and <copy> commands actually allows you to detach just part of a circuit. So if you had a complete amplifier in simulation you could if you wanted detach say just the output stage and drag another into its place.

A very useful command.