An Introduction to Switched DC Analysis With LTspice IV University of Evansville July 27, 2009 In addition to LTspice IV, this tutorial assumes that you have installed the University of Evansville Simulation Library for LTspice IV. This library extends LTspice IV by adding symbols and models that make it easier for students with no previous SPICE experience to get started with LTspice IV. A Switched DC Circuit The use of LTspice IV in simulating RLC circuits with DC sources will be demonstrated using the example circuit shown in Figure 1. t=0 5Ω i 20 V + – t=0 + v – 0.2 F 10 Ω 3A Figure 1 We want to find the voltage v across the capacitor and the current i through the 5 Ω resistor for t > 0. We need to find the capacitor voltage just prior to t = 0 when both switches close. As far as the capacitor is concerned, prior to t = 0, the circuit appears as shown in Figure 2. 5Ω i 20 V + – + v – 0.2 F Figure 2 The circuit is simple enough in this case that we can easily see that v = 20 V prior to t = 0. We can verify this using LTspice IV and DC Operating Point analysis. The result is shown in Figure 3 where the initial capacitor voltage is seen to be 20 V. (The cursor is hovering over node N002 which is the node between the resistor and the capacitor. The voltage at node N002 (relative to the ground node) is displayed in the information bar at the bottom of the window.) After t = 0 the circuit appears as shown in Figure 4. Figure 5 shows the corresponding LTspice IV schematic. In order to get correct simulation results we need to specify the correct initial voltage across the capacitor. There are several ways to do this, but the easiest method is to just add “IC=20” (IC stands for Initial Condition) after the capacitor value as shown in Figure 6. (Just right-click on the capacitor or the capacitor value to add the IC text. Make sure to leave a space between the capacitor value and the IC.) It is important to get the polarity of the initial voltage correct. The assumed positive terminal of the capacitor has a small triangle near the corresponding terminal of the schematic symbol. Rotate the capacitor, if necessary, so that the triangle terminal is at the top. We need to do a Transient Analysis to plot the voltage and current versus time. After setting up the circuit as shown in Figure 5, select Edit Simulation Cmd from the Simulation menu. The Edit Simulation Command dialog window shown in 1 of 8 Figure 6 will then appear. There are a large number of options in this window and they must be set correctly in order to get correct results. We want to simulate out to 5-10 time constants so that we can see the capacitor voltage settle down to its final value. The time constant for the circuit in Figure 5 is 2/3 s. In Figure 6 the Stop Time has been set to 6 s which corresponds to 9 time constants. The Time to Start Saving Data and the Maximum Time Step are left blank and they will assume their default values. It is important that the Skip Initial operating point solution selection box be checked. If it is unchecked LTspice IV will be another DC operating point analysis before starting the simulation. We do not want a DC operating point analysis now, we want to start the simulation with an initial capacitor voltage of 20 V. Checking the box will cause the text “uic” (use initial conditions) to appear as part of the “.tran” command. Click on the OK button and you will be returned to the schematic where the resulting simulation command can be placed on the schematic. Figure 3: Dynamic DC Analysis (prior to t = 0) 5Ω i + v – 0.2 F 10 Ω 3A Figure 4: Circuit After t = 0 Displaying Circuit Voltages and Currents Now start the simulation by clicking on the Start Simulation icon in the toolbar or by selecting Run from the Simulate menu. A new graph window should appear above the schematic window. You can now click on nodes in the schematic window and the corresponding node voltage will be plotted in the graph window. As you move the screen cursor over a node the cursor will change shape to a scope probe as shown in Figure 7. This indicates that the voltage at that node is available for display in the graph. If the cursor is moved over a component the cursor will change shape to a current probe. This is shown in Figure 8. Notice that the current probe includes an arrow indicating the positive direction of current. 2 of 8 Figure 5: Circuit Schematic for t > 0 Figure 6: Setting the Initial Capacitor Voltage Figure 9 shows the graph of the voltage across the capacitor (the voltage v in the original circuit) and the left-to-right current through resistor R1 (the current i in the original circuit). The graph shows that the capacitor voltage is initially 20 V and settles to 10 V in about 3.6 s (five time constants corresponds to 3.33 s). The current trace starts at -4 A and ends at -2 A. The traces are easier to distinguish in the actual window than in this tutorial because the traces are shown in different colors in the window. The horizontal axis has units of time while the left axis is in Volts and the right axis in Amperes. You can 3 of 8 right-click on the plot background and select Add Plot Pane from the menu that appears. You can then choose to plot voltages in one pane and currents in the other one. This is illustrated in Figure 10. You can have multiple plot panes and plot multiple voltages and currents in each pane. Left-click on a plot pane to select it as the active plot pane. Figure 7: Probing Node Voltages Figure 8: Probing Component Currents 4 of 8 Instead of probing the schematic, you can alternatively add a trace by right-clicking on the background of a plot pane and selecting Add Trace from the menu that appears. The dialog window shown in Figure 11 should then appear (only a portion of the dialog window is shown). You can choose to plot any of the traces listed or to plot mathematical functions (differences between voltages and currents for example) of the traces. The expression shown in Figure 11 is the theoretical expression for the voltage across the capacitor. (The ability to plot theoretical expressions along-side simulation results is is one of the very nice features of LTspice IV.) The results are shown in Figure 12. (The theoretical and simulated voltage graphs overlap and so can not be distinguished in the graph.) Adding units (in this case a voltage unit of V) to the numbers in the theoretical expression, as shown in Figure 11, ensures that the expression is plotted against the existing voltage vertical axis. Figure 9: The Capacitor Voltage and Resistor Current Figure 10: The Capacitor Voltage and Resistor Current in Different Plot Panes Figure 11: A Portion of the Add Traces Dialog Window 5 of 8 Figure 12: Theoretical and Simulated Results on the Same Graph A Second Order Circuit Example A second order circuit problem is shown in Figure 13. The switch has been in position a for a long time. It is switched to position b at time t = 0. The problem is to find v and vR for t > 0. The initial capacitor voltage (v(0)) is equal to 8 V. (This is easy to determine by direct analysis, you could also verify the value using a DC Operating Point analysis.) A theoretical analysis indicates that the system is underdamped and the desired voltages are: −2 t v t = 10−1.1547sin 3.464 t2 cos3.464t e v R t = 2.31e− 2t sin 3.464 t V V We want to use LTspice IV to verify our theoretical solutions. 1Ω + 12 V – b 2.5 H a 2Ω 1 F 40 t=0 + v – Figure 13: A Second Order Circuit The corresponding LTspice IV schematic is shown in Figure 14. 6 of 8 10 Ω – vR + 10 V + – Figure 14: LTspice IV Schematic Corresponding to Figure 13 Figure 15 shows the simulation results. The theoretical expressions are plotted in the same plot pane as the simulation results. The graphs overlap, verifying that the theoretical expressions are correct. Figure 15: Simulation Results Stepping Component Values LTspice IV allows you to change a parameter value through a range or list of values and automatically run the simulation for each value of the parameter. Probing a circuit will then display the traces for all possible parameter values. This is demonstrated in Figure 16 where the value of resistor R1 in the original circuit in Figure 1 has been changed to {R1}. (When referencing a parameter the parameter name must be enclosed in curly braces.) The SPICE Directive entry on the Edit menu has been used to add a SPICE step command to the schematic. In this case the parameter R1 is given the values 5, 10, and 15 respectively. Simulation results are shown in Figure 17 where three traces are now shown for both the capacitor voltage and the R1 current. The different traces correspond to difference R1 resistance values. 7 of 8 Figure 16: Theoretical and Simulated Results on the Same Graph Figure 17: Comparing Simulation Results for Different Values of R1 Tips 1. Refer to the LTspice IV online help for additional information on the Waveform Viewer (zooming, waveform arithmetic, axis control, plot panes, attached cursors) and on the SPICE step command (see the Dot Commands section of the LTSpice book in the online documentation. 2. You can change the default color scheme used by the Waveform Viewer from the LTspice IV control panel. Click on the the Waveforms tab and then on the Color Scheme button. A white background works best when cutting and pasting waveforms into word processor documents. 3. The data points from the Waveform Viewer can be exported to a file and then to a spreadsheet program (or other scientific graphing program) if so desired. When the Waveform Viewer is the active window, just select Export from the File menu. The data file will have the same basename as the circuit schematic file, but with a “.txt” extension. 8 of 8