How can I generate a .raw file for use in a 3rd party waveform viewer?

Thanks! That works even when entered on the schematic. GWAVE will read the output correctly, but the LTspice waveform reader gives a bad result. I’d love to use the LTspice viewer, at least until the KiCAD or other FOSS viewer gets similar features (subplots, waveform expressions, multiple y-axis with units, undo zoom, click and integrate, save setups… a very nice viewer), but that’s a separate topic. When using “all”, I can see all voltages and currents on the top level, but not in my subcircuit. I can call out a global net (no “/” in front) for the target of the write command instead of “all”, and this works. I’ve tried using “/” and “.” to try to write a subcircuit voltage to the .raw file, but to no avail. Also, I can’t figure out how to even view (from RAM) subcircuit nodes in the KiCAD built-in viewer (which show all top level V and I by default, independent of the “write” argument, as I would expect). Any hints on how to view/plot subcircuit nodes and currents? My subcircuit is text-only. Thanks again!

Full netlist:

.title KiCad schematic
.include “/home/steve/MyKiCAD/SPICE_TRIAL/LTspiceX.lib”
I101 Net-C101-Pad2 +5V 5
R102 +5V Net-C101-Pad2 1
C101 +5V Net-C101-Pad2 100n
I102 Net-C101-Pad2 /IN+ 25m
R103 /IN+ Net-C101-Pad2 1
C102 /IN+ Net-C101-Pad2 100n
I103 Net-C101-Pad2 /IN- dc 0 PWL(0 20m 100n 30m 250n 30m 350n 20m)
R104 /IN- Net-C101-Pad2 1
C103 /IN- Net-C101-Pad2 1n
XU101 /IN+ /IN- +5V Net-C101-Pad2 OUT tlv3201aidck
C104 OUT Net-C101-Pad2 15p
R101 Net-C101-Pad2 0 1m
.save @r102[i]
.save @c101[i]
.save @r103[i]
.save @c102[i]
.save @r104[i]
.save @c103[i]
.save @c104[i]
.save @r101[i]
.save V(+5V)
.save V(/IN+)
.save V(/IN-)
.save V(0)
.save V(GND)
.save V(Net-C101-Pad2)
.save V(OUT)
.tran 10p 450n
.options reltol=1E-4 abstol=1E-13 vntol=1E-7 chgtol=1E-15
.options plotwinsize=0
.options numdgt=7
.options trtol=1
.control
write /home/steve/MyKiCAD/TB_TLV3201.raw all
.endc
.end

.subckt tlv3201aidck +IN -IN +V -V OUT
R_delay post N001 R=(tp-tr/2)/Cpd/1
C_power_diss post 0 {Cpd}
R_out_hi OUT +V R=(1-V(out_bin))r_off+r_out_high
B3 +V -V I=abs(I(V1))V(+V,-V)
R1 +in_r +IN 10
R3 -in_r -IN 10
R4 +V -V R=Vdd/Idd
D1 -in_r +V BAV99HM
D2 -V -in_r BAV99HM
D3 +in_r +V BAV99HM
D4 -V +in_r BAV99HM
C1 -in_r -V {Cin}
B10 0 pre I=0.5+0.5
tanh(Avol
(V(+in_r,-in_r)/V(+V,-V)+hyst*(V(post)-0.5)))
R5 pre 0 1
B6 0 out_bin I=0.5+0.5tanh(Arf(V(post)-0.5-((0.632-0.5)2(V(pre)-0.5))))
R8 out_bin 0 1
R_out_lo OUT -V R=V(out_bin)*r_off+r_out_low
V1 N001 pre 0
C2 +in_r -V {Cin}
C3 out_bin 0 {Cn}
C4 pre 0 {Cn}

  • hyst is hysterisis normalized to VDD
  • Arf is gain to control rise and fall time (emperical)
  • Subtract 2.6pF for diodes from input capacitance to get Cin
  • Cn is C_Norton - delay from this should be enough to help convergence, but not enough to affect circuit significantly
    .param hyst=240u r_out_low=56.3 r_out_high=42.5 r_off=10MEG Avol=100k Arf=150 tp=55n tr=5.2n Cpd=5p Vdd=5 Idd=65u Cin=1.4p Cn=200p
    .MODEL BAV99HM D(Is=1.7962E-9 N=1.7555 Rs=.55113 Ikf=72.153E-3 Cjo=1.3304E-12 M=.11174 Vj=4.1020 Bv=100 tt=11.542E-9)
    .ends tlv3201aidck

The KiCad-generated netlist contains several .save statements. These are the vectors saved and printed with the ‘write … all’ command. No other vectors are saved during the simulation.

You may try to add an additional ‘.save all’ statement to the ‘Custom’ window. This would add to the already given .save statements.

Works to produce subcircuit results for the .raw file, but I still can’t see any subcircuit signals in the KiCAD viewer from RAM. Adding “.save all” on the schematic also works for the .raw file, but it will not appear in the “Simulation settings/Custom” window along with the rest of the schematic dot commands. The “control… .endc” lines are also invisible in “Custom”, but show up in the netlist and are executed. This invisibility-in-Custom appears to be insensitive to the order of appearance on the schematic. The “.save all” does not cause the previous auto-generated “.save” lines to be deleted from the netlist (which is benign). Placing “.save all” in both the schematic and the Custom window causes it to appear in the netlist twice (and it still works for the .raw file).

.title KiCad schematic
.include “/home/steve/MyKiCAD/SPICE_TRIAL/LTspiceX.lib”
I101 Net-C101-Pad2 +5V 5
R102 +5V Net-C101-Pad2 1
C101 +5V Net-C101-Pad2 100n
I102 Net-C101-Pad2 /IN+ 25m
R103 /IN+ Net-C101-Pad2 1
C102 /IN+ Net-C101-Pad2 100n
I103 Net-C101-Pad2 /IN- dc 0 PWL(0 20m 100n 30m 250n 30m 350n 20m)
R104 /IN- Net-C101-Pad2 1
C103 /IN- Net-C101-Pad2 1n
XU101 /IN+ /IN- +5V Net-C101-Pad2 OUT tlv3201aidck
C104 OUT Net-C101-Pad2 15p
R101 Net-C101-Pad2 0 1m
.save @r102[i]
.save @c101[i]
.save @r103[i]
.save @c102[i]
.save @r104[i]
.save @c103[i]
.save @c104[i]
.save @r101[i]
.save V(+5V)
.save V(/IN+)
.save V(/IN-)
.save V(0)
.save V(GND)
.save V(Net-C101-Pad2)
.save V(OUT)
.save all
.tran 10p 450n
.options reltol=1E-4 abstol=1E-13 vntol=1E-7 chgtol=1E-15
.options plotwinsize=0
.options numdgt=7
.options trtol=1
.control
write /home/steve/MyKiCAD/TB_TLV3201.raw all
.endc
.end

I think this is what I found from KiCad 5.0 - which not allow you to run customized run. It seem to replace it own .control version, or run twice.

NGspice does indeed support subcircuit probing in the .raw file, as mentioned above. Access to the subcircuit results is a feature that seems to not yet be implemented in the KiCAD waveform viewer though. There is a work-around if you need to see a subcircuit voltage in KiCAD. You can reference the sub-circuit node in a top-level behavioral source to see it. Not very convenient, but it works.

No, I also consider /IN+ and /IN- to be on the top level. KiCAD just uses the “root” symbol for non-global labeled nets at the top level. I am also talking about the comparator subcircuit (tlv3201aidck) as “the subcircuit”. For example the net “/XU101/pre” is a net that can only be accessed (so far as I know) in the KiCAD waveform viewer by calling it out in a behavorial source at the top level. I suspect that this is a KiCAD bug or missing feature, not a bug with NGspice. The subcircuit is fully saved in the .raw file using the procedure Holger outlined above, and can be fully viewed with “load …” and “plot all” in standalone NGspice as well as in Gwave through its GUI.

1 Like

What issues are there ?
The .raw file is readable, and fairly simple.
FWIR, Entry count, Signal Name headers, and then repeated Time & node sets records
We’ve created .raw from logging SW, and loaded them into LTSpice as a viewer.

If you can check & edit it until it works, and submit a bug report, that would help fix this.

The .raw file is actually a binary file, and the format of the NGspice .raw file is not what is expected by the LTspiceviewer. I was thinking I might convert the NGspice .raw file to ASCII that can then be read by the LTspice Viewer. Of course it would be nice to have a more direct route. Here is a previous discussion of the issue:
https://sourceforge.net/p/ngspice/discussion/133842/thread/41eb3917/

The LTspice viewer won’t even import ASCII directly. I’ll need to create PWL sources in an LTspice netlist, one for each net I want to plot. Each PWL source is just pointing to a result from NGspice in the proper ASCII format. It will then be necessary to actually run a (trivial) simulation in LTspice so that I can plot the output of each PWL source. I’ll see if I can script this flow. I think it will be worth the effort, as the LTspice viewer is very full featured, and I’ve used it for years. I can’t find another free .raw viewer that comes close to it, but I’m open to suggestions.

Ah, ok, the LTSpice files we saw generated/read, were all always ASCII.

Google did find this, that sounds applicable ?

Should be easy to then export that as LTSpice-Ascii-raw ?

1 Like

Yep - I’ll check it out, thanks. I’ll try to make a script.

Add

set filetype=ascii

to .spiceinit or spice.rc

The ascii raw file will be read directly by LTSPICE. On Windows you do:
Right-click on xxx.raw -> Open with -> Spice Simulator (aka LTSPICE) -> Plot settings -> visible traces -> yourvector

3 Likes

Thanks Holger! There’s one tiny extra step required if you have non-global labelled nets on the top level of the KiCAD schematic. You must open the text .raw file and delete or replace the “/” that KiCAD uses to denote the “root” schematic in the net names. Otherwise the LTspice viewer will complain and won’t plot those nets.

Also: The LTspice viewer won’t accept “+” , “-”, or “~” in any net name. It will load the .raw file, and you can look at all the nets except the illegally named ones.

I’ve noticed that I have to run a simulation twice to get the ASCII .raw file to update correctly. The .raw file is re-written with every simulation run, but it rewrites a duplicate of the previous version after a netlist change until the second time it runs. I’ve been varying the simulation duration by a factor of 10 to check this out. If I delete the raw file and run the sim, then the resultant .raw file is correct the first time.

FYI: Simulation of circuit with power nodes

There also a JKWaves allow to plot .raw file directly

In fact adding a .control section to the eeschema generated netlist may raise some caveats.

It is largely untested in this environment (shared ngspice, simulation called by bg_run in a second thread) and thus bears some risk due to the multithreading involved. It may happen that the write command starts before the simulation has finished, then writing the old data.

It might be much better that the eeschema interface handles all the issues directly and care for thread synchronization. This has to be coded into eeschema. Therefore it is necessary to notify the KiCad developers and add these issues to the wishlist.

2 Likes

I’ve reported this as a wishlist item at:

To finally answer the OPs question (how to add writing a raw file?):

Add the following .control section as a text box to the Eeschema window:

.control
set controlswait
write /home/steve/MyKiCAD/TB_TLV3201.raw all
.endc

set controlswait will delay all commands following until the simulation (started automatically in a second thread by internal command bg_run) has finished.

1 Like