SPICE Simulation Tutorial: How to Use Circuit Simulation
SPICE (Simulation Program with Integrated Circuit Emphasis) is the standard for circuit simulation. It lets you test a circuit design on your computer before building it physically -- saving time, components, and potentially expensive mistakes. This tutorial covers what SPICE simulation is, the three main analysis types, and how to use browser-based SPICE simulation in CircuitDiagramMaker.
What Is SPICE Simulation?
SPICE was developed at the University of California, Berkeley in the 1970s and has become the universal standard for analog circuit simulation. It solves the mathematical equations that describe circuit behavior -- Kirchhoff's laws, Ohm's law, and semiconductor device models -- numerically.
What SPICE Can Do
- Calculate voltages and currents at every node in a circuit
- Simulate circuits with resistors, capacitors, inductors, diodes, transistors, and op-amps
- Perform DC analysis (steady-state), transient analysis (time-domain), and AC analysis (frequency response)
- Generate waveforms, Bode plots, and voltage/current overlays
- Test circuit behavior before building -- catch design errors early
What SPICE Cannot Do
- Simulate mechanical or thermal effects (it is purely electrical)
- Replace physical testing entirely (real components have tolerances and parasitic effects)
- Design the circuit for you (you design it; SPICE verifies it)
- Simulate digital logic in detail (SPICE is primarily for analog circuits)
The Three Main Analysis Types
1. DC Operating Point Analysis
DC analysis finds the steady-state voltages and currents in a circuit with all capacitors fully charged and all inductors carrying constant current. It answers: "What are the voltages and currents right now, after everything has settled?"
When to use DC analysis:
- Verify bias points in transistor circuits
- Check voltage divider outputs
- Verify power supply output voltage
- Confirm current draw from a battery
- Set up initial conditions for transient analysis
Example: Voltage Divider
A simple voltage divider with a 12V source, R1 = 10k ohms, R2 = 5k ohms:
- Expected output: 12V x 5k / (10k + 5k) = 4V
- DC analysis confirms: V_out = 4.000V
- Current: 12V / 15k = 0.8mA
This seems trivial for a voltage divider, but DC analysis becomes essential for complex circuits with multiple sources, nonlinear devices, and feedback loops.
2. Transient Analysis (Time-Domain)
Transient analysis simulates the circuit over time, showing how voltages and currents change from moment to moment. It answers: "What happens when I turn this circuit on, apply a signal, or change a load?"
When to use transient analysis:
- Simulate RC and RLC circuits (charging, oscillation, damping)
- Test filter response to step or pulse inputs
- Verify timing circuits (555 timers, multivibrators)
- Analyze switching power supply behavior
- View PWM waveforms and motor control signals
- Observe transient startup behavior
Key settings:
- Start time: Usually 0 seconds
- Stop time: How long to simulate (e.g., 10ms, 1s)
- Time step: Resolution of the simulation (e.g., 1us). Smaller steps = more accuracy but slower simulation
Example: RC Circuit Charging
A 10 microfarad capacitor charging through a 1k-ohm resistor from a 5V source:
- Time constant (tau) = R x C = 1k x 10uF = 10ms
- At 1 tau (10ms): Capacitor reaches 63.2% of 5V = 3.16V
- At 5 tau (50ms): Capacitor is essentially fully charged (4.97V)
Transient analysis plots the voltage versus time curve, showing the exponential charging characteristic.
3. AC Analysis (Frequency Sweep)
AC analysis sweeps a range of frequencies and calculates the circuit's gain (magnitude) and phase shift at each frequency. The results are typically displayed as Bode plots. It answers: "How does this circuit respond to different frequencies?"
When to use AC analysis:
- Design and verify filters (low-pass, high-pass, band-pass, notch)
- Measure amplifier bandwidth and gain
- Analyze resonant circuits
- Check power supply output impedance vs frequency
- Determine stability margins in feedback circuits
Key settings:
- Start frequency: e.g., 1 Hz
- Stop frequency: e.g., 1 MHz
- Sweep type: Usually logarithmic (decade)
- Points per decade: Typically 20-100 for smooth curves
Example: Low-Pass RC Filter
A simple RC low-pass filter with R = 1k ohms, C = 100nF:
- Cutoff frequency: f_c = 1 / (2 x pi x R x C) = 1.59 kHz
- Below f_c: Signal passes with near-unity gain
- At f_c: Gain is -3dB (0.707 of input)
- Above f_c: Gain rolls off at -20dB/decade
The Bode plot from AC analysis visually confirms the filter's frequency response.
Step-by-Step SPICE Tutorial
Step 1: Draw the Circuit
Start by drawing your circuit schematic. Place components, set their values, and connect them with wires. Every circuit needs:
- At least one source (voltage source, current source, or signal source)
- A ground reference (every circuit needs a ground node -- node 0)
- Component values set correctly (resistance in ohms, capacitance in farads, etc.)
Step 2: Set Component Values
SPICE uses standard engineering notation:
| Suffix | Multiplier | Example |
|---|---|---|
| T | 10^12 | 1T = 1 tera |
| G | 10^9 | 1G = 1 giga |
| Meg | 10^6 | 1Meg = 1 mega |
| k | 10^3 | 10k = 10,000 |
| m | 10^-3 | 100m = 0.1 |
| u | 10^-6 | 10u = 10 micro |
| n | 10^-9 | 100n = 100 nano |
| p | 10^-12 | 22p = 22 pico |
Step 3: Choose Your Analysis Type
Based on what you want to learn about the circuit:
- DC analysis: For steady-state voltages and currents
- Transient analysis: For time-domain behavior (charging, oscillation, switching)
- AC analysis: For frequency response (filters, amplifiers)
Step 4: Run the Simulation
Click the simulate button. The SPICE engine:
- Builds the circuit matrix (nodes and branches)
- Solves the equations iteratively (Newton-Raphson for nonlinear circuits)
- Generates results for each node and branch
Step 5: View Results
Results are displayed as:
- Voltage/current values overlaid on the schematic (DC analysis)
- Waveform plots in the oscilloscope-style viewer (transient analysis)
- Bode plots showing magnitude and phase (AC analysis)
Step 6: Iterate
If the results are not what you expected:
- Check component values and connections
- Verify the ground reference is connected
- Adjust component values and re-simulate
- Compare simulation results to hand calculations
Common SPICE Components
Passive Components
- Resistor (R): Value in ohms. Example: R1 = 10k
- Capacitor (C): Value in farads. Example: C1 = 100n (100 nanofarads)
- Inductor (L): Value in henries. Example: L1 = 10m (10 millihenries)
Sources
- DC voltage source (V): Constant voltage. Example: V1 = 12V
- DC current source (I): Constant current. Example: I1 = 10mA
- Sine wave source: AC signal with frequency, amplitude, offset
- Pulse source: Square wave or pulse with rise/fall times, period, duty cycle
- PWM source: Pulse-width modulated signal
Semiconductors
- Diode (D): Uses device models (1N4148, 1N5819, LED)
- NPN transistor (Q): Uses models (2N2222, 2N3904, BC547)
- PNP transistor (Q): Uses models (2N2907, 2N3906, BC557)
- N-MOSFET (M): Uses models (IRF540, 2N7000)
- P-MOSFET (M): Uses models (IRF9540)
- Op-amp: Ideal or specific model (LM741, LM358)
Practical Simulation Examples
Example 1: LED Current-Limiting Resistor
Verify the correct resistor value for an LED:
- Supply: 9V battery
- LED forward voltage: 2V (red LED)
- Desired current: 20mA
- Calculated R = (9V - 2V) / 20mA = 350 ohms, use 330 ohm standard value
DC simulation confirms: LED current = 21.2mA (acceptable)
Example 2: 555 Timer Astable
Simulate a 555 timer generating a 1 kHz square wave:
- Transient analysis over 5ms shows the output toggling
- Verify the frequency matches the calculated value
- Observe the capacitor charging/discharging waveform
Example 3: Audio Amplifier Frequency Response
Test a common-emitter amplifier's bandwidth:
- AC analysis from 20 Hz to 20 kHz
- Bode plot shows the midband gain and -3dB cutoff frequencies
- Verify the amplifier covers the audio band
Example 4: Power Supply Ripple
Simulate a full-wave rectifier with filter capacitor:
- Transient analysis shows the ripple voltage
- Increase the filter capacitor to reduce ripple
- Verify output voltage under load
Tips for Better Simulations
- Always add a ground node: Every SPICE circuit needs a ground reference (node 0). Missing ground causes convergence errors.
- Start simple: If a complex circuit fails to converge, simulate subsections separately first.
- Check component values: A missing decimal point (10 ohms vs 10k ohms) gives wildly wrong results.
- Use realistic models: Ideal op-amps work for basic checks, but real models reveal bandwidth limits and offset voltages.
- Watch for convergence errors: These usually mean a circuit condition that SPICE cannot solve (e.g., voltage source directly across a voltage source). Add small series resistance.
- Verify with hand calculations: Simulation should confirm your calculations, not replace them. If the results disagree, find out why.
SPICE Simulation in CircuitDiagramMaker
CircuitDiagramMaker includes a full SPICE simulation engine directly in the browser -- no separate software needed:
- Draw your circuit in the editor with drag-and-drop components
- Set component values by double-clicking each component
- Click Simulate and choose DC, transient, or AC analysis
- View results overlaid on the schematic or in the waveform viewer
- Iterate on the design without switching between applications
The AI circuit generator can create simulation-ready circuits -- describe your circuit and it generates a complete schematic with correct component values, ready to simulate.
Common SPICE Simulation Errors and How to Fix Them
Even correctly designed circuits can fail to simulate if the netlist has an issue SPICE cannot resolve numerically. These errors are not bugs in the simulator -- they mean the circuit as described does not have a well-defined solution, or the solver could not find one within its iteration limits.
| Error | Typical Cause | Fix |
|---|---|---|
| "No DC path to ground" / floating node | A node (often a capacitor-only branch or an unconnected component pin) has no resistive path to the ground reference | Add a large resistor (1M ohm or more) from the floating node to ground, or check for a missing wire |
| Convergence failure in DC or transient analysis | Two voltage sources connected directly in parallel, a voltage source directly across a capacitor, or aggressive nonlinear device models | Add a small series resistance (0.01-1 ohm) between conflicting sources; loosen convergence tolerances only as a last resort |
| Singular matrix error | A node has no connection at all, or a component value is set to zero (e.g., a 0-ohm resistor used where a wire was intended) | Check for unconnected pins; replace 0-ohm components with a small nonzero value or an actual wire |
| Simulation runs but results look wrong | Missing or incorrect ground node (node 0), wrong component value (decimal point or unit suffix error) | Confirm every circuit has one node designated as ground/reference; recheck component value suffixes (m vs Meg, u vs n) |
| Transient analysis "timestep too small" | The solver is struggling with a fast transition (sharp edge, switching event) and keeps shrinking the timestep | Set a maximum timestep manually, simplify very fast edges in source definitions, or add a touch of parasitic capacitance to soften transitions |
Every SPICE circuit needs exactly one node identified as ground (node 0), and every other node needs at least one DC-connected path back to it -- even circuits built entirely from capacitors and inductors, which have no DC resistance path unless you add one.
Setting Simulation Step Size and Initial Conditions
For transient analysis, the time step controls both accuracy and simulation speed. As a working rule, set the maximum time step to somewhere between 1/10 and 1/100 of the fastest time constant or signal period in the circuit. A circuit with a 10ms RC time constant simulated with a 5ms step will produce a jagged, inaccurate charging curve; the same circuit stepped at 0.1ms or smaller resolves the exponential curve clearly.
Circuits with feedback, multiple stable states, or oscillators that need a "kick" to start (astable multivibrators, ring oscillators, flip-flops) may settle into an unrealistic or symmetric state if simulated from a cold start with all nodes at 0V. Two tools handle this:
- Initial conditions (.IC): Manually set a starting voltage on a specific node (for example, forcing one side of a flip-flop high) so the simulation begins from a realistic or intentional state rather than a symmetric one.
- Use Initial Conditions (UIC): Tells the transient analysis to skip the DC operating point calculation and start directly from the initial conditions you specified, useful when the DC operating point itself would not converge or is not the state you want to observe.
Choosing the right device model also affects realism. An ideal op-amp model simulates fast and is fine for verifying gain and basic topology, but it will not show slew-rate limiting, input offset voltage, or bandwidth roll-off. A manufacturer's SPICE model (LM358, TL072, and similar) captures those real-world limits at the cost of a slower, more complex simulation.
Popular SPICE Simulators Compared
Several SPICE-based tools are in common use, each suited to different workflows:
| Simulator | Cost | Platform | Typical Use |
|---|---|---|---|
| LTspice | Free | Windows, macOS | General analog design, power supplies; large built-in model library from Analog Devices |
| ngspice | Free, open-source | Windows, macOS, Linux | Command-line and scriptable simulation; used as the simulation backend in some open-source EDA tools |
| PSpice | Commercial (free student edition) | Windows | Integrated with Cadence OrCAD schematic capture; common in university engineering curricula |
All three implement the same underlying SPICE analysis engine (DC, transient, AC) and read variations of the same netlist syntax, so a circuit built and understood in one tool transfers conceptually to the others -- the differences are mostly in the schematic editor, model libraries, and integration with other design software.
Conclusion
SPICE simulation is an invaluable tool for circuit design. It catches errors before you build, lets you experiment with component values instantly, and provides insight into circuit behavior that is difficult to measure physically. Start with simple circuits (voltage dividers, RC filters) to build confidence, then tackle more complex designs.
Simulate circuits in your browser with CircuitDiagramMaker -- the only online wiring diagram tool with built-in SPICE simulation (DC, transient, AC analysis).
Frequently asked questions
What is Monte Carlo analysis in SPICE, and when do I need it?
Monte Carlo analysis runs a simulation many times, randomly varying component values within their tolerance range each run, to see how manufacturing variation affects circuit performance. It's used when you need to know whether a design still works reliably with real-world component tolerances, not just with exact nominal values.
How long does a SPICE simulation typically take to run?
Simple circuits with a handful of components and a DC or basic transient analysis usually complete in under a second. Runtime grows with circuit complexity, the number of nonlinear devices (transistors, diodes), a long stop time paired with a small time step, and tight convergence requirements -- large circuits can take from several seconds to minutes.
Do I need to learn SPICE netlist syntax to use a graphical circuit simulator?
No. Graphical SPICE tools, including browser-based ones, generate the netlist automatically from the schematic you draw. Understanding basic netlist concepts (nodes, component references, the ground node) helps you interpret error messages, but you can build and run simulations entirely through the schematic editor without writing netlist code by hand.
Can SPICE simulate circuits with dual power supply rails, like +/-15V?
Yes. Dual-rail circuits are common in op-amp designs and are simulated by placing two DC voltage sources -- one for the positive rail, one for the negative rail -- both referenced to the same ground node. SPICE has no special mode for dual supplies; it simply solves both sources as part of the same circuit.
Does SPICE account for temperature effects on components?
SPICE device models include temperature-dependent parameters, and most simulators let you set a simulation temperature (default is typically 27°C/300K) or sweep across a temperature range. This affects semiconductor behavior noticeably -- diode forward voltage and transistor gain both shift with temperature -- but has little effect on ideal passive components.
Can I import a manufacturer's SPICE model for a specific real-world component?
Many SPICE tools support importing a manufacturer-supplied .MODEL or .SUBCKT file for a specific part number, letting you simulate with that exact component's characteristics instead of a generic device model. Availability depends on the simulator -- check whether your tool supports custom model or subcircuit import before relying on manufacturer-specific behavior.