Circuit simulation and virtual measurements
A simulator solves, for each instant, the Kirchhoff equations of the circuit. That is all it does, and it is a great deal: it lets you try twenty variants in one afternoon. But what it returns is not reality, but reality according to the models that were loaded into it.
01What a simulator does inside
All circuit simulators descend from SPICE, written at Berkeley in 1973. The procedure has not changed: a system of equations is set up with Kirchhoff’s laws, solved numerically to find the voltages at all the nodes, and the calculation is repeated for each point in time or frequency.
- In: the netlist —the same data as the schematic— plus a model for each component and a directive that says which analysis to run.
- Out: voltages and currents at each node, for each time or frequency point calculated.
- What does not go in: the length of the traces, the wiring capacitance, the real temperature, the tolerance of the components or the ambient noise. None of that exists for the simulator unless it is added by hand.
02Types of analysis
Choosing the right analysis is half the work. Each one answers a different question.
| Analysis | Question it answers | Typical example |
|---|---|---|
| Operating point (.op) | At what voltages and currents does the circuit settle at rest? | Checking the biasing of a transistor before looking at anything else. |
| DC sweep (.dc) | How does the output change if I sweep a source or a resistor? | Plotting the characteristic curve of a diode or a transistor. |
| Transient (.tran) | What happens over time? | Charging of a capacitor, start-up of an oscillator, waveform of a power supply. |
| Frequency (.ac) | How does it respond at each frequency? | Response curve of a filter, bandwidth of an amplifier. |
| Parametric (.step) | What happens if this component has a different value? | Sweeping R from 1 k to 100 k and viewing the ten overlaid curves. |
| Monte Carlo / tolerances | What happens with the real spread of component values? | Checking that the circuit works with 5% resistors and 20% capacitors. |
| Noise (.noise) | How much noise does it generate itself? | Design of the input stage of an instrument. |
Monte Carlo. A circuit that works with nominal values can fail in production, where each resistor sits at some random point within its tolerance. Simulating a hundred random combinations shows whether the design has margin or works “by luck.” It is the difference between a prototype that works and a product that works.
03Models: that is where everything is
A resistor is modeled with one number. A transistor, with more than twenty parameters. The quality of the simulation does not depend on the program: it depends on the model.
Published alongside the datasheet, fitted to real measurements. It is the one to look for every time: almost all serious manufacturers offer it for download.
The “NPN transistor” that comes with the program. It serves to understand a concept, not to predict the behavior of a specific circuit.
Perfect source, ideal op amp, switch with no resistance. Useful for isolating an idea; dangerous if you forget you are using it.
- The inductance of the leads and of the traces.
- The capacitance between traces and to the ground plane.
- The ESR of real capacitors, which increases with age (impedance measurements).
- Heating: the model usually calculates at a fixed 27 °C unless told otherwise.
- Coupling between stages through the shared power supply.
All of that has to be added by hand when it matters: a source model with its internal resistance, an inductance in series with each filter capacitor, a 0.1 Ω resistance representing the trace. A good simulation engineer is, above all, someone who knows which parasitics to add.
04Simulation versus reality
| Observed difference | Where it comes from |
|---|---|
| The oscillator frequency does not match | Tolerance of R and C, and parasitic capacitances of the board and of the oscilloscope probe. |
| The edge has overshoot and ringing | Wiring inductance resonating with the input capacitance. It was not in the model. |
| The real gain is lower | The generic model had a higher β than the real transistor, or the loading of the instrument has an effect. |
| The circuit oscillates and in the simulator it does not | Feedback through the shared power supply or through coupling between traces: decoupling is missing. |
| It heats up more than expected | The simulation did not take temperature and its effects on the parameters into account. |
| The regulator goes into oscillation | The ESR of the real output capacitor is outside the range the IC requires. In the model, the capacitor was ideal. |
- Calculate first, even if only approximately. Whoever does not know what to expect cannot tell that the simulation is wrong.
- Simulate to verify the calculation, view waveforms and explore variants.
- Prototype and measure with real instruments.
- Compare the three results. If they differ, there is something that was not understood, and that is the most valuable part of the learning.
A simulation result that nobody questioned is as unreliable as a measurement made with an uncalibrated instrument.
When the simulator reports “analysis failed” or “singular matrix,” it is almost always one of these causes, and none of them is the program’s fault:
- Missing ground node: SPICE needs a reference (node 0). It is the number one cause.
- A floating node, with no DC path to ground: it is resolved with a very large resistor, 1 MΩ or 1 GΩ.
- Inductors or voltage sources in an ideal closed loop, with no resistance: a small series resistor must be added.
- Perfectly vertical steps: give the sources a realistic rise time, even if only nanoseconds.
- Absurd initial conditions: use
.icoruicwith judgment.
05Tools and virtual measurements
| Program | Strength | Note |
|---|---|---|
| LTspice | Full SPICE, free, fast and widely used | Excellent for switching power supplies and analog work. Spartan interface, but it is the free standard. |
| Falstad | Browser-based simulator, with the current animated over the circuit | Unbeatable for seeing what happens; it does not replace a serious SPICE. |
| Proteus | Simulates the circuit with the microcontroller running the program | Widely used in technical education: it lets you test the firmware before having the board. |
| Multisim | Virtual instruments very similar to real ones | Good for practicing measurements; paid license. |
| Qucs-S / Ngspice | Free, with a SPICE engine | Open, cross-platform alternatives. |
The simulator’s oscilloscope has infinite bandwidth, infinite input impedance and does not load the circuit. The virtual multimeter is exact and has no burden voltage. Measuring in the simulator is, by definition, easier than measuring on the bench, and that is why lab practice cannot be replaced by simulation: what you learn by measuring is precisely how to deal with instruments that are not ideal, as seen in digital measuring instruments.
An honest simulation report states: which model was used for each active component, with what tolerances the analysis was run, at what temperature, and which parasitics were included. “The circuit gives 4.98 V” is not a result; “with 1% resistors and at 25 °C, the output lies between 4.92 and 5.04 V in 95% of cases” is.
06In the lab
With R = 10 kΩ and C = 10 nF: run the operating point, a transient with a square-wave input and a frequency sweep. Verify that the time constant is τ = RC = 100 µs, that the output reaches 63% in one τ, and that the cutoff in the sweep falls at 1592 Hz. The three results describe the same circuit.
Build that same R-C circuit on the bench and measure it with the generator and the oscilloscope. Overlay the two curves. Note the differences and look for the cause of each: capacitor tolerance, probe capacitance, generator output resistance.
Run a parametric analysis varying R ±5% and C ±20% and observe how far the cutoff frequency shifts. Compare with what is measured on three different units of the same circuit built by different classmates.
Deliberately build a circuit with no ground and check the error. Then leave a node floating and fix it with a 1 MΩ resistor. It is the quickest way to learn to diagnose the most frequent simulator problem.
Simulate the astable of the 555 with the same R and C as the site’s interactive simulator, and compare the three results: the formula, the SPICE simulation and the measurement on the built circuit. All three should agree within the tolerance of the components; if not, there is something to investigate.
07Common mistakes
| Symptom | Usual cause |
|---|---|
| “Singular matrix” or failed analysis | The ground node is missing, or there is a node with no DC path to ground. |
| The transient takes forever | Time step too small for the requested duration, or signals of very different frequencies in the same analysis. |
| The circuit simulates perfectly and oscillates on the board | Parasitics are missing: wiring inductance, decoupling, source resistance. |
| The simulated gain does not match the measured one | Generic model instead of the manufacturer’s model. |
| The frequency curve comes out flat and meaningless | An .ac analysis was run without a declared AC signal source, or with the circuit improperly biased. |
| Everything works in simulation on the first try | A reason for suspicion: almost certainly something ideal is being simulated. Review the models. |
| The result changes a lot when the time step is changed | The analysis did not really converge: adjust the tolerances and the maximum step. |
08Self-assessment
What exactly does a SPICE-type simulator solve?
The circuit’s Kirchhoff equations, numerically, for each point in time or frequency, using a mathematical model of each component.
Which analysis is used to obtain a filter’s response curve?
The frequency analysis (.ac): it sweeps the source frequency and plots the magnitude and phase of the output.
What is a Monte Carlo analysis for?
To see what happens with the real spread of component values: it runs many simulations with values drawn at random within their tolerances and shows the distribution of results. It is what distinguishes a design with margin from one that works by luck.
Why can a circuit simulate well and oscillate on the board?
Because on the board there are elements the model did not have: inductance and capacitance of the traces, impedance of the shared power supply, coupling between stages. The positive feedback that causes the oscillation was not in the simulated circuit.
What is the most common cause of an analysis failing to converge?
A missing ground node. SPICE needs a voltage reference; without it the system of equations has no unique solution.
Why is the generic model of a transistor not enough?
Because its parameters —gain, capacitances, saturation voltages— do not correspond to any real component. It serves to illustrate a concept, not to predict the behavior of the circuit you are going to build.
The simulator gives 4.98 V. Is that a sufficient result?
No. It must also state with which models, which tolerances, at what temperature and with which parasitics. A useful result is an interval with its conditions, not a single number.
What is the limitation of the simulator’s virtual oscilloscope?
That it is ideal: infinite bandwidth and impedance, no noise and no loading of the circuit. That is why it shows waveforms that no real instrument would see the same way, and why it does not replace measurement practice.
In what order should you work?
Calculate, simulate, prototype and measure; and then compare the three results. Each one checks the others: without a prior calculation there is no way to realize that the simulation is set up wrongly.
Which parasitics should be added by hand in a power supply simulation?
The ESR and ESL of the capacitors, the resistance and inductance of the traces, the internal resistance of the input source and the real switching time of the semiconductors. Without them, the simulated ripple and oscillations do not resemble the real ones.