SpiceSharpParser can translate supported native LTspice A... lines into the
portable models supplied by DigitalSubcircuitLibrary and
AnalogSubcircuitLibrary.
Install SpiceSharpParser.CustomComponents, select LTspice compatibility, and
enable the custom reader mappings:
using SpiceSharpParser.CustomComponents;
var options = new SpiceCompileOptions
{
Dialect = SpiceDialect.LTspice,
ConfigureReader = settings => settings.UseCustomComponents(),
};Every native A-device line has eight terminal positions followed by its model:
A<name> n1 n2 n3 n4 n5 n6 n7 n8 <model> [parameter=value ...] [flag ...]
Unused terminals are written as 0. Model and parameter names are
case-insensitive.
SET drives Q high and RESET drives it low. The complementary output is
QB.
* Set Q, then reset it
VSET set 0 PULSE(0 5 10n 100p 100p 2n 100n)
VRESET reset 0 PULSE(0 5 30n 100p 100p 2n 100n)
ASR set reset 0 0 0 qb q 0 SRFLOP Vhigh=5 Vlow=0 Td=1n
RQ q 0 10k
RQB qb 0 10k
.tran 100p 45n 0 100p UIC
.meas tran q_after_set FIND V(q) AT=20n
.meas tran q_after_reset FIND V(q) AT=40n
.end
Q_AFTER_SET is approximately 5 V and Q_AFTER_RESET is approximately 0 V.
Q captures DATA on each rising edge of CLOCK. PRESET and CLEAR are
active high, so they are tied low here.
* First clock edge captures high; second captures low
VDATA data 0 PULSE(0 5 5n 100p 100p 17n 40n)
VCLOCK clock 0 PULSE(0 5 10n 100p 100p 5n 20n)
VPRESET preset 0 0
VCLEAR clear 0 0
ADFF data 0 clock preset clear qb q 0 DFLOP Vhigh=5 Vlow=0 Td=1n
RQ q 0 10k
RQB qb 0 10k
.tran 100p 40n 0 100p UIC
.meas tran q_after_first_edge FIND V(q) AT=15n
.meas tran q_after_second_edge FIND V(q) AT=35n
.end
The two measurements are approximately 5 V and 0 V.
This counter repeats every four rising clock edges. DUTY=0.5 keeps Q high
for half of each count cycle.
* Divide the input clock by four
VCLOCK clock 0 PULSE(0 5 5n 100p 100p 2n 10n)
VRESET reset 0 0
ACOUNT clock reset 0 0 0 qb q 0 COUNTER cycles=4 duty=0.5 Vhigh=5 Vlow=0
RQ q 0 10k
RQB qb 0 10k
.tran 100p 42n 0 100p UIC
.meas tran q_at_10n FIND V(q) AT=10n
.meas tran q_at_30n FIND V(q) AT=30n
.end
Plot V(clock), V(q), and V(qb) to see the divide-by-four sequence.
The phase detector sources current when A leads B and sinks current when
B leads A. A resistor converts that current into an easy-to-view voltage.
* Convert phase error into an output voltage
VA a 0 PULSE(0 1 10n 100p 100p 2n 50n)
VB b 0 PULSE(0 1 20n 100p 100p 2n 30n)
APD a b 0 0 0 0 out 0 PHASEDET Iout=1m Vhigh=10 Vlow=-10
ROUT out 0 1k
.tran 100p 75n 0 100p UIC
.meas tran out_a_leads FIND V(out) AT=15n
.meas tran out_b_leads FIND V(out) AT=55n
.end
With IOUT=1 mA and ROUT=1 kOhm, the active source and sink levels are close
to +1 V and -1 V.
With terminal 4 tied low, the device captures its differential input when
SAMPLE rises. The input keeps ramping while HELD retains the sampled value.
* Capture a ramp at 10 us
VIN input 0 PWL(0 0 20u 2 40u 4)
VSAMPLE sample 0 PULSE(0 1 10u 10n 10n 1u 100u)
ASH input 0 sample 0 0 0 held 0 SAMPLEHOLD Rout=100
RLOAD held 0 100k
.tran 100n 30u 0 100n UIC
.meas tran input_later FIND V(input) AT=25u
.meas tran held_later FIND V(held) AT=25u
.end
At 25 us, INPUT is about 2.5 V while HELD remains near 1 V.
In Linear mode, the OTA multiplies two differential input voltages and
converts the result into output current. The load resistor converts that
current into voltage.
* 0.1 V differential input multiplied by 1 V
VIN1N in1n 0 0
VIN1P in1p 0 0.1
VIN2P in2p 0 1
VIN2N in2n 0 0
AOTA in1n in1p in2p in2n 0 rail out 0 OTA G=1m Linear Vhigh=5 Vlow=-5
RLOAD out 0 10k
.tran 10n 1u UIC
.meas tran output FIND V(out) AT=500n
.end
This configuration produces approximately 1 V at OUT.
The control voltage sets the clamp magnitude. Here a 2 V control limits an output driven from a 10 V supply.
* Clamp OUT near the 2 V control level
VCONTROL control 0 2
VSUPPLY supply 0 10
RDRIVE supply out 1k
AVAR control 0 0 0 0 0 out 0 VARISTOR Rclamp=10
.tran 10n 1u UIC
.meas tran clamped_output FIND V(out) AT=500n
.end
CLAMPED_OUTPUT is slightly above 2 V because RCLAMP is finite.
FM=0.5 V selects the midpoint between SPACE=1 kHz and MARK=2 kHz, giving
a 1.5 kHz output. AM=2 V sets the sine-wave amplitude.
* 1.5 kHz sine wave with 2 V amplitude
VFM fm 0 0.5
VAM am 0 2
AMOD fm am 0 0 0 0 out 0 MODULATOR mark=2k space=1k Rout=1
RLOAD out 0 100k
.tran 1u 1m 0 1u UIC
.meas tran positive_peak FIND V(out) AT=166.6666667u
.end
POSITIVE_PEAK is approximately 2 V. MODULATE is accepted as an alias for
MODULATOR.
The A-device implementations are functional macromodels. They preserve the useful logic, timing, current, clamping, and loading behavior without modeling every transistor or semiconductor region inside a physical device.
Let q be a Boolean state: 0 for low and 1 for high. Its ideal output voltage
is
Without an explicit Ref, an input changes logic state at the midpoint:
The finite output resistance and capacitance turn an ideal logic step into a first-order electrical transition. With an external capacitive load,
This is the physical bridge between Boolean logic and a voltage that can drive the rest of the circuit.
For reset-dominant active-high inputs,
A physical latch uses regenerative positive feedback to preserve state. The macromodel stores that state directly; it does not model transistor-level metastability.
The state immediately after an event is
A physical edge-triggered flip-flop is built from latches or a pulse-triggered
storage path. This model captures the event and applies Td, but it does not
calculate setup time, hold time, or metastability probability.
Let k be the number of rising edges since reset, N=CYCLES, and
Then
The output frequency and realized duty ratio are
A physical counter stores state in interconnected flip-flops. The macromodel
stores a normalized count and regenerates Q and QB.
Let s=+1 while A leads, s=-1 while B leads, and s=0 after the
matching edge. The output current and resistively converted voltage are
Here IOUT parameter.
For a phase-error pulse of width T,
This is the charge-pump principle used in phase-locked loops: edge timing error becomes charge delivered to a loop filter.
The sampled signal is the differential voltage
While tracking, the memory capacitor approximately follows
During hold, leakage produces droop:
Physically, this is an idealized switch charging a hold capacitor. With the
default RHOLD=1 TOhm and CMEM=10 pF, the hold time constant is about 10 s,
so microsecond-scale droop is negligible.
Define the four-quadrant input product
In Linear mode,
until the output reaches VLOW or VHIGH. In the example, G=1 mA/V², and RLOAD=10 kOhm; therefore
Physically, an OTA converts differential voltage into current. This four-quadrant form is also an analog multiplier: changing the sign of either differential pair reverses the output current.
Let
The current law is
For the example above, Kirchhoff's current law gives
so
Normalize the frequency-control voltage as
The instantaneous frequency, phase in cycles, and output voltage are
For FM=0.5 V, SPACE=1 kHz, and MARK=2 kHz, the frequency is
1.5 kHz. Its period is about
LTspiceADeviceCompatibilityGoldenTests executes the same native netlist in
LTspice and SpiceSharpParser and compares the resulting .MEAS values:
$env:LTSPICE_EXE = 'C:\Program Files\ADI\LTspice\LTspice.exe'
dotnet test src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj `
--filter 'FullyQualifiedName~LTspiceADeviceCompatibilityGoldenTests'