0

I am running an operating point simulation in ngspice and I get DC currents through capacitors.

The netlist I am using is programmatically generated. Some components from a circuit were deleted which results in dangling components/nets that do not form a closed circuit.

I am using the following netlist:

.title test_netlist
C1 GND /AFE/SRP 100n
C2 GND /AFE/SRN 100n
C3 /AFE/SRN /AFE/SRP 100n
C4 /AFE/Vbat_filtered GND 2.2u
C6 /AFE/REGOUT GND 4.7u
C9 GND /AFE/VC0 1u
R1 /AFE/SRP_Conn /AFE/SRP 100
R10 Net-_E2-Pad2_ Net-_D14-Pad1_ 100
R11 GND Net-_D13-Pad1_ 1Meg
R12 GND Net-_D14-Pad1_ 1Meg
R13 Net-_D13-Pad1_ /Gauge/SMBD 100
R14 Net-_D14-Pad1_ /Gauge/SMBC 100
R15 GND /AFE/AFE_Inputs/tmp 900
R16 /AFE/AFE_Inputs/tmp /AFE/VC0 100
R2 /AFE/SRN_Conn /AFE/SRN 100
R3 +BATT Net-_D12-Pad1_ 10k
R4 Net-_D12-Pad1_ /AFE/Vbat_filtered 100
R5 /AFE/REGOUT /AFE/SDA 10k
R6 /AFE/REGOUT /AFE/SCL 10k
R9 Net-_E1-Pad2_ Net-_D13-Pad1_ 100
Rshunt1 /AFE/SRN_Conn /AFE/SRP_Conn 0.25m
V1 +BATT /AFE/V3 dc({Vcell})
V2 /AFE/V3 /AFE/V2 dc({Vcell})
V3 /AFE/V2 /AFE/V1 dc({Vcell})
V4 /AFE/V1 GND dc({Vcell})
.param Rs1 = 900
.param Rs2 = 100
.param Rs3 = 1
.param Vcell=3.2
.options savecurrents
.op
.end

Running this in ngspice gives:

Note: can't find the initialization file spinit.
******
** ngspice-38 : Circuit level simulation program
** The U. C. Berkeley CAD Group
** Copyright 1985-1994, Regents of the University of California.
** Copyright 2001-2022, The ngspice team.
** Please get your ngspice manual from http://ngspice.sourceforge.net/docs.html
** Please file your bug-reports at http://ngspice.sourceforge.net/bugrep.html
** Creation Date: Oct 29 2022   15:21:43
******
ngspice 1 -> source test.cir

Note: No compatibility mode selected!

Circuit: test_netlist

ngspice 2 -> run Doing analysis at TEMP = 27.000000 and TNOM = 27.000000

Warning: singular matrix: check nodes /afe/regout and /afe/regout

Note: Starting dynamic gmin stepping Trying gmin = 1.0000E-03 Note: One successful gmin step Trying gmin = 1.0000E-04 Note: One successful gmin step Trying gmin = 1.0000E-05 Note: One successful gmin step Trying gmin = 1.0000E-06 Note: One successful gmin step Trying gmin = 1.0000E-07 Note: One successful gmin step Trying gmin = 1.0000E-08 Note: One successful gmin step Trying gmin = 1.0000E-09 Note: One successful gmin step Trying gmin = 1.0000E-10 Note: One successful gmin step Trying gmin = 1.0000E-11 Note: One successful gmin step Trying gmin = 1.0000E-12 Note: One successful gmin step Trying gmin = 1.0000E-12 Note: One successful gmin step Warning: singular matrix: check nodes /afe/regout and /afe/regout

Warning: Dynamic gmin stepping failed Note: Starting true gmin stepping Trying gmin = 1.0000E-03 Warning: singular matrix: check nodes /afe/regout and /afe/regout

Warning: Further gmin increment Trying gmin = 5.6234E-03 Warning: singular matrix: check nodes /afe/regout and /afe/regout

Warning: Further gmin increment Trying gmin = 8.6596E-03 Warning: singular matrix: check nodes /afe/regout and /afe/regout

Warning: Further gmin increment Trying gmin = 9.6466E-03 Warning: singular matrix: check nodes /afe/regout and /afe/regout

Warning: Further gmin increment Trying gmin = 9.9105E-03 Warning: Further gmin increment Trying gmin = 9.9775E-03 Warning: Further gmin increment Trying gmin = 9.9944E-03 Warning: Further gmin increment Trying gmin = 9.9986E-03 Warning: Further gmin increment Trying gmin = 9.9996E-03 Warning: Last gmin step failed Warning: True gmin stepping failed Note: Starting source stepping Supplies reduced to 0.0000% Trying gmin = 1.0000E-02 Note: One successful gmin step Trying gmin = 1.0000E-03 Note: One successful gmin step Trying gmin = 1.0000E-04 Note: One successful gmin step Trying gmin = 1.0000E-05 Note: One successful gmin step Trying gmin = 1.0000E-06 Note: One successful gmin step Trying gmin = 1.0000E-07 Note: One successful gmin step Trying gmin = 1.0000E-08 Note: One successful gmin step Trying gmin = 1.0000E-09 Note: One successful gmin step Trying gmin = 1.0000E-10 Note: One successful gmin step Trying gmin = 1.0000E-11 Note: One successful gmin step Trying gmin = 1.0000E-12 Note: One successful gmin step Note: One successful source step Supplies reduced to 0.1000% Supplies reduced to 0.0000% Warning: source stepping failed Note: Transient op started Note: Transient op finished successfully

No. of Data Rows : 1 ngspice 3 -> print all +batt = 1.280000e+01 /afe/afe_inputs/tmp = 0.000000e+00 /afe/regout = 0.000000e+00 /afe/scl = 0.000000e+00 /afe/sda = 0.000000e+00 /afe/srn = 0.000000e+00 /afe/srn_conn = 0.000000e+00 /afe/srp = 0.000000e+00 /afe/srp_conn = 0.000000e+00 /afe/v1 = 3.200000e+00 /afe/v2 = 6.400000e+00 /afe/v3 = 9.600000e+00 /afe/vbat_filtered = 5.759280e-03 /afe/vc0 = 0.000000e+00 /gauge/smbc = 0.000000e+00 /gauge/smbd = 0.000000e+00 @c1[i] = 0.000000e+00 @c2[i] = 0.000000e+00 @c3[i] = 0.000000e+00 @c4[i] = 1.266757e-03 @c6[i] = 0.000000e+00 @c9[i] = 0.000000e+00 @r1[i] = 0.000000e+00 @r2[i] = 0.000000e+00 @r3[i] = 1.266757e-03 @r4[i] = 1.266757e-03 @r5[i] = 0.000000e+00 @r6[i] = 0.000000e+00 @r9[i] = 0.000000e+00 @r10[i] = 0.000000e+00 @r11[i] = 0.000000e+00 @r12[i] = 0.000000e+00 @r13[i] = 0.000000e+00 @r14[i] = 0.000000e+00 @r15[i] = 0.000000e+00 @r16[i] = 0.000000e+00 @rshunt1[i] = 0.000000e+00 net-d12-pad1 = 1.324349e-01 net-d13-pad1 = 0.000000e+00 net-d14-pad1 = 0.000000e+00 net-e1-pad2 = 0.000000e+00 net-e2-pad2 = 0.000000e+00 v1#branch = -1.26676e-03 v2#branch = -1.26676e-03 v3#branch = -1.26676e-03 v4#branch = -1.26676e-03 ngspice 4 ->

There should not be any current flowing. There are no closed paths across the voltage sources. Still I get about 1.2 mA in my simulation.

I am trying determine the operating point of the dangling nets to check what voltages the deleted components might see. (Note: I am aware that this is a pointless exercise with the netlist provided. This is a heavily stripped down netlist to make it manageable to analyse it manually.)

For example: There is a dangling net that goes as follows: V1 --- R3 --- R4 --- net:/AFE/Vbat_filtered

So obviously /AFE/Vbat_filtered should be at 12.8 instead of 5.759280e-03.

How do I make this work? Is inserting very large resistors to ground at all dangling nets the only solution? I really wanted to avoid the additional work.

Also: I remember that there was an option to automatically insert very large resistances between all nets and ground, but I can't find it any longer.


Edit 1 In case anybody else encounters this problem:

I narrowed the issue down to the following failing netlist:

.title test_netlist
V1 +BATT GND dc(12.8)
R3 +BATT Net-_D12-Pad1_ 10k
R4 Net-_D12-Pad1_ /AFE/Vbat_filtered 100
C4 /AFE/Vbat_filtered GND 2.2u

C6 /AFE/REGOUT GND 4.7u R5 /AFE/REGOUT /AFE/SDA 10k R6 /AFE/REGOUT /AFE/SCL 10k

.options savecurrents .op .end

The issue seems to be the existence of the components R5, R6, and C6, which have no connection to any source.

So removing all components that have no path to a source other than through ground might solve this issue.

ocrdu
  • 9,195
  • 22
  • 32
  • 42
ARF
  • 5,199
  • 9
  • 43
  • 71
  • 2
    You are auto-generating all this stuff. Why don't you remove them before sending them off to a Spice? The math for it is relatively easy. In the Advanced Series in Electrical and Computer Engineering, Vol. 5, there is something called "Graph Theory and its Engineering Applications" by Wai-Kai Chen. It gets into these things pretty quickly. And it's not hard, either. Or look up *node-edge incidence matrix* and *nullspace*. – periblepsis Mar 20 '23 at 18:46
  • I think you're looking for .options rshunt=1t. That adds a 1 terraohm resistor to ground at every node. You can of course change the value to whatever you want. Check Section 15.1.2.1 of the ngspice manual for more info. – Ste Kulov Mar 21 '23 at 06:33
  • @periblepsis Thanks for the references. My issue was that I was not really clear on what exactly needed to be remove from the graph. I think I figured it out though. – ARF Mar 21 '23 at 19:03
  • @SteKulov Thanks for the hint. The option did not help but I think I figured it out now. – ARF Mar 21 '23 at 19:04
  • Hmmm...that's weird. rshunt should solve that issue. You shouldn't need a source to run a simulation. Your test netlist fails for me too, but adding .options rshunt=1t fixes it right away. If you don't have XSPICE extensions installed, rshunt won't work. I know people on Linux have an issue with that when using KiCad due to problems with dependencies. On Windows, this issue doesn't exist so rshunt should always be available. – Ste Kulov Mar 21 '23 at 19:31
  • 1
    @SteKulov You are right! rshunt works now for me too. I have no idea what happened when I first tried it. Thank you so much! This is the kind of low-effort solution I was looking for. :-) If you want, make it an answer so I can accept it as the solution. – ARF Mar 22 '23 at 07:40
  • Nice! Glad it works now. OK, I'll add the answer. – Ste Kulov Mar 23 '23 at 04:29

2 Answers2

1

How do I make this work? Is inserting very large resistors to ground at all dangling nets the only solution? I really wanted to avoid the additional work.

Also: I remember that there was an option to automatically insert very large resistances between all nets and ground, but I can't find it any longer.

Yes, adding large resistances to ground on the problematic nodes is the easiest way around this problem. The quick-n-dirty way to do this is to include the following SPICE directive in your netlist:

.options rshunt=1t

This will insert a 1 TΩ (1 teraohm) resistor to ground at every node in the circuit (see ngspice manual section 15.1.2.1 for more details). You, of course, can adjust the value to what best suits your needs. I chose 1t above because that is the reciprocal of the default GMIN value of 1p. For those unfamiliar, GMIN is a built-in constant for adding leakage conductances across reverse biased PN junctions to aid in convergence.

ngspice does not (yet) include a topology checker to detect floating nodes. If it did (or when the feature is added), it could then only apply these extra resistances to the floating nodes like LTspice does by default. Until then, we'll have to settle with this shotgun approach.

Hearth
  • 32,466
  • 3
  • 55
  • 133
Ste Kulov
  • 4,439
  • 2
  • 10
  • 22
0

One thing you can do is suggested is put in a large resistor, this is dependent on what your design can tolerate as far as leakage currents through that resistor as suggested above.

Another thing you can do is insert small capacitors if you only need an AC connection and a leakage current is undesirable. There are other spice packages that allow you to attach very small capacitors to all nodes to help with numerical stability

Voltage Spike
  • 82,181
  • 41
  • 84
  • 220