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!
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).
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.
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.
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
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.
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.
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.