Home | LTspice Tutorials | dc/dc Converter Design | Articles | C for the PIC | Contact


LTspice Tutorial: Part 5

This LTspice tutorial discusses some of the more advanced tricks in LTspice®.


The following topics are explained on this page:



Tricks with Piecewise Linear (PWL) Sources

Waveform Mathematics
Stepping through parameters


Rather than use the menu bar, the shortcuts in FIG1 are available to enable you to speed up schematic entry.




Tricks with Piecewise Linear (PWL) Sources

Piecewise Linear (PWL) sources enable the user to construct a waveform consisting of a series of straight lines. FIG 2 defines a voltage that starts at 0V, rises to 10V over 100ms, stays at 10V for the next 100ms then decays linearly over the next 100ms to 0V.




An alternative way of creating this PWL waveform is by defining each timing relative to the previous one. This makes it easier to move the waveform forward and backwards in time without having to recalculate all of the timings. FIG 3a and 3b shows how the above waveform is described using this technique.


FIG 3a



FIG 3b


If this is cumbersome to read on the schematic, an alternative way of describing the waveform is shown in FIG 4. This is simply constructed by right clicking over the schematic text describing the PWL source and editing it.



This file can be downloaded here: Piecewise Linear Test


The resultant waveform is shown in FIG 5




If you want to repeat the above waveform, LTspice allows you to edit the PWL text. To repeat the above waveform 5 times, right click over the PWL text and alter as shown in FIG 6.




Likewise, if you want the waveform to repeat forever, edit the PWL text according to FIG 7




LTspice also allows PWL waveforms to be read from a file. FIG 8 shows how to read the above waveform from a file called pwl_file.txt (and repeated 5 times) stored in the same directory as the schematic. The file format is shown in FIG 9. The first column specifies the time and the second specifies the voltage with the 2 columns separated by spaces or tabs.






Similarly, the line


PWL repeat forever (FILE=pwl_file.txt) endrepeat


repeats the PWL waveform forever.


Waveform Mathematics

The icon V(pwl) in FIG 4 can be edited if needed. Thus if you want to see what V(pwl) looks like when multiplied by 3, simply right click over the icon and edit it as shown in FIG 10


FIG 10


This results in the plot shown in FIG 11 where the voltage has been increased by a factor of 3.


FIG 11


Indeed LTspice also recognises the variables 'time' and 'pi' and these can be used to manipulate the waveform accordingly.


Stepping through parameters

It is possible to perform multiple back to back simulations with different component values. FIG 12 shows a simple non inverting amplifier.


FIG 12


By relabeling the feedback resistor value to 'R' (instead of, say, 10k) and putting it in curly brackets tells LTspice to treat the value as a variable. The .step command is then used to step R through different values. The .step command in this case steps the parameter R through the values 10k, 20k and 30k. Any number of parameters can be made into variables, however LTspice will run simulations on all the different combinations of each value. The above circuit applies a 100mV sinewave to an amplifier with gain of 2, 3 and 4.


The resulting waveform at the OUT pin is shown in FIG 13.


FIG 13


To determine which waveform corresponds to which value of R, left click on the V(out) icon to bring up the cursor, then use the UP and DOWN arrows on the keyboard to move the cursor from one waveform to another. Right clicking over the vertical cursor brings up a dialogue box indicating which value of R has been used, as shown in FIG 14.


FIG 14


Want to know more?

Please see LTspice Tutorial: Part 6


LTspice is a registered trademark of Linear Technology Corporation



Home | LTspice Tutorials | dc/dc Converter Design | Articles | C for the PIC | Contact

Send Mail to: webmaster@simonbramble.co.uk with questions about this site

sitemap: www.simonbramble.co.uk/sitemap.xml


© Copyright Simon Bramble