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