Spice things to remember.
I have invented my own representation of syntax which I feel if easier to understand than the usual one with parentheses, braces, and brackets. Each item in the line is represented by a capitol letter of the alphabet. Below is a list in which each letter is followed by a verbal explanation of the item.Syntax of a Netlist Line.
A B1 B2 B3 etc. C ; D
- This is the ComponentCode consisting of one letter followed by a number. No embedded spaces.
A few of the commonly used letters are listed below.
C--capacitor. 23 of the letters of the alphabet are actually used. I have cut the list down to the ones you are most likely to need. Note: Don't try to memorize the above list. You will come to know the ones you use most often. These are likely to be capacitor, diode, inductor, resistor, and voltage source. The others you can look up as you need them. The complete list of all 23 component codes will be given at the end of this file.
D--Diode.
I--Current source.
J--JFET.
K--Coupled Inductors.
L--Inductor.
M--MOSFET.
Q--BJT.
R--Resistor.
V--Voltage source.
X--Sub Circuit. X may be followed by another letter such as U for a vacuum tube.
Z--MESFET.- The list of nodes is as long as it needs to be for the particular component. For simple parts such as resistors, capacitors, and inductors the list is 2 nodes long and the order doesn't matter except for polarized capacitors where the order is positive, negative. For diodes the order does matter and it is anode cathode. For voltage and current sources the order is positive, negative. For bipolar transistors you would think that it should be three nodes but it is actually 4 to accommodate some transistors that do have 4 leads. The order is collector, base, emitter, and shield which is grounded except for npn4 in which the fourth lead is the cathode of a diode whose cathode is connected to the collector. All four versions of the MOSFET have 4 leads but in two of them the substraight is internally connected to the source. In the other two it is brought out to the fourth lead. The order is drain, gate, source, substraight, or no connection. JFETs and MESFETS have only three leads and the order is drain, gate, source.
- Value. For capacitors, resistors and inductors, the value is what you would expect, the number of farads, ohms, or henrys. For semiconductor devices the value is the type number such as 1N4148 or 2N3904. Numeric values may be followed by a multiplier character. These are f for femto, p for pico, n for nano, u for micro, m for milli, k for kilo, meg for mega, G for giga, and T for terra. In standard physics notation a lower case m is used for milli and an upper case M is used for mega. However, spice is not case sensitive. As you see it makes the distinction by m for milli and meg for mega. Additional letters to represent units are optional. F for farads, h for henrys, Hz for hertz, s for seconds etc. There doesn't seem to be a way to insert the omega symbol for ohms. +
- A comment must begin with a semicolon. They are optional but you should always include them. You may be tempted to leave out a comment because the only thing you can think of is obvious. Something that seems obvious today may not be so a year from now. Always put in comments. You will never regret putting in too many comments. On the other hand it is highly likely that you will live to regret not putting in enough comments.
Syntax of most often used spice directives. Including Necessary Generator Settings.
Frequency Response.
.ac A B C D
Spaces are used as the delimiters between parameters. That is why spaces cannot be embedded within a parameter. For example 1MegHz must never be written as 1 Meg Hz. Note: You can enter more than 3 frequencies in a list. You can type them in the syntax box at the bottom of the dialog. The limit is 500 characters but there is a practical limit imposed by the length of the spice directive line.
- The four types of sweep are Octave, Decade, Linear, and List.
- The Octave is a logarithmic sweep in which each cycle is an octave (2 to 1 frequency range). This one is most often used to plot the response of band pass filters. To get the complete picture of the behavior of such a filter the frequency response is often plotted from half of the center frequency to twice the center frequency of the filter. It might also be used by a designer of electronic musical instruments in which the octave of musical notes is an integral part of the performance of the device.
- The Decade sweep should be familiar to anyone who has ever plotted a graph on semi log graph paper. This is the common way of plotting the frequency response of an audio amplifier or any of its subsystems such as tone controls. The plot is logarithmic and each cycle covers a 10 to 1 frequency range. It is often seen in reviews of audio equipment and on rare occasions in manufacturer's data.
- The linear frequency plot is often how electronic neophytes try to plot frequency response. They quickly learn that it fails to give a clear picture of how the circuit behaves across its working frequency spectrum. There are occasions where it may be used for a plot of a narrow band filter which has a relatively high center frequency. For example the response of a 2 kHz wide filter which has a center frequency of 9 MHz.
- The list is useful in which an amplifier must have specific values of gain at specific frequencies. A spice directive is limited to 500 characters so the list can have as many frequencies as you can squeeze into this limit. However, there is a practical limit imposed by how many characters you can tolerate on the screen.
- Number of points. This is the number of points in an octave or decade for those kinds of sweeps. For a linear sweep it is the total number of points in the sweep. For a list this box is relabeled 1st frequency and is exactly that.
- This is the start, lowest, frequency of the frequency plot for Octave, Decade, and Linear. For a list it is labeled 2nd frequency and it is the second item in the list.
- this is the stop, highest, frequency for Octave, Decade, and linear sweeps. When list is selected it is the third frequency in the list.
Generator Settings.
The generator must be set to 1 volt AC. This is 1 volt peak. It shows on the screen as "AC 1".To set this,
- Right click on the generator.
- Click the advanced button.
- Press the tab key until you hear "function sine". If you hear "function none" you are already in the right place so skip the next step and continue pressing the tab key.
- Press the up arrow twice and you will hear "none".
- Press tab some more until you hear "small signal AC analysis.".
- The cursor will be in the AC amplitude box.
- Type the number 1 and press enter.
- The voltage source will now be labeled AC 1.
Transient Response and Distortion.
.tran A B C
- The Start Time is not prompted for in the dialog box but it can be set to a nonzero value in the syntax box. It is the time in seconds at which the simulation starts.
- Stop Time is the time in seconds when the simulation ends.
- Start Saving Data is the time when data begins to be saved for display. This is used when it is desired to allow startup transients to decay in order to see steady state values.
.four A B
Example .four 1kHz V(out)The Fourier directive is how spice calculates total harmonic distortion. It must be used in conjunction with the ".tran" directive and a sine wave generator. The Frequency parameter in the .four directive must be the same as that of the generator. Both are active on the screen at the same time. The results are found in the Spice Error Log which may be opened through the View menu.. It is a good idea to name the output node of the circuit "out".
- Frequency.
- Output Node Name.
Generator settings.
SINE(A B C D E F G)
- DC Offset is a DC voltage that is added to the sine wave.
- Peak Volts is the peak, not RMS, voltage of the wave.
- Frequency is the number of cycles per second.
- Start Time Delay delays the start of the wave by the specified time in seconds.
- Time Constant. If this parameter is set to a nonzero value the wave will decay exponentially.
- Phase shift of the sine wave.
- Number of Cycles Generated. If entered as zero or omitted, generator runs for duration of simulation.
PULSE(A B C D E F G H)
- Low Level (Volts).
- High Level (Volts).
- Delay. Time before wave starts. (Seconds).
- Rise Time (Seconds).
- Fall Time (Seconds).
- Length of time pulse is high. Half the period for a square wave (Seconds).
- Period. 1/frequency (Seconds).
- Number of Cycles Generated. If entered as zero or omitted, generator runs for duration of simulation.
EXP(A B C D E F)
Value E MUST be larger than value C. If D = E - C and D=0, an interesting wave results. This wave cannot be made to repeat. It only happens once per simulation.
- Low Level (Volts).
- High Level (Volts).
- Rise Delay. Time at which wave starts rising. (Seconds).
- Time Constant of Rise (Seconds).
- Fall Delay. Time at which wave begins to fall. (Seconds).
- Time Constant of fall (Seconds).
The rises and falls are of the form f(x) = 1 - e- Τ x.SFFM(A B C D E). Frequency Modulation.
If you want to be able to see the frequency modulation, don't set the carrier frequency so high relative to the simulation time that you can't resolve individual cycles in the graph window.
- DC Offset. (Volts).
- Peak Amplitude. (Volts).
- Carrier Frequency, (Hertz).
- Modulation Index. This quantity is Deviation / Signal Frequency.
- Signal Frequency, (Hertz).
Two More Functions.
The remaining two functions are both called PWL. I don't know what the PW stands for but I'm pretty sure that the L stands for list. The first one prompts for a list of coordinates that describe a function. The second one prompts for the name of a file that contains the list of coordinates. Either way it sounds like a hard way to make a living.
Stepping and Sweeping.
The distinction between stepping and sweeping is a fine one. Because the computer is digital so is the program. So strictly speaking everything is stepping. When the steps become "small enough" a stepped value turns into a swept value. I am not going to make any attempt to define "small enough". When the difference is obvious I will use "stepping" and "sweeping" appropriately. For the middle gray area, all bets are off.Stepping Passive Component Values.
The passive component you want to step must be properly labeled. In place of the value it must have a name which is enclosed in braces. For example {R1}. This can be the same as the component designator but it doesn't have to be. You could use anything including your girlfriend's initials if you wanted to.This directive has 3 different syntaxes depending on which nature of sweep is selected. A separate line will be given for each one along with an example.
Linear.
.step param A B C D
Example.step param R2 1 10001 2k Note that the word "Linear" does not appear in the syntax.
- Component name Without the braces.
- Start Value.
- End Value.
- Increment, added to previous value.
Octave and Decade.
.step A param B C D
Example.
.step oct param R2 1k 32k 1
- Type or nature of sweep.
- Component name Without the braces.
- Start Value.
- End Value.
- Number of points per, Octave or Decade.
When a similar syntax was used for graphing frequency response you used a large number of points to get a smooth curve. But this is stepping the value of a component. The simulation is run once for each step. You don't want to sit around while the simulation runs 200 times and the graph window gets colored in solidly with overlapping lines. In the example, 1k to 32k covers 5 octaves. That is about the maximum number of curves you would want on a graph. So the final value is 1 per octave. When using a decade step you might want 2 or 3 points per decade but certainly no more.
List.
.step param A B C1 C2 etc.
Example.
.step param R2 list 2.5k 6.67k 15k 40k
- Component name Without the braces.
- Type or nature of sweep.
- Items in list separated by spaces.
Sweeping Voltage and Current Sources.
You can use ".step" to step or sweep a voltage or current source but it must be done in conjunction with another directive such as ".ac" or ".tran". The ".DC" directive can stand alone on the schematic or in the netlist to cause a source to step or sweep.Linear.
.dc A B C D Example.
.dc V1 0 500 1
- Source to be swept.
- Start Value.
- Stop Value.
- Increment.
Octave and Decade.
.dc A B C D E
Example.
.dc dec V1 5 500 400
- Type or nature of sweep.
- Source to be swept.
- Start value.
- End value.
- Number of points per Octave or Decade.
List.
.dc A B C1 C2 etc.
Example.
.dc V1 list 100 250 350
- Source to be stepped.
- Type or nature of sweep.
- Items in list separated by spaces.
Here is a complete list of the component codes.
When they appear as the first character in a netlist line
they tell spice what component is being entered in that line.
- A Special Function.
- B Arbitrary Signal Source.
- C Capacitor.
- D Diode.
- E Voltage Controlled Voltage Source.
- F Current Controlled Current Source.
- G Current Controlled Voltage Source.
- H Voltage Controlled Current Source.
- I Current source.
- J JFET.
- K Coupled Inductors.
- L Inductor.
- M MOSFET.
- O Transmission Line with Loss.
- Q BJT.
- R Resistor.
- S Voltage Controlled Switch.
- T Transmission Line without Loss.
- U Line with RC Uniform Distribution.
- V Voltage source.
- W Current Controlled Switch.
- X Sub Circuit. X may be followed by another letter such as U for a vacuum tube.
- Z MESFET.
This page last updated March 10, 2020. Home.
Since I don't know where you came from to get here,
I can't give you a link that will send you back.
Use the Back Button in your Browser to Go Back.