I am trying to come up with a generic Python program that I can use to simulate different simple electronic circuits. The actual idea is to programmaticaly change parameters and do Montecarlo analyses.
First, I was using the PyLTSpice API but this is mainly to run an LTspice file using LTspice. I do not want to do this. I would like to work with a SPICE netlist so that we are free to do our design in whichever program we prefer.
Below you can find a netlist of a design I am currently working on:
"ExpressPCB Netlist"
"LTspice XVII"
1
0
0
""
""
""
"Part IDs Table"
"D1" "D" ""
"D2" "D" ""
"D3" "D" ""
"L1" "9μ" ""
"C1" "140μ" ""
"R1" "100m" ""
"L2" "12μ" ""
"S2" "S1" ""
"R3" "1k" ""
"V3" "PULSE(0 2 0 35u 35u 100u)" ""
"D4" "D" ""
"C2" "105μ" ""
"Net Names Table"
"N001" 1
"N003" 6
"N005" 9
"N007" 12
"0" 14
"N006" 20
"N004" 22
"N002" 24
"Net Connections Table"
1 1 1 2
1 2 2 3
1 3 1 4
1 6 1 5
1 8 2 0
2 1 2 7
2 2 1 8
2 4 1 0
3 3 2 10
3 11 1 11
3 12 1 0
4 4 2 13
4 5 1 0
5 5 2 15
5 7 2 16
5 8 4 17
5 9 2 18
5 10 2 19
5 12 2 0
6 6 2 21
6 7 1 0
7 8 1 23
7 11 2 0
8 8 3 25
8 9 1 26
8 10 1 0
Here, for instance, I would like to change the values of certain parameters and simulate this circuit, hence the netlist. How could I achieve this? Could you point me to some documentation?
Also, the netlist I have attached above is obtained when I "export" the netlist. When I "view" it, I have the following (which has the switch model etc., so I don't understand why the other one doesn't have that):
D1 N001 N003 D
D2 N003 N001 D
D3 N001 N005 D
L1 N003 N007 9μ
C1 N007 0 140μ IC=9k
R1 N001 N006 100m
L2 N006 0 12μ
S2 N004 N001 N002 0 S1
R3 N002 0 1k
V3 N002 0 PULSE(0 2 0 35u 35u 100u)
D4 N005 N004 D
C2 N005 0 105μ IC=9k
.model D D
.lib C:\Users\<user_name>\<some_dir>\LTspiceXVII\lib\cmp\standard.dio
.tran 0 {transtop} 0 {timestep} startup
.model S1 SW(Ron=1 Roff=1Meg Vt=.5 Vh=-.4)
.include trancmd.txt
.include param.txt
.backanno
.end
1 Answer 1
This first one is not a SPICE netlist; it looks like it's typical for the ExpressPCB program. The one after the edit is a SPICE netlist. The general notation for the elements is this:
- The first letter designates the element (
R
= resistor,C
= capacitor, etc) and must be followed by at least alphanumeric characters, including underscore, without spaces, making the reference designator. Various SPICE programs may accept various other characters. E.g.C1 ...
in the SPICE netlist. - Then come the pins, the original SPICE accepted only numbers but, in time, alphanumeric characters were added and, again, various SPICE programs will allow various other characters but, all the pins must be separated by spaces. E.g.
C1 N007 0 ...
. - The list of values and/or the names of the elements are next, also separated by spaces. E.g. for values:
C1 N007 0 140μ IC=9k
. Note that it is recommended that the value comes first in the list,140μ
, then the rest of the attributes and flags. It depends on what a particular SPICE program allows and what not. E.g. for names:D1 N001 N003 D
. - The SPICE directives, starting with a
.
(dot) at the beginning of the line and a keyword, representing the command, e.g..model
,.tran
. - You may also find the concatenated lines, with a
+
at the begining of the line, signaling a break of the previous active line. By active I mean that -- - comments are marked with a
*
and it's at the beginning of the line, or a;
anywhere in the middle (or at the beginning). - The typical netlist starts with a comment as the first line (e.g.
* full-wave rectifier
) and ends with the keyword.end
. Note, don't mistake for.ends
, which marks the end of a.subckt
. Anything after.end
is discarded.
Honestly, what you're asking for would require a full SPICE manual and, if the above are not enough, or if you want to know more, just use any of the plenty available SPICE resources on the web (e.g. eCircuit Center has descriptions for each elements and what they do; I am not affiliated with them).
-
\$\begingroup\$ Thank you for making the distinction between the two lists. However, I am a bit surprised because the first one is the output of "Export Netlist" in LTspice. But, yes what I would like to do is to be able to simulate circuits without a dependency for a program, so I am trying to find a complete reference. I thought maybe someone has already had this problem before. Thank you for the reference, I will check it out right away. \$\endgroup\$Guarneer– Guarneer2022年09月06日 05:45:37 +00:00Commented Sep 6, 2022 at 5:45
-
\$\begingroup\$ @Guarneer If you hover the mouse over the Tools > Export Netlist and read the description in the status bar (on the bottom right of the application window) you'll see that it says: Export a netlist for, e.g., PCB layout. If you want the SPICE netlist that is from the View > SPICE Netlist. \$\endgroup\$a concerned citizen– a concerned citizen2022年09月06日 07:12:45 +00:00Commented Sep 6, 2022 at 7:12
-
1\$\begingroup\$ @Guarneer If you're worried about compatibility across various SPICE implementations, I would go to
Tools->Control Panel->Netlist Options
and check theConvert 'µ' to 'u'
option before you begin exporting SPICE netlists out of LTspice. Some programs, like ngspice, don't like the mu symbol. SPICE3 is the base framework most SPICE programs out there are built upon, so if you follow SPICE3 rules/conventions you'll have a high likelyhood of compatibility. Manual here: bwrcs.eecs.berkeley.edu/Classes/IcBook/SPICE/UserGuide/… \$\endgroup\$Ste Kulov– Ste Kulov2022年09月06日 18:00:35 +00:00Commented Sep 6, 2022 at 18:00 -
\$\begingroup\$ @SteKulov Thank you for the reference and information. It helps a lot \$\endgroup\$Guarneer– Guarneer2022年09月07日 05:37:26 +00:00Commented Sep 7, 2022 at 5:37