Difference between revisions of "SPICE3-hacking primer"
From Electriki
Jump to navigationJump to searchLine 1: | Line 1: | ||
__NOEDITSECTION__ | __NOEDITSECTION__ | ||
[[category:support]] | [[category:support]] | ||
+ | |||
+ | [[File:Spice3girls.jpg|frame|the original Spice developers]] | ||
== Why, and what (not) to expect here == | == Why, and what (not) to expect here == |
Revision as of 17:28, 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