# LTspice: Generating Triangular & Sawtooth Waveforms

Mar 16th 2016

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 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.

### PWL Function

For any arbritrary 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.

## Software

### LTspice

LTspice^{®} software is a powerful, fast and free simulation tool, schematic capture and waveform viewer with enhancements and models for improving the simulation of switching regulators. Click here to download LTspice

To launch a ready to run LTspice demonstration circuit for this part:

**Step 1:**If you have not installed LTspice on this computer, download and install LTspice**Step 2:**Once LTspice is installed, click on the link(s) below to launch the simulation

**Step 3:**If LTspice does not automatically open after clicking the link above, you can instead run the simulation by right clicking on the link and selecting "Save Target As." After saving the file to your computer, start LTspice and open the demonstration circuit by selecting 'Open' from the 'File' menu

To explore other ready to run LTspice demonstration circuits, please visit our Demo Circuits Collection.

### View More LTspice Solutions

**View All** - List View