- 1 Why, and what (not) to expect here
- 2 Real docs
- 3 Examples
- 3.1 Piece-wise linear: voltage-source with V/t-curve consisting of line segments
- 3.2 AC (frequency-) analysis of a simple low-pass filter
- 3.3 Initial conditions: giving a component an initial value
- 3.4 DC-sweep: ramp a (voltage-)source from start- to end-value
- 3.5 Current-measurement using a dummy voltage-source (0V)
- 3.6 Pulsed source using nonzero rise- and fall-times
- 3.7 Physical pushbutton switch using helper voltage-source
- 3.8 Voltage-controlled voltage-source as sad excuse for opamp-model
Why, and what (not) to expect here
I heard a lot about SPICE, and never used it outside of one of its many fuzzy packages, e.g. PSpice. Googling by accident showed that SPICE-models representing simple circuits can be extremely short, so let's try.
- If you spot an obvious mistake, please tell or change this page.
- My goal here was clearly to simulate small and isolated parts of circuits using mainly passive components; a simple setup can be hacked together and simulated, well, within tens of seconds, really.
- A lot of funny plots are about to greet your eyes. SPICE can do a lot more than all this. For example, subcircuits and actual component-models are not shown, since that's where I draw the line - I'll use a graphical front-end for that.
- I use the ngspice incarnation on a NetBSD system, plotting directly to my monitor. I have not actually tested these examples on other SPICE3-incarnations.
- No redundant text - learn by example, please, or RTFM (see below).
I don't like the original SPICE3 docs; I guess everything is explained, but it feels incoherent and IMHO it could have been twice as long without being too long.
Original user's manual
- (an) original SPICE3 User's Manual
- The Spice Page, with clickable version of the official user's manual
- ...and another clickable version, elsewhere
- 2007 SPICE docs by Michael Steer for the fREEDA multi-physics simulator
- a recent ngspice manual (version 22plus)
Tutorials and introductions
- very nice and short walkthrough of simulation of a circuit
- SPICE - A Brief Tutorial; didn't read this one yet
- SPICE Simulation Fundamentals, didn't read this myself yet
- short SPICE devices and statements reference sheet
- a lot of SPICE models/subcircuits for existing components
- ngspice official site
To 'run' these examples, copy-paste the given text to a file, then issue "ngspice the_file_name", assuming you are using ngspice. And out will come a plot (or more plots) to the screen.
Piece-wise linear: voltage-source with V/t-curve consisting of line segments
AC (frequency-) analysis of a simple low-pass filter
Initial conditions: giving a component an initial value
transient analysis: discharging a cap with initial condition *** The cap has an (I)nitial (C)ondition of 1V r a 0 1k c a 0 1u ic=1 *** Simulate first 10 ms in steps of 10 us, and (U)se initial conditions .control tran 10u 10m uic plot a .endc .end
DC-sweep: ramp a (voltage-)source from start- to end-value
DC-analysis: sweep on voltage source *** No need to specify voltage source properties since we'll do that in simulation v a 0 r1 a b 1k r2 b 0 2k *** Sweep voltage source from 1 V to 3 V in steps of 0.1 V .control dc v 1 3 .1 plot a b .endc .end
Current-measurement using a dummy voltage-source (0V)
transient analysis: current-measurement using 0V voltage source *** Dummy (0 V) voltage-source 'vsense' between resistor and cap v a 0 dc 1 r a b 1k vsense b c dc 0 c c 0 1u *** Show current through dummy voltage source, and (effectively) cap voltage * * CAVEAT: 'uic' _must_ be added, else cap behaves as open circuit .control tran 10u 10m uic plot i( vsense ) plot b .endc .end
Pulsed source using nonzero rise- and fall-times
Voltage-controlled voltage-source as sad excuse for opamp-model
Have fun -- Michai