multisim2kicad 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -2
- package/dist/cli.js +2044 -39
- package/dist/db/symbols.d.ts +6 -2
- package/dist/emit/kicad-sch.d.ts +18 -1
- package/dist/index.js +2044 -39
- package/dist/ir/types.d.ts +24 -0
- package/dist/parse/dchip.d.ts +110 -0
- package/dist/parse/ms-hierarchy.d.ts +5 -1
- package/dist/parse/sim-settings.d.ts +35 -0
- package/dist/parse/spice.d.ts +303 -0
- package/package.json +1 -1
package/dist/ir/types.d.ts
CHANGED
|
@@ -307,6 +307,27 @@ export interface SchematicSymbol {
|
|
|
307
307
|
floating?: boolean;
|
|
308
308
|
/** The part's name in the EW database (e.g. "BAV23C"), when known. */
|
|
309
309
|
partName?: string;
|
|
310
|
+
/** How KiCad's simulator should model it (from Multisim's netlist template). */
|
|
311
|
+
sim?: SimSpec;
|
|
312
|
+
/** Added for the simulator only (a supply source): not in the BOM or on the board. */
|
|
313
|
+
simOnly?: boolean;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* KiCad simulator (ngspice) settings for one part, as `Sim.*` fields.
|
|
317
|
+
* `exclude`: Multisim has no model for it. Otherwise `device` is a KiCad
|
|
318
|
+
* device (`R`, `C`, `L`, `SUBCKT`), with `params` for the built-in models,
|
|
319
|
+
* `name` the model in the design's SPICE library (`library: true`), and
|
|
320
|
+
* `pins` symbol pin number -> model pin.
|
|
321
|
+
*/
|
|
322
|
+
export interface SimSpec {
|
|
323
|
+
exclude?: boolean;
|
|
324
|
+
device?: string;
|
|
325
|
+
params?: string;
|
|
326
|
+
/** Built-in R/C/L: the value KiCad would infer the same model from. */
|
|
327
|
+
value?: string;
|
|
328
|
+
name?: string;
|
|
329
|
+
library?: boolean;
|
|
330
|
+
pins?: [string, string][];
|
|
310
331
|
}
|
|
311
332
|
export interface SchematicWire {
|
|
312
333
|
points: SchPoint[];
|
|
@@ -388,4 +409,7 @@ export interface Schematic {
|
|
|
388
409
|
rootSheet: string;
|
|
389
410
|
sheets: SchematicSheet[];
|
|
390
411
|
root: SchInstance;
|
|
412
|
+
/** SPICE model library for the simulator (models + wrappers); "" when none. */
|
|
413
|
+
spiceLibrary?: string;
|
|
414
|
+
warnings?: string[];
|
|
391
415
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multisim's `d_chip` behavioural logic -> ngspice XSPICE.
|
|
3
|
+
*
|
|
4
|
+
* Multisim describes most MSI logic (74xx counters, decoders, comparators,
|
|
5
|
+
* 4000-series registers, ...) with a `.MODEL <name> d_chip (behaviour="...")`
|
|
6
|
+
* whose string is a small table language:
|
|
7
|
+
*
|
|
8
|
+
* /inputs A B C pins, in the order the instance lists them
|
|
9
|
+
* /outputs Y Z
|
|
10
|
+
* /wires W1 W2 internal nets of the top level
|
|
11
|
+
* /module NAME ... /endmodule
|
|
12
|
+
* /instance NAME a b y a module instance (its inputs, then outputs)
|
|
13
|
+
* /table N N rows: input values, then output values
|
|
14
|
+
* /clock CLK +|-|X F S A F state flags; S synchronous rows (applied on
|
|
15
|
+
* the clock edge), then A asynchronous rows
|
|
16
|
+
* /delay N N rows: input output rise fall
|
|
17
|
+
* /conditional_delay N, /constraint N timing detail and checks
|
|
18
|
+
*
|
|
19
|
+
* Rows match top to bottom; the first that matches wins. Input values are
|
|
20
|
+
* `L`/`H`/`X` (don't care), one character per column, so `HHLL` covers four
|
|
21
|
+
* columns. A clocked module's columns are its inputs followed by its flags
|
|
22
|
+
* (`F0` = flag 0). Output values: `L`, `H`, `X`, `Z`, an input's name (or
|
|
23
|
+
* `~name`), `Fk` / `~Fk`, and `F+k` / `F-k`: bit k of the flags read as a
|
|
24
|
+
* binary number (F0 lowest) plus or minus one.
|
|
25
|
+
*
|
|
26
|
+
* Translation: each output of a table becomes an XSPICE `d_lut` over the
|
|
27
|
+
* columns it depends on; each flag a `d_dff` whose data input is a `d_lut`
|
|
28
|
+
* of the synchronous rows and whose set / reset inputs are `d_lut`s of the
|
|
29
|
+
* asynchronous rows; modules are flattened. Delays: a module output gets the
|
|
30
|
+
* largest rise / fall delay its `/delay` rows give it (per-path delays and
|
|
31
|
+
* conditional delays are folded into that one number); timing constraints
|
|
32
|
+
* are dropped.
|
|
33
|
+
*/
|
|
34
|
+
interface Clock {
|
|
35
|
+
input: string;
|
|
36
|
+
edge: "+" | "-" | "X";
|
|
37
|
+
flags: number;
|
|
38
|
+
sync: string[][];
|
|
39
|
+
async: string[][];
|
|
40
|
+
}
|
|
41
|
+
interface Module {
|
|
42
|
+
name: string;
|
|
43
|
+
inputs: string[];
|
|
44
|
+
outputs: string[];
|
|
45
|
+
wires: string[];
|
|
46
|
+
clock?: Clock;
|
|
47
|
+
table?: string[][];
|
|
48
|
+
/** Output -> largest rise / fall delay in seconds. */
|
|
49
|
+
delays: Map<string, {
|
|
50
|
+
rise: number;
|
|
51
|
+
fall: number;
|
|
52
|
+
}>;
|
|
53
|
+
/** Output -> largest delay into / out of high-Z (rise = turn on, fall = turn off). */
|
|
54
|
+
zDelays: Map<string, {
|
|
55
|
+
rise: number;
|
|
56
|
+
fall: number;
|
|
57
|
+
}>;
|
|
58
|
+
instances: {
|
|
59
|
+
module: string;
|
|
60
|
+
args: string[];
|
|
61
|
+
}[];
|
|
62
|
+
}
|
|
63
|
+
export interface Chip {
|
|
64
|
+
top: Module;
|
|
65
|
+
modules: Map<string, Module>;
|
|
66
|
+
}
|
|
67
|
+
/** Parse a `d_chip` model's behaviour string. Throws on anything it doesn't know. */
|
|
68
|
+
export declare function parseChip(modelText: string): Chip;
|
|
69
|
+
/** A translated chip: its subcircuit's name and pin count. */
|
|
70
|
+
export interface DChip {
|
|
71
|
+
name: string;
|
|
72
|
+
pins: number;
|
|
73
|
+
inputs: number;
|
|
74
|
+
outputs: number;
|
|
75
|
+
/**
|
|
76
|
+
* Tri-state outputs (indexes into the outputs): each has an enable pin,
|
|
77
|
+
* 1 while it drives, after the outputs in the same order.
|
|
78
|
+
*/
|
|
79
|
+
enables: number[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A d_chip model as an ngspice subcircuit named `spiceName(name)`: pins are
|
|
83
|
+
* the chip's inputs, then its outputs.
|
|
84
|
+
*/
|
|
85
|
+
export declare function dchipSubckt(name: string, modelText: string): DChip & {
|
|
86
|
+
text: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Translate every `.MODEL x d_chip (...)` in `text` into a subcircuit, and
|
|
90
|
+
* its `a...` instances in `text` into `x...` subcircuit calls. Generated
|
|
91
|
+
* subcircuits go to the top level, ahead of the rest (a model inside a
|
|
92
|
+
* `.subckt` would otherwise nest). `chips` is keyed by the lower-case model
|
|
93
|
+
* name, both as written and SPICE-safe. Models that fail to translate stay
|
|
94
|
+
* as they are, with the reason in `errors`.
|
|
95
|
+
*/
|
|
96
|
+
export declare function translateDChips(text: string): {
|
|
97
|
+
text: string;
|
|
98
|
+
chips: Map<string, DChip>;
|
|
99
|
+
errors: string[];
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* `aName [in ...] [out ...] model` -> `xaName in ... out ... model` for
|
|
103
|
+
* translated chips. Templates often list more nodes than the chip declares
|
|
104
|
+
* (an IC variant's VCC / GND at the end of the outputs, an open-collector
|
|
105
|
+
* part's outputs read back at the end of the inputs); the chip never reads
|
|
106
|
+
* them, so trailing extras are dropped. Too few nodes is an error.
|
|
107
|
+
* Tri-state outputs' enable nodes are added to `enables`.
|
|
108
|
+
*/
|
|
109
|
+
export declare function rewriteDChipInstances(text: string, chips: ReadonlyMap<string, DChip>, errors?: string[], enables?: Set<string>): string;
|
|
110
|
+
export {};
|
|
@@ -58,6 +58,8 @@ export interface MultisimDesign {
|
|
|
58
58
|
pinRemap(inst: SheetInstance, page: string, drawnKey: string): Map<string, string> | undefined;
|
|
59
59
|
/** 1-based unit (section) of the final part this drawn symbol is, if multi-section. */
|
|
60
60
|
finalUnit(inst: SheetInstance, page: string, drawnKey: string): number | undefined;
|
|
61
|
+
/** Final refdes of each `CiComponent`, one per placement (a subcircuit used twice places it twice). */
|
|
62
|
+
finalNames(): Map<string, string[]>;
|
|
61
63
|
warnings: string[];
|
|
62
64
|
}
|
|
63
65
|
export interface CiItem {
|
|
@@ -71,5 +73,7 @@ export declare function parseMultisimDesign(input: XmlInput): MultisimDesign & {
|
|
|
71
73
|
* Multisim's flattened netlist (final refdes, final pin numbers), built from
|
|
72
74
|
* the drawing ID graph. This is the scorecard's reference.
|
|
73
75
|
*/
|
|
74
|
-
export declare function flattenNetlist(design: ReturnType<typeof parseMultisimDesign
|
|
76
|
+
export declare function flattenNetlist(design: ReturnType<typeof parseMultisimDesign>,
|
|
77
|
+
/** Filled with each net name users gave (lowercase; the root sheet's first, then deeper ones) -> its pins. */
|
|
78
|
+
named?: Map<string, NetPin[]>): Map<string, NetPin[]>;
|
|
75
79
|
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multisim's simulation settings -> ngspice directives.
|
|
3
|
+
*
|
|
4
|
+
* Each sheet's `CIITDiagram` carries a `SimState` attribute: Multisim's own
|
|
5
|
+
* serialization, `KEY:type{value}` with `list` values nesting
|
|
6
|
+
* (`SIMULATION_INFO > ANALYSES > TRAN > ANALYSIS > TSTOP:double{0.5}`).
|
|
7
|
+
* Per analysis (OP, AC, TRAN, ...) it keeps the settings, an `ANALYSIS_ID`
|
|
8
|
+
* (non-zero once that analysis has results in the design) and `ASYS_OPT`,
|
|
9
|
+
* the SPICE options with an `IsEnabled` flag each. Multisim enables
|
|
10
|
+
* `rshunt=1e12` (plus `trtol=7 itl4=100 convlimit`) by default, which is
|
|
11
|
+
* why it simulates designs with floating nets that plain ngspice rejects.
|
|
12
|
+
*/
|
|
13
|
+
export interface SimStateNode {
|
|
14
|
+
key: string;
|
|
15
|
+
type: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
items?: SimStateNode[];
|
|
18
|
+
}
|
|
19
|
+
/** Parse a `SimState` string. Throws on text that isn't one. */
|
|
20
|
+
export declare function parseSimState(t: string): SimStateNode[];
|
|
21
|
+
export interface SimSettings {
|
|
22
|
+
/** `.options ...`, or undefined when none apply. */
|
|
23
|
+
options?: string;
|
|
24
|
+
/** The analysis to run (`.tran ...`, `.ac ...`, `.op`), from those Multisim has results for, plus any note on it. */
|
|
25
|
+
analysis?: string;
|
|
26
|
+
/** The other analyses Multisim has results for (KiCad's directive runs one). */
|
|
27
|
+
skipped: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Settings from a sheet's `SimState` attribute (the root sheet's speaks for
|
|
31
|
+
* the design). `digital`: the design has XSPICE event-driven parts.
|
|
32
|
+
*/
|
|
33
|
+
export declare function simSettings(simState: string, o?: {
|
|
34
|
+
digital?: boolean;
|
|
35
|
+
}): SimSettings;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multisim simulation data -> KiCad simulator (ngspice) fields.
|
|
3
|
+
*
|
|
4
|
+
* Every simulated `CiComponent` carries a *netlist template* (attribute
|
|
5
|
+
* strings[1][5]) that Multisim expands into SPICE lines:
|
|
6
|
+
*
|
|
7
|
+
* - `%p` the component name (refdes), `%m` its model's name,
|
|
8
|
+
* - `%tNAME` the node on the terminal (pin) called NAME,
|
|
9
|
+
* - `#N` parameter N of its `CiaParamList`,
|
|
10
|
+
* - `%vN?A%v:B%v;` A when parameter N is set (non-zero), else B.
|
|
11
|
+
*
|
|
12
|
+
* Models (`.SUBCKT` / `.MODEL` text) live in `CiModel` objects, referenced
|
|
13
|
+
* by the component's `Model` attribute. Their names are scoped by Multisim
|
|
14
|
+
* (`2N7002PW/NXP__MOS_ENH_N__1`), and the template references them by `%m`.
|
|
15
|
+
*
|
|
16
|
+
* KiCad mapping, from most to least native:
|
|
17
|
+
* 1. Plain resistors, capacitors and inductors use KiCad's built-in R / C / L
|
|
18
|
+
* models (or nothing at all when KiCad infers them from the value).
|
|
19
|
+
* 2. `x%p %tA %tB ... %m` parts (a vendor `.SUBCKT`) point at that
|
|
20
|
+
* subcircuit in the design's model library, with a pin map.
|
|
21
|
+
* 3. Anything else (sources, diode `.MODEL`s, inline subcircuits, ...)
|
|
22
|
+
* becomes a small wrapper subcircuit holding exactly what Multisim would
|
|
23
|
+
* netlist, so the simulation matches Multisim's.
|
|
24
|
+
* Parts with no template have no simulation model in Multisim and are
|
|
25
|
+
* excluded from simulation.
|
|
26
|
+
*/
|
|
27
|
+
import type { SchematicSheet, SchematicSymbol, SimSpec } from "../ir/types.ts";
|
|
28
|
+
import type { EwElement } from "./doc.ts";
|
|
29
|
+
import { type DChip } from "./dchip.ts";
|
|
30
|
+
export interface SpiceDesign {
|
|
31
|
+
/** Sim spec per `CiComponent` id. */
|
|
32
|
+
byComponent: Map<string, SimSpec>;
|
|
33
|
+
/** The design's model library text (models + wrappers); empty when none. */
|
|
34
|
+
library: string;
|
|
35
|
+
/** Top-level netlist lines for a KiCad text directive (couplings across parts). */
|
|
36
|
+
directives: string[];
|
|
37
|
+
warnings: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface ModelDef {
|
|
40
|
+
/** Sanitised name used in the library. */
|
|
41
|
+
name: string;
|
|
42
|
+
kind: "subckt" | "model";
|
|
43
|
+
/** Subcircuit node names, in order. */
|
|
44
|
+
nodes: string[];
|
|
45
|
+
text: string;
|
|
46
|
+
/** The model was a Multisim `d_chip`, now this subcircuit (instances need rewriting). */
|
|
47
|
+
dchip?: DChip;
|
|
48
|
+
/** Why parts of the text could not be translated (a `d_chip` left as it was). */
|
|
49
|
+
issues?: string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* KiCad leaves power symbols (`#PWR` references) out of the simulation, but
|
|
53
|
+
* Multisim simulates its supply symbols (VCC is a 5 V source to ground). For
|
|
54
|
+
* each supply net whose symbol has a model, add a one-pin, simulation-only
|
|
55
|
+
* part carrying that model, touching a copy of the net's power symbol,
|
|
56
|
+
* parked to the right of the root page.
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Where simulation-only additions go: right of everything on the page
|
|
60
|
+
* (Multisim content can sit past its edge) and of the parked extra-page
|
|
61
|
+
* sheet symbols at width + 40.
|
|
62
|
+
*/
|
|
63
|
+
export declare function parkingX(page: SchematicSheet): number;
|
|
64
|
+
export declare function supplySymbols(sheets: SchematicSheet[], page: SchematicSheet): {
|
|
65
|
+
symbols: SchematicSymbol[];
|
|
66
|
+
warnings: string[];
|
|
67
|
+
};
|
|
68
|
+
/** SPICE-safe identifier: Multisim names carry `/`, `-`, `+`, ... */
|
|
69
|
+
export declare const spiceName: (s: string) => string;
|
|
70
|
+
/**
|
|
71
|
+
* Multisim's resistor template pairs `rR1 a b 10k vresR1` with a
|
|
72
|
+
* `.model vresR1 r(TC1=.. TC2=..)` that is often empty. In PSpice mode
|
|
73
|
+
* (which the model files need) a resistor's model name goes before its
|
|
74
|
+
* value, so the pair breaks: drop the model and put its temperature
|
|
75
|
+
* coefficients on the resistor itself.
|
|
76
|
+
*/
|
|
77
|
+
export declare function inlineResistorModels(text: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* Subcircuit parameters named like functions (NI's PI block has `max=60
|
|
80
|
+
* min=-60` and uses `limit(..., min, max)`) become `p_<name>`: in the
|
|
81
|
+
* subcircuit that declares them, and in every call's `PARAMS:`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function renameReservedParams(text: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* PSpice's integral `sdt(x)`, which ngspice lacks, as XSPICE's integrator:
|
|
86
|
+
* a B source carries `x` onto a node, an `int` block integrates it (from 0
|
|
87
|
+
* at the operating point, as PSpice does), and the expression reads its
|
|
88
|
+
* output. The new lines go after the element that used it, in its scope.
|
|
89
|
+
*/
|
|
90
|
+
export declare function sdtToIntegrator(text: string): string;
|
|
91
|
+
/** A transfer function: numerator / denominator polynomials in s (index = power), times e^(-delay*s). */
|
|
92
|
+
interface Rational {
|
|
93
|
+
num: number[];
|
|
94
|
+
den: number[];
|
|
95
|
+
delay: number;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Read a PSpice `LAPLACE` transfer function, `e^(-1m*s)/(1+0.001*s)`, into
|
|
99
|
+
* a rational function of s and a pure delay. Numbers only (with SPICE
|
|
100
|
+
* suffixes); undefined for anything else (parameters, other functions).
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseLaplace(expr: string): Rational | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* PSpice's `E/G name n+ n- LAPLACE {input} {H(s)}` (no ngspice equivalent)
|
|
105
|
+
* as XSPICE: a B source carries the input onto a node, a lossless line
|
|
106
|
+
* delays it when H has an `e^(-sT)` factor, an `s_xfer` block applies the
|
|
107
|
+
* rational part, and the original E / G drives from its output.
|
|
108
|
+
*/
|
|
109
|
+
export declare function laplaceToXspice(text: string, warnings?: string[]): string;
|
|
110
|
+
/**
|
|
111
|
+
* Multisim's `adc_bridge (in_low=a in_high=b schmitt=true)`: a Schmitt input
|
|
112
|
+
* that switches high at `in_high` and low at `in_low`. XSPICE's bridge has
|
|
113
|
+
* no hysteresis (it ignores `schmitt`), so an XSPICE `hyst` block takes the
|
|
114
|
+
* input first (rising threshold `b`, falling `a`, output 0..1) and the bridge
|
|
115
|
+
* reads that at 0.5.
|
|
116
|
+
*/
|
|
117
|
+
export declare function schmittBridges(text: string): string;
|
|
118
|
+
/**
|
|
119
|
+
* A capacitor's `IC=` in a vendor model: PSpice (which these models target)
|
|
120
|
+
* holds that voltage during the bias point, and models lean on it to start
|
|
121
|
+
* their latches in a known state (Basso's PWM controllers). ngspice uses
|
|
122
|
+
* device `IC=` only with `uic`, so such latches leave the operating point
|
|
123
|
+
* without a solution. A `.nodeset` for each grounded one gives ngspice the
|
|
124
|
+
* same starting state, without holding the node once the bias point is found.
|
|
125
|
+
*/
|
|
126
|
+
export declare function capacitorIcNodesets(text: string): string;
|
|
127
|
+
/** Rewrite the Multisim-only SPICE that real models use into ngspice. */
|
|
128
|
+
export declare function ngspiceDialect(text: string): string;
|
|
129
|
+
/** A model's definition: find its `.SUBCKT` / `.MODEL` head and rename it SPICE-safe. */
|
|
130
|
+
export declare function modelDef(localName: string, textIn: string): ModelDef | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Expand a Multisim netlist template. `node` maps a terminal name to the
|
|
133
|
+
* node it should print; unknown terminals are reported via `missing`.
|
|
134
|
+
*/
|
|
135
|
+
export declare function expandTemplate(template: string, o: {
|
|
136
|
+
ref: string;
|
|
137
|
+
params: string[];
|
|
138
|
+
node: (terminal: string) => string | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* `%tNAME?%t:d%t;NAME`: the digital side of pin NAME (`d`, or `r` for
|
|
141
|
+
* bidirectional pins), which Multisim bridges to the pin's analog node
|
|
142
|
+
* with the pin's interface model.
|
|
143
|
+
*/
|
|
144
|
+
digital?: (terminal: string, prefix: string) => string;
|
|
145
|
+
/** `%sN`: the component's string parameters (MOSFET geometry, ...). */
|
|
146
|
+
strings?: string[];
|
|
147
|
+
/** Circuit parameter names (lower case): values using them get braces. */
|
|
148
|
+
circuitParams?: ReadonlySet<string>;
|
|
149
|
+
model?: string;
|
|
150
|
+
missing?: (t: string) => void;
|
|
151
|
+
}): string;
|
|
152
|
+
/** The component's netlist template (attribute strings[1][5]). */
|
|
153
|
+
export declare const netlistTemplate: (comp: EwElement) => string;
|
|
154
|
+
/** A SPICE number with an optional scale suffix / unit: `10k`, `1.5e-3`, `100nF`. */
|
|
155
|
+
export declare const isSpiceNumber: (v: string) => boolean;
|
|
156
|
+
/** The component's `CiaParamList` parameter values (`parameters`, or `strings`). */
|
|
157
|
+
export declare function componentParams(comp: EwElement, list?: "parameters" | "strings"): string[];
|
|
158
|
+
/**
|
|
159
|
+
* Circuit parameters (Multisim's per-sheet `.param`s) as one simulator
|
|
160
|
+
* directive per sheet title: names from `CircuitParamNameList`, values
|
|
161
|
+
* (numbers or expressions) from `CircuitParamValueList`.
|
|
162
|
+
*/
|
|
163
|
+
export declare function circuitParams(root: EwElement): Map<string, string>;
|
|
164
|
+
/**
|
|
165
|
+
* Multisim's interactive potentiometer: a script (in `*` comments) sets the
|
|
166
|
+
* two halves from the slider at run time; the netlisted values are 1 mOhm
|
|
167
|
+
* placeholders. Fix them at the saved setting:
|
|
168
|
+
* R1 = total * setting% (clamped like the script), R2 = total - R1.
|
|
169
|
+
*/
|
|
170
|
+
export declare function staticPot(lines: string): string;
|
|
171
|
+
/**
|
|
172
|
+
* The first `.MODEL` type in `text` that ngspice lacks, if any; or a PSpice
|
|
173
|
+
* source form it lacks: a `FREQ` response table (no exact time-domain
|
|
174
|
+
* equivalent), or a `LAPLACE` that `laplaceToXspice` couldn't translate.
|
|
175
|
+
*/
|
|
176
|
+
export declare function unsupportedModelType(text: string): string | undefined;
|
|
177
|
+
/** One simulated section of a part: its template, parameters, model and terminals. */
|
|
178
|
+
export interface SimSection {
|
|
179
|
+
template: string;
|
|
180
|
+
params: string[];
|
|
181
|
+
/** String parameters (`%sN`). */
|
|
182
|
+
strings?: string[];
|
|
183
|
+
/** The design's circuit parameter names (lower case). */
|
|
184
|
+
circuitParams?: ReadonlySet<string>;
|
|
185
|
+
model?: ModelDef;
|
|
186
|
+
/** Terminal name -> symbol pin number. */
|
|
187
|
+
pins: Map<string, string>;
|
|
188
|
+
/** Digital pins: terminal name -> its interface (A/D, D/A bridge) model. */
|
|
189
|
+
pinModels?: Map<string, PinModel>;
|
|
190
|
+
}
|
|
191
|
+
/** A digital pin's interface model and the template that instantiates it. */
|
|
192
|
+
export interface PinModel {
|
|
193
|
+
model: ModelDef;
|
|
194
|
+
template: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* A pin interface model: Multisim keeps an ideal (`*#L1`, standard XSPICE
|
|
198
|
+
* `adc_bridge` / `dac_bridge`) and a real (`*#L2`, Multisim-only code
|
|
199
|
+
* models) variant in one text; ngspice gets the ideal one.
|
|
200
|
+
*/
|
|
201
|
+
export declare function pinModelDef(id: string, text: string): ModelDef | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* An XSPICE `dac_bridge` output is an ideal voltage source, so two outputs
|
|
204
|
+
* tied together, or one driving a source (NI's pin-model demo), make a
|
|
205
|
+
* singular matrix. Multisim's real pin models have an output impedance; a
|
|
206
|
+
* 1 mOhm series resistor keeps the ideal level within microvolts while
|
|
207
|
+
* letting such circuits solve.
|
|
208
|
+
*/
|
|
209
|
+
export declare function dacOutputResistance(text: string): string;
|
|
210
|
+
/**
|
|
211
|
+
* A tri-state / bidirectional pin model with an enable pin. Multisim's
|
|
212
|
+
* `dac_hiz` turns its digital input's high-Z into the voltage that opens the
|
|
213
|
+
* output switch; an ngspice `dac_bridge` can't see high-Z (it holds its
|
|
214
|
+
* level). The variant takes an extra last node, `en` (1 while the logic
|
|
215
|
+
* drives the pin, from the translated chip), and a plain `dac_bridge` makes
|
|
216
|
+
* the switch voltage from that. `undefined` for a model without `dac_hiz`.
|
|
217
|
+
*/
|
|
218
|
+
export declare function enablePinModel(pm: PinModel): PinModel | undefined;
|
|
219
|
+
/** Split out top-level `.subckt ... .ends` blocks (with anything nested in them). */
|
|
220
|
+
export declare function hoistSubckts(text: string): {
|
|
221
|
+
body: string;
|
|
222
|
+
blocks: string[];
|
|
223
|
+
};
|
|
224
|
+
/** The models and wrapper subcircuits a design or library needs, deduplicated. */
|
|
225
|
+
export declare class SpiceLibrary {
|
|
226
|
+
private models;
|
|
227
|
+
private wrappers;
|
|
228
|
+
private names;
|
|
229
|
+
private texts;
|
|
230
|
+
readonly warnings: string[];
|
|
231
|
+
useModel(m: ModelDef): void;
|
|
232
|
+
/**
|
|
233
|
+
* A wrapper subcircuit around `lines`; identical bodies share one.
|
|
234
|
+
* Subcircuits defined inside `lines` (templates that carry their own)
|
|
235
|
+
* move to the top level: KiCad's library reader misreads the outer
|
|
236
|
+
* subcircuit's pins when another is nested in it.
|
|
237
|
+
*/
|
|
238
|
+
wrapper(base: string, nodes: string[], linesIn: string, comment: string): string;
|
|
239
|
+
/** Nodes every subcircuit shares (cross-part probes, see `Xref`). */
|
|
240
|
+
readonly globals: Set<string>;
|
|
241
|
+
text(header: string): string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Cross-part references. Multisim netlists flat, so a part's expression can
|
|
245
|
+
* read another part's current (`I(Vsensor1)`) or any net (`V(pri)`). Here
|
|
246
|
+
* each part is its own subcircuit, where ngspice would look those names up
|
|
247
|
+
* locally (and fail, or read a floating node). The part that owns the name
|
|
248
|
+
* gets a probe instead: a B source copying the current or voltage onto a
|
|
249
|
+
* `.global` node, which the expression reads.
|
|
250
|
+
*/
|
|
251
|
+
export interface Xref {
|
|
252
|
+
/** In: the part's lines moved to the top level (couplings); the part itself is excluded. */
|
|
253
|
+
moved?: boolean;
|
|
254
|
+
/** In: always build a wrapper (a probe needs one), even for an ideal R/C/L or a vendor subcircuit. */
|
|
255
|
+
wrap?: boolean;
|
|
256
|
+
/** In: node names the expressions read -> what to read instead (a pin's node or a global). */
|
|
257
|
+
nodes?: Map<string, string>;
|
|
258
|
+
/** In: device names whose current the expressions read -> the global node carrying it. */
|
|
259
|
+
currents?: Map<string, string>;
|
|
260
|
+
/** In: probes to add, onto global nodes: a pin's voltage, or a device's current. */
|
|
261
|
+
probes?: {
|
|
262
|
+
global: string;
|
|
263
|
+
pin?: string;
|
|
264
|
+
device?: string;
|
|
265
|
+
}[];
|
|
266
|
+
/** Out: whether the part became a wrapper. */
|
|
267
|
+
wrapped?: boolean;
|
|
268
|
+
/** Out: devices the wrapper defines, and the node of each pin. */
|
|
269
|
+
devices?: string[];
|
|
270
|
+
pinNodes?: Map<string, string>;
|
|
271
|
+
/** Out: names the expressions read but the wrapper doesn't define (lowercase). */
|
|
272
|
+
readsNodes?: string[];
|
|
273
|
+
readsCurrents?: string[];
|
|
274
|
+
/** Out: the wrapper is only mutual inductances (`K`) coupling inductors it doesn't define. */
|
|
275
|
+
couplings?: {
|
|
276
|
+
name: string;
|
|
277
|
+
inductors: string[];
|
|
278
|
+
k: string;
|
|
279
|
+
}[];
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* KiCad simulation spec for one part from its sections (one per Multisim
|
|
283
|
+
* section that carries a template). KiCad simulates a part as one element
|
|
284
|
+
* across all its units, so several sections become one wrapper.
|
|
285
|
+
*/
|
|
286
|
+
export declare function simSpec(ref: string, sectionsIn: SimSection[], lib: SpiceLibrary, wrapperBase?: string, xref?: Xref): SimSpec;
|
|
287
|
+
/**
|
|
288
|
+
* Build KiCad simulation specs for every simulated component of a design.
|
|
289
|
+
* `items` is the design's Ci objects by class (`collectCiItems`). The
|
|
290
|
+
* sections of one part (same circuit and refdes) share one spec.
|
|
291
|
+
*/
|
|
292
|
+
export declare function parseSpice(items: Map<string, {
|
|
293
|
+
id: string;
|
|
294
|
+
body: EwElement;
|
|
295
|
+
}[]>, circuitParamNames?: ReadonlySet<string>,
|
|
296
|
+
/** Final refdes per `CiComponent` placement (`MultisimDesign.finalNames`), for cross-part references. */
|
|
297
|
+
finals?: Map<string, string[]>,
|
|
298
|
+
/** Pins on each net users named (`flattenNetlist`), for expressions that read `V(name)`. */
|
|
299
|
+
namedNets?: Map<string, {
|
|
300
|
+
refdes: string;
|
|
301
|
+
pin: string;
|
|
302
|
+
}[]>): SpiceDesign;
|
|
303
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "multisim2kicad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Convert NI Multisim schematics, Ultiboard boards and component databases (Electronics Workbench) to KiCad",
|
|
5
5
|
"author": "Cameron Tacklind <cameron@tacklind.com>",
|
|
6
6
|
"license": "ISC",
|