Measuring currents in eeschema/ngspice

Looking up how to measure currents using Eeschema/Ngspice I found the following link in this forum:


If I look at what is shown there, it should be possible to add things like i(r1), i(vin)…
Unfortunately I can’t figure out how I can add these signals to the list shown when clicking on Add Signals.
Should I place an extra directive (something equivalent to .probe i(r1) ) in the schematic?

kind regards,
Hugo

You may send commands from eeschema to ngspice for measuring currents and calculation power etc. using the ngspice .control section.

However, currently it is not possible to get these data back into eeschema for adding them to the list of plottable vectors. This is due to some limitations of the current eeschema-ngspice interface.

There has been some discussions about this issue at https://lists.launchpad.net/kicad-developers/msg42430.html. Somebody still has to take care to implement this feature into eeschema.

There’s this proposal:

I tried adding a wrdata command to the control section:
wrdata ‘ldf.dat’ @v1[i]
unfortunately that results in an error : no such vector “@v1[i]”
even though the display-command shows this vector.
How should I proceed?

thanks in advance and kind regards,
Hugo

As far as I can tell, KiCad already adds the currents for all components in the signal list. Like “I(R1)” or “Id(D1)” etc… So you just select it and click OK to have it plotted. Is this not what you need?

[quote=“holger, post:2, topic:20002”]
However, currently it is not possible to get these data back into eeschema for adding them to the list of plottable vectors. This is due to some limitations of the current eeschema-ngspice interface.
[/quote]W

What kymatica writes seems to contradict the quote from holger above and what I experience myself.
Because of the above, I’m trying to get a file with the data using wrdata in the control section, however
wrdata ‘ldf.dat’ @v1[i]
unfortunately results in an error : no such vector “@v1[i]”
even though the display-command shows this vector.

Maybe I’m misunderstanding your question. But see attached simple test circuit. As you see, the currents for R and V shows up in the list and can be plotted as expected.

Which Kicad version are you using? Could you attach the project files, I’d like to open them in my Kicad version. Thanks in advance and kind regards.

This is a build of the most recent git master branch, with some custom patches applied. However, I’m 100% sure this worked also in the 5.1 version.

Project attached: SimCrash.zip (239.5 KB)

Did you consider Adding wrdata statement in a schematic, e.g. setting
set controlswait
at the beginning of your .control section?

I tried out your schematic and I do see indeed the currents presented in the list of plotable signals.
But I don’t see what you are doing differently from what I do in my schematic.
I have attached therefore my circuit for which the currents don’t show up and which doesn’t produce the current vector asked for in the wrdata statement
rc.zip (2.8 KB)

Did you consider Adding wrdata statement in a schematic , e.g. setting
set controlswait
at the beginning of your .control section?

Yes I did, the strange thing is it works for other vectors such as V(/out) but not for @v1[i].
I attached my schematic in my reply to kymatica’s post.

kind regards,
Hugo

Maybe you have to tell ngspice that it should save the @v1[i] vector.
This may be done by adding
.save @v1[i]
right before the .control statement.

Maybe you have to tell ngspice that it should save the @v1[i] vector.
This may be done by adding
.save @v1[i]
right before the .control statement.
I tried that but it doesn’t help. It’s really strange as putting the following control-section
to the schematic (with or without your suggestion):

*.save @v1[i]
.control
set controlswait
*.save @v1[i]
listing
display
wrdata ‘ldf.dat’ @v1[i]
.endc

Gives the following output:

Circuit: KiCad schematic
Background thread stopped with timeout = 0
Prepared to start controls after bg_run has finished
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+02

No. of Data Rows : 81
KiCad schematic
1 : kicad schematic
2 : .global gnd
4 : r1 /out /in 15k
5 : c1 /out 0 2.2n
6 : v1 /in 0 dc 0 ac 1
7 : .save @r1[i]
8 : .save @c1[i]
9 : .save @v1[i]
10 : .save v(/in)
11 : .save v(/out)
12 : .ac dec 20 100 1meg
13 : .control
14 : set controlswait
15 : save @v1[i]
16 : listing
17 : display
18 : wrdata ‘ldf.dat’ @v1[i]
19 : .endc
21 : .end
Here are the vectors currently active:
Title: KiCad schematic
Name: ac3 (AC Analysis)
Date: Wed Nov 27 13:54:54 2019
/in : voltage, complex, 81 long
/out : voltage, complex, 81 long
@c1[i] : current, complex, 0 long
@r1[i] : current, complex, 0 long
@v1[i] : current, complex, 0 long
frequency : frequency, complex, 81 long, grid = xlog [default scale]
Error: no such vector @v1[i]
(END)

And the vector @v1[i] is indeed not available for displaying nor writing to ldf.dat

kind regards,
Hugo

comparing my schematic with the one of kymatica I noticed he is doing a transient analysis and I am doing an AC analysis. Therefore I changed my voltage source to a sine-source and the analysis to a transient analysis and to my surprise the currents became available! Now the question is of course why the choice of analysis results in this behaviour?

kind regards,
Hugo

Sounds like a good bug catch to me. Easy to overlook since most people don’t look at currents during AC analysis. For example, I’ve been doing a bunch of AC lately to test a model I made and I never noticed the currents were missing from the list.

I made a bug report: