Some of the most common waveforms needed in simulating voltage and current sources are sine, square, triangular and sawtooth shapes.
LTspice® simulation software has a built-in pulse, sine, exponential, single frequency FM and an arbitrary piece-wise linear functions available in the source component editor. Although it may not look like it, LTspice does have a triangular and sawtooth functions available but they need to be created from either a PULSE or PWL function.
PULSE fuction is often used in transient circuit simulation where we want the source to behave like a square wave. You can omit Ncycles if you need a free-running square waveform.
PULSE(Voff Von Tdelay Trise Tfall Ton Tperiod Ncycles)
A simple approach to creating a triangular and sawtooth waveform is using the PULSE fuction using the source component editor shown above. For the triangular waveform you can set the rise and fall time equal to 1/2 of your desired period in your pulse function. Likewise, to create a sawtooth fuction you cab set the rise time equal to the period and the fall time to zero. The PULSE function can be further modify to best match your simulation needs. Waveforms for these two fuctions are show on the top of the page.
For any arbitrary or complex waveform, you can always rely on the piece-wise linear function. The arbitrary piece-wise linear fuction is defined by a sequence of time and voltage pairs.
PWL(t1 v1 t2 v2 t3 v3...)
This specifies that for time before t1, the voltage is v1. For times between t1 and t2, the voltage varies linearly between v1 and v2. There can be any number of time, voltage points given and for times after the last time, the voltage is the last voltage.
To implement a triangular or sawtooth waveform you could use the following piece-wise linear functions. Waveforms for these two fuctions are show on the top of the page.
These two examples use an undocumented repeat feature of PWL function. To explore these features you will need to directly edit by right-clicking on the source symbol's text in the schematic editor rather than using the source component editor.
Here are some highlights of the undocumented features for the PWL fuction:
- Repeat date pairs forever
PWL REPEAT FOREVER (0 0 .5 1 1 0) ENDREPEAT
- Repeat data pairs for 5 cycles
PWL REPEAT 5 (0 0 .5 1 1 0) ENDREPEAT
- A trigger expression that turns the source on as long as the expression is true
PWL (0 0 .5 1 1 0) TRIGGER V(node)>1
- Scaled the time or source values
PWL TIME_SCALE_FACTOR=0.5 VALUE_SCALE_FACTOR=2 (0 0 .5 1 1 0)
More information on the pulse, sine, exponential, single frequency FM and an arbitrary piece-wise linear functions is available in the LTspice help file (F1). An example LTspice simulation is also provided below for your reference.