Difference between revisions of "SPICE3-hacking primer"
From Electriki
Jump to navigationJump to search(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | == | + | __NOEDITSECTION__ |
+ | [[category:support]] | ||
+ | |||
+ | [[File:Spice3girls.jpg|frame|the original Spice developers]] | ||
+ | |||
+ | == 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. | 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. | 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 == | == Real docs == | ||
Line 14: | Line 19: | ||
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. | 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 === | |
− | - | + | |
− | - | + | * [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] | |
− | + | ||
+ | === Not-so-official 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 === | ||
+ | |||
+ | * [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 === | ||
+ | |||
+ | * [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 == | ||
+ | |||
+ | 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 === | === Piece-wise linear: voltage-source with V/t-curve consisting of line segments === | ||
Line 33: | Line 56: | ||
*** Voltage source shows different ramps using 'pwl()' | *** Voltage source shows different ramps using 'pwl()' | ||
* | * | ||
− | * Parms are | + | * Parms are tuples ( t, V ); i.o.w. at time 't', voltage is 'V'. |
* Intermediate points are calculated using linear interpolation. | * Intermediate points are calculated using linear interpolation. | ||
Line 50: | Line 73: | ||
</pre> | </pre> | ||
|} | |} | ||
− | |||
− | |||
=== AC (frequency-) analysis of a simple low-pass filter === | === AC (frequency-) analysis of a simple low-pass filter === | ||
Line 87: | Line 108: | ||
transient analysis: discharging a cap with initial condition | transient analysis: discharging a cap with initial condition | ||
− | *** The cap has an (I)nitial (C)ondition of 1V | + | *** The cap has an (I)nitial (C)ondition of 1V |
− | + | r a 0 1k | |
− | + | c a 0 1u ic=1 | |
− | c | ||
*** Simulate first 10 ms in steps of 10 us, and (U)se initial conditions | *** Simulate first 10 ms in steps of 10 us, and (U)se initial conditions | ||
Line 97: | Line 117: | ||
.control | .control | ||
tran 10u 10m uic | tran 10u 10m uic | ||
− | plot | + | plot a |
.endc | .endc | ||
Line 219: | Line 239: | ||
{| | {| | ||
− | |[[Image:8_vcvs.png]] | + | |[[Image:8_vcvs.png]] Ok, admittedly this is a very boring graph; shown is the VCVS output-voltage, being exactly at 0.5 V. The voltage at 'b' is not plotted, but since no extra load on the 1:1 voltage-divider is created, it would also be at 0.5 V. |
| | | | ||
<pre> | <pre> | ||
Line 246: | Line 266: | ||
</pre> | </pre> | ||
|} | |} | ||
+ | |||
+ | ---- | ||
+ | |||
+ | Have fun -- [[User:Michai|Michai]] |
Latest revision as of 18:23, 9 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
- (an) original SPICE3 User's Manual
- The Spice Page, with clickable version of the official user's manual
- ...and another clickable version, elsewhere
Not-so-official documentation
- 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
Miscellaneous stuff
- short SPICE devices and statements reference sheet
- a lot of SPICE models/subcircuits for existing components
- ngspice 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