LTspice - Transient Analysis

Article:  Andy Collinson
Email :

Please Note: All the information presented here is my own work and not from Linear Technology. This advice does not replace the information given by Linear Technology, the LTWiki or the LTspice User group. Please also read my sites general disclaimer.
Sections:
DC Transient
Initial Conditions
Maximum Timestep
Using Cursors
Cursor Zoom
AC Transient
Calculating Phase Difference
Calculating Phase Difference using Cursor
Using Measure tp Convert Units
Using Parameters
Maths and LTspice
Retrieving Measure Results
Plotting Current
Plotting Power
Add Trace
Parallel Tuned Circuit
Add New Plot Pane

Transient Analysis
Transient analysis allows you to view signals in the time domain. This mode of analysis is very similar to viewing a waveform on an oscilloscope. You must know something about the signal to set-up the correct parameters for a transient analysis.

Basic DC Transient Charging a Capacitor
DC capacitor charge

Start LTspice and select New Schematic from the File Menu. Components can be selected in two ways. Either from the edit menu, or by pressing F2. The F2 key will give access to all the components in LTSpice, frequently used parts like the resistor,capacitor, inductor and ground symbol can be selected from the top menu line.
In this circuit the DC voltage source is set to 10 Vdc. See the previous page on Drawing the Schematic if you have trouble. When power is applied to a capacitor the voltage will rise exponentially and this is a good curve to view in LTSpice. In order to view this curve you need to know two commands, the transient command and the initial condition command. An explanation of these two commands now follows.


Transient Command
Like the measure command, the transient command starts with a period, "." then the work "tran" followed by a series of time constants, the start time, stop time and maximum time step. The maximum time step can be calculated bt LTSpice itself, or to speed up long simulations, you can manually enter a value. The full format for the command is then:

.tran start time | stop time | max timestep

To enter the transient command you can go simulation menu and click on edit simulation command. You will see the following dialogue box (shown left). Click on the transient tab, then enter a stop time of 50m and a start time of 0. Click on "Ok" then the simulation command can be placed on the schematic.

The Maximum Timestep
The maximum timestep option has been left out. In many cases LTSpice is clever enough to predict this value itself, but entering a value can speed up calculations. For every point on the graph a calculation is performed, and when sufficient points have been calculated, a graph can be drawn.

How did we arrive at the figure 50 milliseconds? Remember in the first paragraph I said you need to know something about the signal. Well a capacitor has a time constant of RC, you multiply the value of the resistor and capacitor and this gives you one time constant, or the time it takes for a capacitor to reach 63% of its charge. After 5 time constants it reaches 99% of its charge. So with values chosen 5RC = 25ms Now I've used double this time constant to show the state after 10RC constants, which will be shown on the graph, however, first we need to use another command called .ic This command sets the initial conditions of a node.

Introducing Initial Condition Command.
The initial conditions command ".ic", is used to define the voltage of a particular node when a simulation is run. By default LTSpice assumes all captivators have a full charge.. If the circuit is run without .ic being set then the capacitor would not charge because the default simulation behaves this way. The command takes the form:

.ic | node id or number = initial voltage

The command can be entered from the edit menu and selecting SPICE Directive or a shortcut is to press "S" on the keyboard. The node that needs to defined is the junction of the resistor and capacitor, this is node N002 and node ids can be found by hovering the mouse cursor over the wire and reading the node on the bottom status bar. This has been described on the previous article on DC Analysis, click here to read.
The node needs to be set to 0 Volts so after pressing S enter ".ic V(N002=0, this is shown below:

Running the Simulation
transient capacitor charge To run the simulation click on the running man icon or press the appropriate hot key if you remapped this function. The transient analysis is run and the voltage calculated over the time range defined by the transient command. The voltage on the capacitor rises from zero at an exponential rate defined as:

V = Vs [ 1 - e-t/RC]

Where Vs is the power supply voltage, e is Euler's constant (2.71828), t the time in seconds, R resistance in ohms and C capacitance value in Farads.
The product of R and C or RC is also called the time constant. In one time constant 1RC or just RC a capacitor, charges to 63.2* of its full charge, and in 5 time constants or 5RC it reaches 99.3% of full charge. I will now demonstrate this using the graph cursors.

Graph Measurement Using Cursors
Using the cursors, you can measure, time, amplitude of any particular point on the graph. With two cursors, you can measure displacement, phase difference and calculate the slope, maximum and minimum values, impedance measurement, rise and fall times and more. To display the cursors, right click over the id of the waveform , in this case V(n002) and then left click on 1st and 2nd. See below

Moving the mouse over the cross-hairs you will see a yellow "1" and yellow "2" appear. Hold your left mouse button down and drag left or right to change the values. The cursor popup window displays the difference between cursor 1 and cursor 2, see screenshot below.

Cursor Zoom
To "fine-tune" or home in on a value on the graph, press and hold the left mouse button down, while still pressing move to draw a rectangle, see below.

Release the mouse button and a much more detailed view is shown is displayed. As shown below it is much easier to get the first cursor to exactly 5ms.

cursor zoom on LTspice

To zoom out, right click the graph and the option zoom to fit will displayed.

This can take a few attempts, but with zooming in and out you can arrive at the precise point or very close to it.

The final zoomed values shown above show the cursors place at 5 ms (one time constant) and at 5 time constants, 25 ms. With a 10 Volt supply voltage you can see the capacitor has charged to 6.32 Volts or 63.2% After 5 RC the voltage has reached 99.3%

AC Transient
The AC signal source can be found in components, press F2, then [MISC], then choose the part called 'signal'. The symbol contains a sinusoidal wave and a right click will bring up this components properties shown below:

The box highlighted in red allows you to set waveform type, this can be sine, pulse, exponential, SFFM (single frequency FM), or FM or PWL, (piece wise linear). Many different waveforms can be emulated with these options.

The selection highlighted in blue is where you set up the waveform parameters. The main ones for a sine wave are DC offset, frequency and amplitude. The amplitude is the peak value measured from zero to the positive peak, if you enter 1 for 1V peak, then there will also be a negative 1V peak so the peak to peak value is 2 Volts. For a desired peak to peak value, simply half the peak value. So if you wanted a 10 Vpk-pk waveform you would enter 5 in the amplitude. Tdelay is the time delay in seconds. The default is set to zero for normal sinusoidal waves. Theta is the damping factor. A damping factor applies an exponential decay to the sinusoidal wave, theta is the decay constant in 1/seconds. PHI is the phase advance in degrees. This is set at zero for a sine wave, but if you a cosine wave set PHI to 90 degrees. Finally Ncycles is the number of cycles if a pulse waveform is chosen.

The yellow selection box highlights options for small signal AC analysis. The lower box adds series resistance or parallel capacitance to the signal source. The signal source in LTSpice is ideal, it has zero ohms resistance and zero capacitance. A signal generator in the real world always contains series resistance and capacitance, and for some experiments, entering values here can more closely approximate a real signal source.

AC Transient Analysis for Series RC Circuit
In the circuit above, the signal source is set at 5 Volts peak and 1Khz. It is connected to a simple EC circuit and the node junction of the resistor and capacitor is labelled Vc. As the frequency is 1kHz, one complete waveform takes 1ms. The transient command is set to end at 3 ms and after the simulation is run the waveforms are displayed for the signal generator (blue trace) and the voltage across the capacitor (green trace). You can see that there is a phase difference between the waveforms.

Calculating the Phase Difference of RC Circuits
It is often necessary to know the phase difference between waveforms and you can calculate it manually, using the cursors or using the measure command in LTSpice, see below.

Manual Calculation
In the series RC circuit the reactance of the capacitor, Xc is calculated then the impedance Z. You can find the calculations on the AC theory page. The series AC current is V/Z and the voltage across the capacitor is then IZ. The phase difference is then arctan Xc/R. As the Voltage source is 5 volts peak, the voltage across the capacitor will be in peak volts, the frequency is 1kHz, R = 1.5k and C =100n the calculation is:

XC = 1 / 2πfC = 1 / 2π x 1000 x 100 x 10-9 = 1591.54 Ohms Z = √ R2 + Xc2 = √15002 + 1591.542 = 2187.04 Ohms
Series Current, I = V/Z = 5/2187.04 = 0.0022 Amp
Voltage across capacitor Vc = IXc = .002286 x 1591.54 = 3.638 Vp
The phase angle across the capacitor is:
tan-1 θ = Xc/R = tan-1 1591.54 / 1500 = 46.69 °

Graphical Method Using Cursors
Using the cursors method, both cursors are enabled and the time difference between the capacitor voltage and the supply voltage is measured at the points where both curves pass through the zero volts. This is done on the last cycle, as waveforms take time to stabilise. You can zoom in on the axis as mentioned in cursors section to get very close to zero volts axis.

The time difference between the horizontal cursors is shown in the right hand box and is 120.2 micro-seconds. To get phase difference in degrees, multiply by 360. See also AC theory page. The phase difference is:
Phase φ = 360 * f * Δt = 360 * 1000 * 0.00001202 = 43.27°

Error Between Manual and Cursor Measurement
The cursor measurement has a greater accuracy than the calculated method. The differnce of 46.69 and 43.27 degrees in percent is:

Error % = (46.69 43.27)/ 43.27) = 7.9 %

Using Measure to Convert to RMS Values
The transient waveform in LTspice shows the full peak to peak waveform, the same as an oscilloscope. A digital multi-meter will generally measure AC quantities of voltage and current as RMS values. It would be useful to extract the RMS value using the measure statement. The measure function can directly convert units to RMS, PP (peak to peak) and AVG values. To begin type 's' on the keyboard and type a blank .meas statement. Place on the schematic then right click to bring up the Measure Statement Editor, see below: To measure the voltage across the capacitor as an RMS value, enter a unique Result id, I called it VCRMS, then click on the drop-down menu in genre. This has many options including AVG, PP, MAX, MIN and RMS. Select RMS and enter 'V' followed by node number or node id, in the this node is called 'vc'. Click OK and place the statement on the schematic. The full measure statement is completed in the last field of the statement editor and for clarity is shown below:

.meas VCrms RMS V(vc))
Using the same method I have added measure statements to measure the input voltage as RMS, the current through the resistor and capacitor (the current in AC series circuits is the same magnitude but phase value is different for reactive components.) Then I have used the parameter statement to measure reactance and impedance, see below.

The Parameter Statement .param
Whilst we are measuring RMS values, LTspice has many built in mathematical functions. The .param statement can be used as a variable to store values. As a demonstration we'll use it to calculate the reactive capacitance and impedance of the circuit. The parameter format is:

.param id = VALUE

To store the value 2πf or omega you can press s and then enter w=6283.4 Similarly a right click will display an edit window where you can enter values, as shown left.

Measure Using Parameter Statements
Once a parameter has been defined, for example, w=6283.4, the idd parameter (w) can be used for other formulas and in measurements. As the capacitive reactance Xc = 1/2πfC and the value for 2πf has aleady been assigned then we can calculate Xc using the measure statement for Xc = 1/wC below. The result id has been called Xc, see screenshot below:

Maths and LTspice
LTspice contains many builtin mathematical functions, including integration and derivatives (INTEG and DERIV) and as well as addition, subtraction, multiplication and division, trigonometr, logs, powers and square roots are also possible. The format takes the form :

function id (arg1,arg2)

Function id is the command, followed by either a single argument e.g. sin(30) or a double argument e.g. pow(x,2) The pow(x,2) would square the value of parameter x, (x must have been already defined). To use this to work out the circuit impedance:

Z = √ R2 + Xc2)

To calculate this using the measure statement, the square root statement sqrt() and power function power(x,y) are used. The power statement is used to square the Xc parameter, because 'y' is set to 2. Xc has already been calculated using previously defined .param statements. You can see from this example just how powerful the measure statements can be. The full measure statement is shown below:

Retrieving Measure Statements.
Download Example Code Once run the measure statements are automatically calculated and can be displayed using the View menu, option View SPICE Error Log. In earlier LTspice versions you could use shortcut 'alt+L' but in LTspice XVII you need to use the view menu. Results are just text and are shown below:

.OP point found by inspection.
seriesii: RMS(i(r1))=0.00155088 FROM 0 TO 0.003
v1rms: RMS(v(n001))=3.53547 FROM 0 TO 0.003
vcrms: RMS(v(vc))=2.60263 FROM 0 TO 0.003
iv1: RMS(i(v1))=0.00155088 FROM 0 TO 0.003
vpp: PP(v(n001))=9.99934 FROM 0 TO 0.003
vc: PP(v(vc)/2)=3.74761 FROM 0 TO 0.003
xc: 1/(w*0.0000001)=1591.55
ic: RMS(i(c1))=0.00155088 FROM 0 TO 0.003
z: sqrt(pow(1500,2)+pow(xc,2))=2187.01

Looking at the results, the second line 'seriesii' calculates the RMS current through resistor R1. With no internal specified this is calculated over the entire transient period 0 to 3 ms and is 0.00155A or 1.55mA. The RMS current through capacitor C1 label id 'ic' also has the same value, as does 'iv1' the current from the power supply. The current in an series ac circuit is the same at all points, although the phase will change in the capacitor. The supply voltage is 5V peak and the peak voltage at the capacitor, label 'vc' is 3.74 Volts. Converting to RMS you will find that 'v1rms' is 3.53 VRMS and thee voltage across the capacitor 'vcrms' is 2.60 VRMS. These are the values you would read on a digital multi meter. The value for 'xc' has also been calculated at 1591.55 ohms and the impedance 'z' of the circuits 2187.01 ohms. These are the same as a manual calculation, except this time all the calculations have been performed by measure statements.

You can download example 1 below. The fileis called AC_basic1.asc It should open directly with LTspice. The schematic files are ASCII yexy and some browsers may display the file as lines of text. If this happens to you, then try a right click and use option "save link as" which should allow you to save the file complete. N.B. If you are a windows user extensions (the letters after the .asc) may not be displayed. The file should still run though.

Download the example here.

Plotting Transient Current

As well as voltage, transient current and power can also be graphed. Once the simulation has run, move the mouse cursor near to the component whose current you want to plot. In this example, its the current flowing through C1. The cursor changes to a current clamp (see left) with a red arrow pointing in the current direction. A left click will graph the peak to peak current and the vertical axis changes to units of milliamps.

Multiple graphs can be plotted, the supply current I(V1) shown in purple and I(C1) shown in red can be seen on the right. Note the phase shift of current in the capacitor is different to the supply.

Plotting Power

To plot power, first make sure that the graph window is active. As shown above, the active window will have a blue title bar (or whatever colour scheme is set for an active window). If not active, left click anywhere in the active window, then right click. This beings up a menu and select 'add trace'. A shortcut is to press "ctrl+A" whilst the graph window is active.

Add Trace
The add trace editor can be seen right. The list of available data can be selected and you can create a plot using any built in math function of LTspice. In this case to graph the power developed in C1, the voltage across the capacitor us selected then multiplied by the current flowing through it.

The final graph is shown below with a dual plot of capacitor current and capacitor power.

AC Parallel Tuned Circuit
The final AC transient analysis is for a parallel tuned LC circuit with series resistance. At resonance the current in the inductor and capacitor and in phase and the impedance of the tuned circuit becomes a maximum. It is also known as the dynamic impedance and is given by:

Z = L / CR
Where L is the inductance in Henri-es, C is the capacitance in Farads and R is the ohmic resistance of the inductor. In the example below the inductor has a series resistance of 5 ohms. To add internal series resistance to an inductor, right click over the symbol on the schematic. The values of 200uH and 126.64pF are resonant at 1 MHz. At 1 MHz, 1 cycle is completed every microsecond so the transient command will simulate over 3 cycles or 3 us, circuit is shown below:

Add New Plot Pane

After running the simulation, the voltage across the tank circuit is plotted and also the supply current. Once the circuit has stabilised, after after 1.5 us the current in the inductor and capacitor will be in phase, i.e. have 0° phase difference. To plot these on the same graph becomes convoluted, so we will add another plot plane.

To add another plot plane, right click over the graph and the menu shown left will be displayed. You can add as many plot planes as you need. Once a new plot plane has been added, the horizontal axis aligns with the base axis time. To add a plot in the new plot window just right click and select add trace. The list of variables will be shown and the process is the same as the previous add trace section.

The final graph is shown below. For added finesse you can add, text and arrows to the graph again by right clicking and selecting add text or the draw sub menu.

The example circuit again uses measure statements and parameters to calculate the current in the supply and the impedance of the parallel circuit. The example can be downloaded here.

Top of Page

Return to LTspice