Catto / Topic Map · Computing for Electronics II Year 5
Computing for Electronics II · 120 h · Topic 5 of 5

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.

CAD and design SPICE Analysis Error margins

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.

What goes in and what comes out
  • 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.

.op · operating point 5 V R 10k C 10n V = 5.000 V one number per node, the circuit at rest .tran · in time 63% τ = RC = 100 µs the complete evolution .ac · in frequency cutoff at 1592 Hz the response across the band The same R-C circuit: three different questions, three different analyses.
Figure 1. Three analyses of the same R-C circuit, animated. The operating point gives a number; the transient, the evolution in time; the frequency analysis, the response across the whole band. They are three different questions about the same circuit.
AnalysisQuestion it answersTypical 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 / tolerancesWhat 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.
The analysis almost nobody runs and you always should

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.

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

Generic model

The “NPN transistor” that comes with the program. It serves to understand a concept, not to predict the behavior of a specific circuit.

Ideal model

Perfect source, ideal op amp, switch with no resistance. Useful for isolating an idea; dangerous if you forget you are using it.

What models do not include
  • 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

simulated: perfect edge measured: overshoot, ringing and rise time overshoot The difference is not a simulator error: it is wiring inductance and capacitance the model lacked. Comparing the two curves is the part of the work where you really learn.
Figure 2. The same signal, simulated and measured, animated. In the simulator the edge is perfect; on the board there is overshoot, ringing and a finite rise time. Neither of the two is “wrong”: they describe different circuits, because the real one includes elements the model did not have.
Observed differenceWhere it comes from
The oscillator frequency does not matchTolerance of R and C, and parasitic capacitances of the board and of the oscilloscope probe.
The edge has overshoot and ringingWiring inductance resonating with the input capacitance. It was not in the model.
The real gain is lowerThe 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 notFeedback through the shared power supply or through coupling between traces: decoupling is missing.
It heats up more than expectedThe simulation did not take temperature and its effects on the parameters into account.
The regulator goes into oscillationThe ESR of the real output capacitor is outside the range the IC requires. In the model, the capacitor was ideal.
The right method
  1. Calculate first, even if only approximately. Whoever does not know what to expect cannot tell that the simulation is wrong.
  2. Simulate to verify the calculation, view waveforms and explore variants.
  3. Prototype and measure with real instruments.
  4. 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.

Convergence problems

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 .ic or uic with judgment.

05Tools and virtual measurements

ProgramStrengthNote
LTspiceFull SPICE, free, fast and widely usedExcellent for switching power supplies and analog work. Spartan interface, but it is the free standard.
FalstadBrowser-based simulator, with the current animated over the circuitUnbeatable for seeing what happens; it does not replace a serious SPICE.
ProteusSimulates the circuit with the microcontroller running the programWidely used in technical education: it lets you test the firmware before having the board.
MultisimVirtual instruments very similar to real onesGood for practicing measurements; paid license.
Qucs-S / NgspiceFree, with a SPICE engineOpen, cross-platform alternatives.
Virtual instruments are ideal, and that is misleading

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.

Error margins: how to report a simulated result

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

Lab 1 · The three analyses on an R-C circuit

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.

Lab 2 · Simulated versus measured

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.

Lab 3 · Tolerances

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.

Lab 4 · Provoke a convergence failure

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.

Lab 5 · Compare with the published results

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

SymptomUsual cause
“Singular matrix” or failed analysisThe ground node is missing, or there is a node with no DC path to ground.
The transient takes foreverTime 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 boardParasitics are missing: wiring inductance, decoupling, source resistance.
The simulated gain does not match the measured oneGeneric model instead of the manufacturer’s model.
The frequency curve comes out flat and meaninglessAn .ac analysis was run without a declared AC signal source, or with the circuit improperly biased.
Everything works in simulation on the first tryA reason for suspicion: almost certainly something ideal is being simulated. Review the models.
The result changes a lot when the time step is changedThe 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.

Development of the topic “Circuit simulation and virtual measurements” of Computing for Electronics II (Year 5), based on the “Curriculum Proposal – Second Cycle of the Technical-Vocational Track, Secondary Education – Electronics,” Ministry of Education of the Province of Córdoba, DGETyFP. Back to the Topic Map · catto.ar