SpiceSharpParser.CustomComponents
0.1.2
dotnet add package SpiceSharpParser.CustomComponents --version 0.1.2
NuGet\Install-Package SpiceSharpParser.CustomComponents -Version 0.1.2
<PackageReference Include="SpiceSharpParser.CustomComponents" Version="0.1.2" />
<PackageVersion Include="SpiceSharpParser.CustomComponents" Version="0.1.2" />
<PackageReference Include="SpiceSharpParser.CustomComponents" />
paket add SpiceSharpParser.CustomComponents --version 0.1.2
#r "nuget: SpiceSharpParser.CustomComponents, 0.1.2"
#:package SpiceSharpParser.CustomComponents@0.1.2
#addin nuget:?package=SpiceSharpParser.CustomComponents&version=0.1.2
#tool nuget:?package=SpiceSharpParser.CustomComponents&version=0.1.2
SpiceSharpParser.CustomComponents
SpiceSharpParser.CustomComponents is the optional companion package for
SpiceSharpParser. It adds
LTspice-compatible components and reusable functional subcircuits while keeping
the resulting circuit compatible with the normal SpiceSharp simulation API.
The package targets .NET Standard 2.0 and .NET 8.0.
Installation
dotnet add package SpiceSharpParser.CustomComponents
The package depends on SpiceSharp-Parser, so a separate parser package
reference is not required.
Enable Custom Netlist Components
The original parser/reader flow keeps parsing, translation, and simulation as
explicit steps. Enable the custom mappings on SpiceSharpReader before calling
Read:
using System.IO;
using System.Linq;
using SpiceSharpParser;
using SpiceSharpParser.CustomComponents;
string netlistText = File.ReadAllText("circuit.cir");
var compatibility = CompatibilityOptions.LTspice;
// Parse the SPICE text.
var parser = new SpiceNetlistParser();
parser.Settings.Compatibility = compatibility;
var parsed = parser.ParseNetlist(netlistText);
// Translate the parsed model into SpiceSharp objects.
var reader = new SpiceSharpReader();
reader.Settings.Compatibility = compatibility;
reader.Settings.UseCustomComponents();
var model = reader.Read(parsed.FinalModel);
// Run the analysis defined by .OP, .TRAN, .AC, or .DC in the netlist.
var simulation = model.Simulations.Single();
simulation.Execute(model.Circuit);
UseCustomComponents() adds custom-aware mappings for A, C, D, and L
elements. Call it before Read, and use the same compatibility settings for
the parser and reader. Ordinary diode, capacitor, and inductor syntax continues
to use the standard SpiceSharp implementations.
Included Components
| Family | Supported forms |
|---|---|
| LTspice A-devices | SRFLOP, DFLOP, PHASEDET, COUNTER, SAMPLEHOLD, OTA, VARISTOR, and MODULATOR/MODULATE |
| Ideal diodes | LTspice-style .MODEL D(...) parameters such as Ron, Roff, Vfwd, reverse clamp, smoothing, and current limits |
| Nonlinear capacitors | Charge-defined capacitors using Q=<expression> |
| Nonlinear inductors | Flux-defined inductors using Flux=<expression> |
| Digital subcircuits | Gates, Schmitt inputs, tri-state drivers, multiplexers, an adder, decoder, comparator, open-drain output, latches, flip-flops, a counter, phase detector, and functional 555 timer |
| Analog subcircuits | Sample-and-hold, operational transconductance amplifier, voltage-controlled varistor, and frequency/amplitude modulator |
A-device Quick Reference
Every native LTspice A-device has eight terminal positions followed by its model name.
A<name> n1 n2 n3 n4 n5 n6 n7 n8 <model> [parameter=value ...]
| Model | What it does |
|---|---|
SRFLOP |
Stores one bit using asynchronous set and reset inputs |
DFLOP |
Captures a data bit on a clock edge |
PHASEDET |
Produces signed current pulses from input-edge timing error |
COUNTER |
Counts clock edges and generates a repeating output sequence |
SAMPLEHOLD |
Samples an analog voltage and holds the captured value |
OTA |
Converts differential input voltages into a limited output current |
VARISTOR |
Provides a bidirectional voltage-controlled clamp; like a programmable surge-protection varistor |
MODULATOR |
Generates an amplitude-controlled waveform whose frequency moves between Space and Mark |
Terminal 8 is the common node. A terminal position is unused when it repeats
that common node. If common is not ground, a literal 0 is an active connection
to global ground, not an unused terminal. Unused outputs are electrically
detached; an unused MODULATOR amplitude input selects the native amplitude of
1.
Example:
* Divide a 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
RQ q 0 10k
RQB qb 0 10k
.tran 100p 42n 0 100p UIC
.save V(clock) V(q) V(qb)
.plot tran V(clock) V(q) V(qb)
.meas tran q_at_30n FIND V(q) AT=30n
.print tran V(q)
.end
Programmatic Subcircuit Use
The embedded libraries can also add components directly to a SpiceSharp
Circuit:
using SpiceSharp;
using SpiceSharp.Components;
using SpiceSharpParser.CustomComponents.Digital;
var circuit = new Circuit(
new VoltageSource("VDD", "vdd", "0", 5.0),
new VoltageSource("VA", "a", "0", 5.0),
new VoltageSource("VB", "b", "0", 5.0),
new Resistor("RLOAD", "y", "0", 10_000.0));
var digital = DigitalSubcircuitLibrary.LoadBuiltIn();
digital.AddBinaryGate(
circuit,
DigitalGateKind.Nand2,
instanceName: "XU1",
firstInputNode: "a",
secondInputNode: "b",
outputNode: "y",
positiveSupplyNode: "vdd",
negativeSupplyNode: "0");
Use AnalogSubcircuitLibrary.LoadBuiltIn() for the four analog functional
models.
Compatibility Notes
- A-device support is experimental and intentionally limited to the eight documented families.
MODULATORrequires bothMarkandSpace;COUNTERrequiresCycles.SAMPLEHOLD Tdis rejected because its native delayed timing semantics are not implemented.- Sweep-dependent A-device parameters are rejected instead of being silently frozen at one value.
- The digital and analog libraries are functional macromodels, not transistor-level replicas of a specific physical part.
Documentation and Examples
- A-device guide
- Runnable A-device examples
- Digital subcircuit reference
- Analog subcircuit reference
- Ideal diode guide
- Nonlinear passive guide
License
MIT. See the repository license.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- SpiceSharp (>= 3.2.3)
- SpiceSharpBehavioral (>= 3.2.0)
- SpiceSharp-Parser (>= 3.4.1)
-
net8.0
- SpiceSharp (>= 3.2.3)
- SpiceSharpBehavioral (>= 3.2.0)
- SpiceSharp-Parser (>= 3.4.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
0.1.2