Last update: 2015-07-01
All examples shamelessly copied from the Ngspice Users Manual Version 26plus
Click on the links to toggle the visability of the item.
Elementary Devices
Possible attributes | |||
---|---|---|---|
device | : | RESISTOR | |
refdes | : | R? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:l, w and temp
Example:
Possible attributes | |||
---|---|---|---|
device | : | CAPACITOR | |
: | POLARIZED_CAPACITOR | ||
refdes | : | C? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:area, l, w and ic
Example:
Possible attributes | |||
---|---|---|---|
device | : | INDUCTOR | |
: | COIL | ||
refdes | : | L? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:l, w and ic
Example:
Possible attributes | |||
---|---|---|---|
device | : | K | |
refdes | : | K? | |
inductors | : | L? L? | |
value | : | 0.4 |
Example:
WYYYYYYY N+ N− VNAM MODEL <ON><OFF>
NGspice supports two different switches:
- Voltage controlled switch S? model sw
- Current controlled switch W? model csw
Currently only the voltage controlled switch is supported by the gnet_spice_sdb netlist script. TODO: summit a patch?
Unfortunately gnet_spice_sdb will not let us specify any attributes separately. So we can’t specify whether to switch is initially ON or OFF. TODO: submit a patch?
Possible attributes | |||
---|---|---|---|
device | : | SPICE-VC-switch | |
refdes | : | S? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL |
Example:
IYYYYYYY N+ N− <<DC> DC/TRAN VALUE> <AC <ACMAG <ACPHASE>>> <DISTOF1 <F1MAG <F1PHASE>>> <DISTOF2 <F2MAG <F2PHASE>>>
From the gnet_spice_sdb perspective this is easy. The device attribute is either a VOLTAGE_SOURCE or a CURRENT_SOURCE and the rest we specify in the value attribute.
Possible attributes | |||
---|---|---|---|
device | : | VOLTAGE_SOURCE | |
: | CURRENT_SOURCE | ||
refdes | : | V? | |
: | I? | ||
value | : | See list below | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL |
Possible options for the value attribute are:
- Pulse General SPICE form:
- Sinusoidal General SPICE form:
- Exponential General SPICE form:
- Piece-Wise Linear General SPICE form:
- Single-Frequency FM General SPICE form:
- Amplitude modulated source (AM) General SPICE form:
- Transient noise source General SPICE form:
- Random voltage source General SPICE form:
Example:
The gnet_spice_sdb netlist script will add additional "sense" or "measure" sources to make them work properly. As long as we stick to the predefined symbols, working with the linear dependent source is easy. If we need something special gnet_spice_sdb can't help us.
Gxxxx: Linear Voltage-Controlled Current Sources (VCCS)
gnet_spice_sdb will not let us specify any attributes separately, so if we need to specify m include it in the value attribute.
Example:
Exxxx: Linear Voltage-Controlled Voltage Sources (VCVS)
Example:
Fxxxx: Linear Current-Controlled Current Sources (CCCS)
Please note that the general form of a F source takes the name of a voltage source (VNAM) as a reference the gnet_spice_sdb script will generate that voltage source for us. gnet_spice_sdb will not let us specify any attributes separately, so if we need to specify m include it in the value attribute.
Example:
Hxxxx: Linear Current-Controlled Voltage Sources (CCVS)
Please note that the general form of a H source takes the name of a voltage source (vnam) as a reference the gnet_spice_sdb script will generate that voltage source for us.
Example:
Non-linear Dependent Sources (Behavioral Sources)
General SPICE form:
One of the great features of the gnet_spice_sdb script is that if it doesn't recognize a device attribute or refdes it will still output a spice line in the form REFDES NODES_FOUND VALUE. We can misuse that feature to make a non-linear dependent source. Just take any source from the library:
And use the standard attributes:
Exxxx: non-linear voltage source*
Gxxxx: non-linear current source*
Although gschem library has a transmission line symbol available the gnet_spice_sdb script does not recognize the device attribute nor the refdes. And gnet_spice_sdb will also not let us specify any attributes separately. TODO: submit a patch?
However, one of the great features of the gnet_spice_sdb script is that if it doesn't recognize a device attribute or refdes it will still output a spice line in the form REFDES NODES_FOUND VALUE. We can misuse that feature to make a transmission line. Just take the transmission line symbol from the library:
And use the standard attributes:
Please note that the gschem SPICE library has a transmission line like symbol (wline-1x.sym) that resembles a tline.sym symbol. However the wline-1x.sym uses the W? refdes but the W is reserved for the Current controlled switch (so if we use this symbol we need to change the refdes)
Unfortunately gnet_spice_sdb will not recognize refdes O? and therefore will also not output the model-name attribute (mname) and the model attribute. TODO: submit a patch?
gnet_spice_sdb will recognize refdes U? BUT it will assume it's dealing with an integrated chip and therefore it will output the attributes model-name, model and file or the attribute value. If we don't need the l and n options we can misuse that feature to make an uniform distributed RC line.
Example:
Single Lossy Transmission Line (TXL)
Unfortunately gnet_spice_sdb will not recognize refdes Y? and therefore will also not output the model-name attribute (mname) and the model attribute. TODO: submit a patch?
Coupled Multiconductor Line (CPL)
Unfortunately gnet_spice_sdb will not recognize refdes P? and therefore will also not output the model-name attribute (mname) and the model attribute. TODO: submit a patch?
n+ and n- are the positive and negative nodes. Personally I find it difficult to remember if the anode is positive or negative and visa-versa, so to make it easier for me, I rewrite the general form as:
gnet_spice_sdb script will also look at the file attribute, this will overwrite the model attribute.
Additionally, gnet_spice_sdb will let us specify the following attributes separately:temp, ic, area, off
Possible attributes | |||
---|---|---|---|
device | : | DIODE | |
Refdes | : | D? |
Example:
Bipolar Junction Transistors (BJTs)
Possible attributes | |||
---|---|---|---|
device | : | NPN_TRANSISTOR | |
: | SPICE-NPN | ||
: | PNP_TRANSISTOR | ||
: | SPICE-PNP | ||
refdes | : | Q? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL | |
file | : | /Path/To/Spice/File.prm | The file attribute will take priority over the model attribute. We can define both in our symbol. |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:temp, ic, area, off
Example:
Junction Field-Effect Transistors (JFETs)
Possible attributes | |||
---|---|---|---|
device | : | NFET_TRANSISTOR | |
: | PFET_TRANSISTOR | ||
refdes | : | J? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL | |
file | : | /Path/To/Spice/File.prm | The file attribute will take priority over the model attribute. We can define both in our symbol. |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:temp, ic, area, off
Example:
Possible attributes | |||
---|---|---|---|
device | : | MESFET_TRANSISTOR | |
refdes | : | Z? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL | |
file | : | /Path/To/Spice/File.prm | The file attribute will take priority over the model attribute. We can define both in our symbol. |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:temp, ic, area, off
Example:
Possible attributes | |||
---|---|---|---|
device | : | NMOS_TRANSISTOR | |
: | PMOS_TRANSISTOR | ||
refdes | : | M? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL | |
file | : | /Path/To/Spice/File.prm | The file attribute will take priority over the model attribute. We can define both in our symbol. |
Additionally, gnet_spice_sdb will let us specify the following attributes separately:temp, ic, area, off, l, w, as, ad, pd,ps, nrd, nrs, m
Example:
Apparently this is (or was) mostly used for PMOS and NMOS definitions, but there is no restriction whatsoever to use it for our own frequently used sub circuit.
Possible attributes | |||
---|---|---|---|
device | : | SUBCKT_PMOS | |
: | SUBCKT_NMOS | ||
: | FANTASY_NAME | We must use the X? refdes | |
refdes | : | X? | |
model-name | : | YOURMODELNAME | |
model | : | YOURMODEL | |
file | : | /Path/To/Spice/File.prm | The file attribute will take priority over the model attribute. We can define both in our symbol. |
Due to the PMOS and NMOS inheritance, gnet_spice_sdb will let us specify the following additional attributes separately if de device is either SUBCKT_PMOS or SUBCKT_NMOS:temp, ic, area, off, l, w, as, ad, pd, ps, nrd, nrs, m
Example:
Mixed-Mode and Behavioral Modeling with XSPICE and gEDA
Possible attributes | |||
---|---|---|---|
device | : | FANTASY_NAME | We must use the A? refdes |
refdes | : | A? | |
model-name | : | YOURMODELNAME | |
model | : | XSPICEMODEL | Don’t use a fantasy name for the model, check the ngspice manual for the correct model names. |
file | : | /Path/To/Spice/File.prm | The file attribute will take priority over the model attribute. We can define both in our symbol. |
Most xspice models can be used through the gnet_spice_sdb netlist script without problems as long as they have a single input or output port, like the gain model:a1 1 2 amp
However if the xspice model has a [vector] as input or output, like the summer model:
.model amp gain(in_offset=0.1 gain=5.0 out_offset=−0.01)a2 [1 2] 3 sum1
the standard way will not work.
.model sum1 summer(in_offset=[0.1 −0.2] in_gain=[2.0 1.0] out_gain=5.0out_offset=−0.01)
BUT there is a way to make it work. If we dig deep enough into the script we will find a hidden gem. The hidden gem is an attribute "net-format". We can use that attribute to format how the gnet_spice_sdb script will output the pinsequence numbers into the spice simulation file. We can give the "net-format" attribute the values like the examples in the table below. There are two points important when using the net-format attribute:
- always end the value with a space (in the examples below this is the "_" at the end of the net-format attribute value, use a space i.s.o. the "_" character); TODO: submit a patch?
- the script will output the pinsequence numbers to the spice simulation file and NOT the pin numbers we have defined in our schematic symbol;
The format of the "net-format" attribute is dependent on the "simple-format" used by scheme and guile.
Take a look at Guile manual. At the bottom of the page we see:
Guile contains a format procedure even when the module (ice-9 format) is not loaded. The default format is simple-format, it doesn’t support all escape sequences documented in this section, and will signal an error if you try to use one of them. The reason for two versions is that the full format is fairly large and requires some time to load. simple-format is often adequate too.
If we dig deeper we find we can use the following format to get what we want.
Examples:
"net-format" attribute value | output to spice simulation file | ||
[~a ~a] ~a_ | [1 2] 3 | ||
[~a] [~a]_ | [1] [2] | ||
[~a ~a ~a] [~a]_ | [1 2 3] [4] | ||
(~a ~a) ~a_ | (1 2) 3 |
Here is an example for the Analog-to-Digital Node Bridge:abridge2 [1] [8] adc_buff
Example:
.model adc_buff adc_bridge(in_low = 0.3 in_high = 3.5)
With this information all the XSPICE models mentioned below can be used with the gnet_spice_sdb netlist script.
.model amp gain(in_offset = 0.1 gain = 5.0 out_offset = −0.01)
Example:
.model sum1 summer(in_offset = [0.1 −0.2] in_gain = [2.0 1.0] out_gain = 5.0 out_offset = −0.01)
Example:
.model sigmult mult(in_offset = [0.1 0.1 −0.1] in_gain = [10.0 10.0 10.0] out_gain = 5.0 out_offset = 0.05)
.model divider divide(num_offset = 0.1 num_gain = 2.5 den_offset = −0.1 den_gain = 5.0 den_lower.limit = 1e−5 den_domain = 1e−6
+ fraction = FALSEout_gain = 1.0 out_offset = 0.0)
.model limit5 limit(in_offset = 0.1 gain = 2.5 out_lower_limit = −5.0out_upper_limit = 5.0 limit_range = 0.10 fraction = FALSE)
.model varlimit climit(in_offset = 0.1 gain = 2.5 upper_delta = 0.0 lower_delta = 0.0limit_range = 0.10 fraction = FALSE)
.model xfer_cntl1 pwl(x_array = [−2.0 −1.0 2.0 4.0 5.0]
+ y_array = [−0.2 −0.2 0.1 2.0 10.0]
+ input_domain = 0.05 fraction=TRUE)
.model filesrc filesource (file = "sine.m" amploffset = [0 0] amplscale = [1 1]
+ timeoffset = 0 timescale = 1
+ timerelative = false amplstep = false)
.model pwlm multi_input_pwl(x_array = [−2.0 −1.0 2.0 4.0 5.0]
+ y_array = [−0.2 −0.2 0.1 2.0 10.0]
+ model = "and")
.model switch3 aswitch(cntl_off = 0.0 cntl_on = 5.0 r_off = 1e6 r_on = 10.0 log = TRUE)
.model vref10 zener(v_breakdown = 10.0 i_breakdown = 0.02 r_breakdown = 1.0 i_rev = 1e−6i_sat = 1e−12)
.model amp3 ilimit(in_offset = 0.0 gain = 16.0 r_out_source = 1.0
+ r_out_sink = 1.0 i_limit_source = 1e−3
+ i_limit_sink = 10e−3 v_pwr_range = 0.2
+ i_source_range = 1e−6 i_sink_range = 1e−6
+ r_out_domain = 1e−6)
.model schmitt1 hyst(in_low = 0.7 in_high = 2.4 hyst = 0.5
+ out_lower_limit = 0.5 out_upper_limit = 3.0
+ input_domain = 0.01 fraction = TRUE)
.model slope_gen d_dt(out_offset = 0.0 gain = 1.0
+ out_lower_limit = 1e−12 out_upper_limit = 1e12
+ limit_range = 1e−9)
.model time_count int(in_offset = 0.0 gain = 1.0
+ out_lower_limit = −1e12 out_upper_limit = 1e12
+ limit_range = 1e−9 out_ic = 0.0)
+ num_coeff = [1.0 0.0 0.7464102]
+ den_coeff = [1.0 0.9989420.001170077]
+ int_ic = [0 0])
.model cheby1 s_xfer(num_coeff = [1] den_coeff = [1 1.09773 1.10251]
+ int_ic = [0 0] denormalized_freq = 1500)
.model cheby_LP_3KHz s_xfer(in_offset = 0.0 gain = 1.0 int_ic = [0 0]
+ num_coeff = [1.0]
+ den_coeff = [1.0 1.42562 1.51620])
.model slew1 slew(rise_slope = 0.5e6 fall_slope = 0.5e6)
.model lcouple1 lcouple(num_turns = 10.0)
.model primary lcouple (num_turns = 155)
a2 (3 4) iron_core
.model iron_core core (H_array = [−1000 −500 −375 −250 −188 −125−63 0 63 125 188 250 375 500 1000]
+B_array = [−3.13e−3 −2.63e−3 −2.33e−3 −1.93e−3−1.5e−3 −6.25e−4 −2.5e−4 0 2.5e−4
+ 6.25e−4 1.5e−3 1.93e−3 2.33e−3 2.63e−33.13e−3]
+ area = 0.01 length = 0.01)
a3 (5 0) (4 0) secondary
.model secondary lcouple (num_turns = 310)
.model primary lcouple (num_turns = 155)
a2 (3 4) iron_core
.model iron_core core (mode = 2 in_low =−7.0 in_high = 7.0
+ out_lower_limit = −2.5e−4 out_upper_limit = 2.5e−4
+ hyst = 2.3 )
a3 (5 0) (4 0) secondary
.model secondary lcouple (num_turns = 310)
Controlled Sine Wave Oscillator
.model in_sine sine(cntl_array = [−1 0 5 6]
+ freq_array = [1010 1000 1000] out_low = −5.0
+ out_high = 5.0)
Controlled Triangle Wave Oscillator
.model ramp1 triangle(cntl_array = [−1 0 5 6]
+ freq_array = [10 10 1000 1000] out_low = −5.0
+ out_high = 5.0 duty_cycle = 0.9)
Controlled Square Wave Oscillator
.model pulse1 square(cntl_array = [−1 0 5 6]
+ freq_array = [10 10 1000 1000] out_low = 0.0
+ out_high = 4.5 duty_cycle = 0.2
+ rise_time = 1e−6 fall_time = 2e−6)
.model pulse2 oneshot(cntl_array = [−1 0 10 11]
+ pw_array=[1e−6 1e−6 1e−4 1e−4]
+ clk_trig = 0.9 pos_edge_trig = FALSE
+ out_low = 0.0 out_high = 4.5
+ rise_delay = 20.0−9 fall_delay = 35.0e−9)
.model ctest cmeter(gain=1.0e12)
.model ltest lmeter(gain = 1.0e6)
.model memr memristor(rmin = 1k rmax = 10k rinit = 7k alpha = 0 beta = 2e13 vt = 1.6)
.model dac1 dac_bridge(out_low = 0.7 out_high = 3.5 out_undef = 2.2 input_load = 5.0e−12 t_rise = 50e−9 t_fall = 20e−9)
.model adc_buff adc_bridge(in_low = 0.3 in_high = 3.5)
.model var_clock d_osc(cntl_array = [−2 −1 1 2]
+ freq_array = [1e3 1e3 10e3 10e3]
+ duty_cycle = 0.4 init_phase = 180.0
+ rise_delay = 10e−9 fall_delay = 8e−9)
.model buff1 d_buffer(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load =0.5e−12)
.model inv1 d_inverter(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load =0.5e−12)
.model and1 d_and(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load = 0.5e−12)
.model nand1 d_nand(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load = 0.5e−12)
.model or1 d_or(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load = 0.5e−12)
.model nor12 d_or(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load = 0.5e−12)
.model xnor3 d_xnor(rise_delay = 0.5e−9 fall_delay = 0.3e−9 input_load = 0.5e−12)
.model tri7 d_tristate(delay = 0.5e−9 input_load = 0.5e−12 enable_load = 0.5e−12)
.model pullup1 d_pullup(load = 20.0e−12)
.model pulldown1 d_pulldown(load = 20.0e−12)
.model flop2 d_jkff(clk_delay = 13.0e−9 set_delay = 25.0e−9
+ reset_delay = 27.0e−9 ic = 2 rise_delay = 10.0e−9 fall_delay = 3e−9)
.model flop3 d_tff(clk_delay = 13.0e−9 set_delay = 25.0e−9
+ reset_delay = 27.0e−9 ic = 2 rise_delay = 10.0e−9
+ fall_delay = 3e−9 t_load = 0.2e−12)
.model flop7 d_srff(clk_delay = 13.0e−9 set_delay = 25.0e−9
+ reset_delay = 27.0e−9 ic = 2 rise_delay = 10.0e−9
+ fall_delay = 3e−9)
.model latch1 d_dlatch(data_delay = 13.0e−9 enable_delay = 22.0e−9
+ set_delay = 25.0e−9
+ reset_delay = 27.0e−9 ic = 2
+ rise_delay= 10.0e−9 fall_delay = 3e−9)
.model latch2 d_srlatch(sr_delay = 13.0e−9 enable_delay = 22.0e−9
+ set_delay = 25.0e−9
+ reset_delay = 27.0e−9 ic = 2
+ rise_delay = 10.0e−9 fall_delay = 3e−9)
.model state1 d_state(clk_delay = 13.0e−9reset_delay = 27.0e−9
+ state_file = "newstate.txt" reset_state = 2)
.model divider d_fdiv(div_factor = 5 high_cycles = 3
+ i_count = 4 rise_delay = 23e−9 fall_delay = 9e−9)
.model ram2 d_ram(select_value = 2 ic = 2 read_delay = 80e−9)
.model input_vector d_source(input_file = "source_simple.text")
Version used in this note: gEDA 1.8.1
Comments are welcome at ( geda at myken dot nl )