Source code coming soon. The GitHub repository is private for now and opens to everyone very soon.
BetterSPICE Beta 0.8.0 Join the beta Download soon
Part VI  Parts and modelsReferenceContentsIndex
31

Devices: sources

Every voltage source has a + and a - pin and forces V(+) - V(-). Every current source drives its current out of the + pin into the circuit and back in at -. A source delivering power shows a negative current at its + pin, because pin currents are measured into the part.

31.1Changing the source type

The inspector's Source type list turns a source into another kind in place, keeping its pins and wires: DC voltage, Sine (AC), Square, Function generator, Pulse, PWL, Battery, DC current, Sine current, Function generator current. Levels and frequency carry over as far as the new waveform allows. Every source shows a live preview of its waveform. A battery keeps its chemistry and never gets pinned to a made-up voltage.

A sine source: amplitude, frequency, offset and phase, with the preview.
Figure 31.1A sine source: amplitude, frequency, offset and phase, with the preview.
A function generator set to a 30 % square wave.
Figure 31.2A function generator set to a 30 % square wave.

31.2How sources behave in each analysis

How sources behave in each analysis
AnalysisBehaviour
Operating pointThe value at t = 0: sine = offset + amp · sin(phase), pulse = low level, PWL = first point.
TransientThe full waveform. Pulse, square, function generator and PWL corners are exact breakpoints, so edges are never skipped. A sine limits the timestep to a twentieth of its period.
AC sweepThe source chosen as input gets 1 V (or 1 A) at 0°, whatever its own parameters. Other sources are at their DC value.
DC sweepThe swept source becomes a DC value. For a sine, the offset is swept. A battery cannot be swept.

31.3DC voltage source

DC voltage source
TypeKeyPinsVariantsClass
vdc (V)V+, -noneexact
DC voltage source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
VoltagevV5any. Slider -50 to 50 V.Default, inspector, board importV(+) - V(-).
Series resistancersΩ0≥ 0Default, inspectorA real source: a resistor in the + lead. A battery keeps its own r.
AC magnitude, phaseac_mag, ac_phaseV, °1, 0anyDefault, inspectorThe drive when this is the source an AC analysis sweeps. Noise, loop gain and pole-zero ignore them, as ngspice does.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Two voltage sources in parallel, or one shorted, are refused before the run (E_VSRC_LOOP, E_VSRC_SHORT).

31.4Sine source

Sine source
TypeKeyPinsVariantsClass
vsin (V)A+, -noneexact

v(t) = offset + amp · sin(2π · freq · t + phase).

Sine source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Amplitude (peak)ampV5any. Slider 0 to 400 V.Default, inspectorPeak, not peak to peak or RMS. 230 V RMS mains is 325 V peak.
FrequencyfreqHz500 to 1015. Slider 0.1 Hz to 10 MHz.Default, inspector
Dampingtheta1/s0anyDefault, inspectorAmplitude × exp(-theta (t - delay)), as the SPICE SIN source.
DC offsetoffsetV0anyDefault, inspector
Phasephase°0anyDefault, inspector
Start delaydelays0≥ 0Default, inspectorThe source holds its starting value (offset + amp · sin(phase)) until then, with no jump. Like SIN TD in SPICE.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

31.5Pulse source

Pulse source
TypeKeyPinsVariantsClass
vpulse (V)Alt+A+, -noneexact

The SPICE pulse: low, a linear rise, high for the width, a linear fall, low until the end of the period.

Pulse source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Low (initial)v1V0anyDefault, inspectorLevel before the delay and between pulses.
High (pulsed)v2V5anyDefault, inspector
Start delaydelays0≥ 0Default, inspectorTime before the first rising edge.
Rise timerises1 ns≥ 0 (used ≥ 1 ps)Default, inspector
Fall timefalls1 ns≥ 0 (used ≥ 1 ps)Default, inspector
Pulse widthwidths5 µs≥ 0Default, inspectorTime at the high level between the end of the rise and the start of the fall.
Periodperiods10 µs≥ 1 fsDefault, inspectorIf rise + width + fall is longer, the pulse is cut at the period and the run warns W_PARAM.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

For a PWM signal of duty D at the 50 % level, set width = D · period - (rise + fall) / 2.

A pulse that doesn’t fit in its period is cut off when the next period starts, so it never settles back to the low level. The run says so with a W_PARAM warning that names the numbers and the fix: "V2: rise 1 µs + width 9 µs + fall 1 µs = 11 µs is longer than the period 10 µs; each pulse is cut off when the next period starts …", then "Make V2 width at most 8 µs (period − rise − fall), or the period at least 11 µs." When the two edges alone are longer than the period, the fix says to shorten them. A negative delay, rise, fall or width is still an E_PARAM error that names the key and >= 0.

31.6Square wave source

Square wave source
TypeKeyPinsVariantsClass
vsquare (V)library+, -noneapproximate

A square wave with fixed edges of 1 ns or a thousandth of the period, whichever is shorter, and an optional start delay. For phase or slow edges use the function generator.

Square wave source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Low levelvloV0anyDefault, inspector
High levelvhiV5anyDefault, inspector
FrequencyfreqHz1 kHz> 0Default, inspector
Duty cycleduty% (stored 0 to 1)50 %0 to 1Default, inspectorHigh time at the 50 % level.
Start delaydelays0≥ 0Default, inspectorThe output stays low until then.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

31.7Function generator

Function generator
TypeKeyPinsVariantsClass
vfunc (V)library+, -square, sine, triangle, sawtooth (the waveform)approximate

A bench function generator. The variant is the waveform, chosen with the Square, Sine, Triangle and Sawtooth buttons. The current version, ifunc, is the same with ipp in amps (default 2 mA, centred).

Function generator
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
FrequencyfreqHz1 kHz> 0Default, inspector
Amplitude (peak to peak)vppV5any (magnitude used)Default, inspector
LevelslevelsFrom 0From 0, Centred on 0, Custom offsetDefault, inspectorPresets for the offset. From 0: 0 to vpp. Centred: ± vpp/2. Custom: around the DC offset you typed.
DC offset (mid level)offsetV0anyDefault, inspectorAlways shown, with the mid level the waveform has now (2.5 V for 5 Vpp from 0). Typing a value sets Levels to Custom offset: 1 V offsets the wave by 1 V.
Duty cycle / Symmetryduty% (stored 0 to 1)50 %0 to 1Default, inspectorSquare: high time. Triangle: the rising fraction. Not used by sine and sawtooth.
Rise timerises1 ns≥ 0 (up to 45 % of the period)Default, inspectorSquare edges.
Fall timefalls1 ns (sawtooth: period / 1000)≥ 0Default, inspectorSquare falling edge, or the sawtooth flyback.
Phasephase°0anyDefault, inspectorA positive phase advances the waveform.
Start delaydelays0≥ 0Default, inspectorEvery waveform, the sine too, holds its starting level until then and then starts its first period.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

31.8Piecewise-linear source

Piecewise-linear source
TypeKeyPinsVariantsClass
vpwl (V)library+, -noneexact

Straight lines between time and value points. Before the first point the first value holds, after the last the last value holds. Two points at the same time make a step. The points are sorted by time. The inspector shows them as a table, under a preview of the waveform.

Piecewise-linear source
In the tableWhat it does
A cellType a time or a value, with units such as 1ms or 5V. Enter or Tab applies, Esc puts the stored value back.
+Adds a point after the last one.
× on a rowDeletes the point. At least one point stays.
Edit as textThe same points as text, one per line (1ms 5V) or separated by commas (0 0, 1m 5, 2m 5, 3m 0). Press Ctrl+Enter or click away to apply.
Right-click the source, Edit points…Opens the inspector with the first cell of the table selected.

Undo, and an AI agent’s edits, show in the table at once.

Under the table, Time offset starts the whole list later (the first value holds until then), and Repeat the points plays the list again and again, like td= and r= in a SPICE PWL source. Ticking the box sets Repeat from to the first time, so the whole list repeats. Raise it to repeat only the later part: with Repeat from at 1 ms, a list that ends at 3 ms plays once from the start, and from then on the section from 1 ms to 3 ms repeats every 2 ms. The note under the field says what repeats and how often, for example "After the last point the points from 0 s on repeat, every 2 ms." Each pass jumps back to the value at the repeat time, and the corners of every pass are exact breakpoints. A repeat time that isn’t before the last point is a mistake: the points play once and the run warns W_PARAM.

Piecewise-linear source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Pointspointss, V[[0, 0]] (placed: 0 V, then 5 V at 1 ms)times rising from 0Default, inspectorA list of [time, value] pairs in the file.
Time offsettds0anyDefault, inspectorShifts the whole list later. The first value holds until then. Its slider spans the length of the list.
Repeat fromrsnone (plays once)≥ 0, before the last pointDefault, inspectorA time in the list. After the last point, the section from r to the last point repeats forever. 0 repeats the whole list. Unticking Repeat the points removes it. Exported as r= and td=.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

A PWL source set to repeat: the preview shows the passes, and under the points table are the Time offset, Repeat the points and Repeat from.
Figure 31.3A PWL source set to repeat: the preview shows the passes, and under the points table are the Time offset, Repeat the points and Repeat from.

31.9DC current source

DC current source
TypeKeyPinsVariantsClass
idc (I)I+, -noneexact
DC current source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
CurrentiA1 mAany. Slider -10 to 10 A.Default, inspectorLeaves the + pin into the circuit.
Parallel resistancerpΩnone> 0Default, inspectorA real source: a resistor across its output.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

A current source with nowhere to send its current is refused (E_ISRC_OPEN).

31.10Sine current source

Sine current source
TypeKeyPinsVariantsClass
isin (I)library+, -noneexact
Sine current source
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
AmplitudeampA1 mAanyDefault, inspectorPeak.
FrequencyfreqHz500 to 1015Default, inspector
OffsetoffsetA0anyDefault, inspector
Phasephase°0anyDefault, inspector
Start delaydelays0≥ 0Default, inspectorAs for the sine voltage source.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

31.11Voltage-controlled voltage source (E)

Voltage-controlled voltage source (E)
TypeKeyPinsVariantsClass
vcvs (E)library+, -, c+, c-noneexact

V(+) - V(-) = gain · (V(c+) - V(c-)). The control pins draw no current.

Voltage-controlled voltage source (E)
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
GaingainV/V1any. Slider -1000 to 1000.Default, inspector

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

31.12Voltage-controlled current source (G)

Voltage-controlled current source (G)
TypeKeyPinsVariantsClass
vccs (G)library+, -, c+, c-noneexact

A current gm · (V(c+) - V(c-)) flows from + through the part to -. The control pins draw no current.

Voltage-controlled current source (G)
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
TransconductancegmS1 mSanyDefault, inspector

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

For a source controlled by a current, use the CCVS or CCCS below.

31.13Current-controlled voltage source (H)

Current-controlled voltage source (H)
TypeKeyPinsVariantsClass
ccvs (H)library+, -, s+, s-noneexact

V(+) - V(-) = rt · I(sense), where I(sense) is the current that flows into s+ and out of s-. The sense port is a 0 V branch, an ideal ammeter: wire it in series with the branch whose current you want to sense, the way you put a meter in a line. A positive current goes into s+. Swap the two pins to reverse the sign. The port needs no extra 0 V source in the schematic.

Current-controlled voltage source (H)
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
TransresistancertΩ1 kΩany. Slider -1 MΩ to 1 MΩ.Default, inspectorVolts out per amp sensed. A sensed 5 mA with rt = 200 Ω gives 1.000 V.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Live value: Sensed current (i_sense), and every pin shows its current. The exported SPICE netlist has an H element with a 0 V source for the sense port.

31.14Current-controlled current source (F)

Current-controlled current source (F)
TypeKeyPinsVariantsClass
cccs (F)library+, -, s+, s-noneexact

A current gain · I(sense) flows into + and out of - through the source, as for the VCCS. I(sense) is the current into s+ and out of s-, through the same 0 V sense port as the CCVS. A source may sense the branch it feeds: a gain of 0.5 on its own load current is allowed, and settles at the current the equations give.

Current-controlled current source (F)
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Current gaingainA/A1any. Slider -1000 to 1000.Default, inspectorAmps out per amp sensed. A sensed 5 mA with a gain of 3 gives 15 mA.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Live value: Sensed current (i_sense). Both are linear and exact, like the VCVS and VCCS, and a change of the field applies while the circuit runs.

Start delay sliders (the delay of the sine, square, pulse and function generator sources, and the PWL Time offset) span one period of the source, from 0 to 1 / frequency, so a slider on a 100 kHz source runs from 0 to 10 µs instead of 0 to 1 s. A source with a delay that is already longer than one period gets a slider that spans two or more periods. A range you typed yourself wins.

31.15Battery

The inspector of a battery shows its Chemistry (Li-ion, LiFePO4, NiMH, alkaline, coin, lead-acid, LiPo pack), a graph of the open-circuit voltage, and the fields below. The open-circuit voltage is the one the chemistry’s curve gives at the charge you set, so the inspector, the preview, the canvas label and the simulation agree: a NiMH cell reads 1.30 V, not 3.7 V. The full model is in Batteries and supercapacitors.

A Li-ion battery: chemistry, the curve, charge at the start, cells in series and capacity.
Figure 31.4A Li-ion battery: chemistry, the curve, charge at the start, cells in series and capacity.
Battery
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Chemistryvariantliionliion, lifepo4, nimh, alkaline, coin, leadacid, lipo_packDefault, inspectorPicks the voltage curve, resistance and polarisation.
Charge at startsoc0 to 10.8Default, inspectorShown as a percentage. Falls as the battery delivers charge.
Cells in seriescells1 (LiPo pack 3)whole number, 1 or moreDefault, inspector
Capacitycapacity_ahAh2 (coin cell 0.22)> 0Default, inspector
Internal resistancerΩfrom the chemistry (coin 15)≥ 0Default, inspector
Fixed voltagevVnoneanyDefault, inspectorIf set, the battery is an ideal source with a series resistance and does not discharge. The inspector shows Fixed voltage and a Use the … curve instead button.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

A battery with no chemistry (from a file or a source type change) shows Voltage (3.7 V) and Internal resistance (0.05 Ω) only. The browser’s fallback engine uses the curve at the starting charge and doesn’t discharge it.

31.16Ground and power flags

Ground (G, type gnd) joins net 0, the main ground. A ground with a name other than GND or 0, such as ISO1, is an isolated ground: every ground of that name is one ground domain, tied to net 0 only through its isolation barrier (Keep sides isolated with their own grounds).

Ground and power flags
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Ground namenetemptya name without spacesDefault, inspectorEmpty, GND or 0: the main ground. Any other name: an isolated ground of that domain. Press Tab while placing a ground to step through the domains.
Isolation resistancer_isoΩ1 GΩ> 0Default, inspectorIsolated ground only. Belongs to the domain: setting it on any symbol sets every symbol of the domain. When symbols of an old file disagree, the first symbol that sets it wins.
Isolation capacitancec_isoF10 pF≥ 0Default, inspectorIsolated ground only, same rule. 0 leaves only the resistance.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Power flags (Shift+G) are names, not parts: every flag and label with the same name is one net. A power flag doesn’t supply voltage. Place a source to drive the net.