LTSpice possesses several features that can be used to test your design beyond simple transient analysis and AC sweeps. This article will go over a few advanced functions.

Recommended Level



Parameter Sweeps: Varying Component Values with SPICE Directives

In the first article on LTSpice, one of the features explained showed how to sweep through a range of frequencies with an AC voltage. In some testing cases, however, you may find that you want to be able to quickly vary the value of a component, rather than the input signal. This first part will be an overview of how to do that. Let's start by building a 50MHz bandpass filter (if you built the filter in the first article it'll come in handy again).

As a short tangent to the tutorial, one of the nice features about LTSpice is that it contains a decent library of models for several well-known parts. You can see this by placing a part such as an NPN transistor, right-clicking on it and selecting "Pick New Transistor". You'll see a list of models for common parts that you can use. For this example, we'll use the 2N3904:


Once you've placed it, you'll want to build up a common-emitter amplifier configuration similar to the one below:


At this point we should probably run the simulation as-is to see how the circuit operates before the sweep. Above you may have noticed that my voltage source is on the "SINE" setting. Right-click the voltage source, hit "Advanced" and choose the SINE function. The fields are simple enough to interpret, but you'll only need to set DC offset, amplitude and frequency for now. A 0V DC, 1mV amplitude, 1kHz sine wave signal produces something like this:


You may find it helpful to stretch the plot by clicking on the horizontal axis and lowering the rightmost limit, or lowering the stop time; 100ms was more than necessary. Analyzing the peak voltages by attaching cursors (you'll probably need to zoom in), it seems we've obtained a gain around -1.8:


Now let's step through a few values of R1 and see how the output changes. This is done using the SPICE Directive feature. At the right end of the toolbar, there's a button labeled ".op". Click it (you can also press S) and you'll see a dialog box like the one in the image below. I've filled it out with some values, where R is the component to vary:



The .step directive will perform an analysis of the circuit for each component value in the list and show us the resulting traces on the same plot. Hit OK and place the directive on the schematic like you would your .tran or .ac command. We're not quite ready to perform this simulation, though - LTSpice still doesn't know where to apply the .step directive, and if you simulate now you'll probably see the same output from before. Change the value of R1 from "10k" to "{R}" to assign the directive. You can perform this general process up to three times simultaneously for a single circuit.

Go ahead and hit simulate. The next image shows the input in green, with the three output values plotted in blue. If you assign a cursor to the output and press the up/down arrow keys, you can move between traces and determine the relative values of each:

You can see from this example that the gain on our 10mV signal ranges from a little less than -1.8 to -6. The .step analysis certainly isn't limited to gain calculations; any source or passive component should work.


Piecewise Linear, Pulse and Other Waveforms

PWLs are the methods by which you create various waveforms with straight-line segments: you specify a list of voltages at times in chronological order to create most shapes you'd want to use. However, if you're looking for a true square wave, the PULSE waveform is usually the better option (just don't use it for frequency response tests, as it is effectively a time-domain signal for the purposes of the simulator). With the waveforms other than SINE and .ac sweeps, e.g. PULSE, you can run into issues with your waveform shape if you leave fields like Trise and Tfall empty, but small values will be fine. Below I've set the directive to PULSE(0 1 1ms 0.001m 0.001m 1ms 2ms) and run the signal through a voltage divider:



Limitations and Pitfalls

Like any software tool, LTSpice has limitations in capability that should be kept in mind when using it. While not a knock on the extensive options available to you with SPICE simulation, here are a couple of things to watch out for:

  • Op-amp and transistor models in particular can be touchy and may not perform exactly as expected. Their limitations change depending on the specific model and can range from input noise discrepancies to issues with convergence and simulation time (on older machines). Linear Technology actually released a reference many years ago that, if nothing else, will give you a general idea for the pitfalls involved.
  • With some designs it will be best to just get out the breadboard and build your circuit. Fine-tuning your sim can allow you to get a better idea for worst-case scenarios, but certainly isn't always going to show you how things will actually behave. The advantage of LTSpice is how fast you can set up a simulation and get an overview of general performance and other things to keep in mind. LTSpice does help with some nice features, adding things such as parasitic capacitances and reactances to individual components, but LTSpice isn't capable of modelling things happening in your lab environment. I find that if possible it's good to compare simulation results with the circuit's behavior when probed with an actual scope, because at a certain point adding extra parts and sources to your simulation to account for other factors will be less reliable than seeing how it actually works. As always, use your own best judgment.


Further Reading

Despite two articles, there's still a lot more information and capability out there for getting the most out of LTSpice, including defining subcircuit and part models, netlist exports, math functions and more. A full section of documentation is available under the "Help Topics" option in the Help menu, and is a great resource. In addition, there are many cool undocumented features for which you can find an overview at LTwiki (the entire site has a lot of information if you want more than the LTSpice Help Topics).