Difference between revisions of "SPICE3-hacking primer"
From Electriki
Jump to navigationJump to searchLine 19: | Line 19: | ||
=== Original user's manual === | === Original user's manual === | ||
− | * | + | * [http://www.thedigitalmachine.net/reference/Spice_3f3_Users_Manual.pdf|(an) original SPICE3 User's Manual] |
− | * | + | * [http://bwrc.eecs.berkeley.edu/Classes/IcBook/SPICE/|The Spice Page, with clickable version of the official user's manual] |
− | * | + | * [http://newton.ex.ac.uk/teaching/cdhw/Electronics2/userguide/|...and another clickable version, elsewhere] |
=== More-readable (IMHO) documentation === | === More-readable (IMHO) documentation === | ||
− | * | + | * [http://www.freeda.org/doc/SPICE/spice.pdf|2007 SPICE docs by Michael Steer for the fREEDA multi-physics simulator] |
− | * | + | * [http://ngspice.sourceforge.net/docs/ngspice-manual.pdf|a recent ngspice manual (version 22plus)] |
=== Tutorials and introductions === | === Tutorials and introductions === | ||
− | * | + | * [http://seit.unsw.adfa.edu.au/staff/sites/hrp/teaching/docs/spicetutorial.pdf|very nice and short walkthrough of simulation of a circuit] |
− | * | + | * [http://www.seas.upenn.edu/~jan/spice/spice.overview.html|SPICE - A Brief Tutorial; didn't read this one yet] |
− | * | + | * [http://zone.ni.com/devzone/cda/tut/p/id/5413| SPICE Simulation Fundamentals, didn't read this myself yet] |
=== Miscellaneous stuff === | === Miscellaneous stuff === | ||
− | * | + | * [http://www.ecircuitcenter.com/SPICEsummary.htm|short SPICE devices and statements reference sheet] |
− | * | + | * [http://www.emwonder.com/spicemodels|a lot of SPICE models/subcircuits for existing components] |
− | * | + | * [http://ngspice.sourceforge.net/|ngspice official site] |
== Examples == | == Examples == |
Revision as of 20:56, 8 April 2011
Contents
- 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).
Real docs
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
- original SPICE3 User's Manual
- Spice Page, with clickable version of the official user's manual
- another clickable version, elsewhere
More-readable (IMHO) documentation
- SPICE docs by Michael Steer for the fREEDA multi-physics simulator
- recent ngspice manual (version 22plus)
Tutorials and introductions
- nice and short walkthrough of simulation of a circuit
- - A Brief Tutorial; didn't read this one yet
- SPICE Simulation Fundamentals, didn't read this myself yet
Miscellaneous stuff
- SPICE devices and statements reference sheet
- lot of SPICE models/subcircuits for existing components
- official site
Examples
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
DC-sweep: ramp a (voltage-)source from start- to end-value
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
Physical pushbutton switch using helper voltage-source
Voltage-controlled voltage-source as sad excuse for opamp-model
Have fun -- Michai