Filesource with non-hardcoded file name

I want to simulate using the filesource element from ngspice. I put together a MWE in the attached file works.zip, where the name of the file containing the data is hardcoded in the .subckt definition. I would like to make it a parameter, so I can have multiple filesources reading different files without the need of creating one .subckt for each. I tried the usual way I do with numeric parameters, but it does not work; this is in the attached. fails.zip. Is it possible to have the name of the file as a parameter such that I can define it in KiCad?

fails.zip (12.3 KB)
works.zip (12.2 KB)

I don’t know how to do this in KiCad, but you can work around KiCad, by using symbolic links or copying files to a “target filename”.

I don’t understand what you mean. How can I have a single arbitrary_voltage_source.sub definition and use symlinks to have multiple voltage sources in my simulation using multiple my-source_1.txt, my-source_2.txt, my-source_....txt.

The idea was to have one filename in your spice files. call it “master-source.txt”.

And then you use your operating system (Windoze, Linux or the Fruit brand) to copy “source1.txt” to “master-source.txt” when you need it. I have not tested it. You may have trouble with file caching or it may not work at all for you. It’s just a simple idea.

Ah, but I don’t have N different simulations requiring N different waveforms, but a single simulation requiring N waveforms all simultaneously.

The string parameter is supported in a still very simple fashion only.

I have experimented a bit, using standard ngspice.

This is my working ngspice netlist example of calling the subcircuit twice with different file names (my_source2.txt is just a copy of my_source.txt):

.title KiCad schematic

.include arbitrary_voltage_source.sub

R1 Net-_R1-Pad1_ GND 4
R2 Net-_R2-Pad1_ GND 4

.param w_file="my_source.txt"
XV1 Net-_R1-Pad1_ GND twosource waveform_file=w_file

.param w_file2="my_source2.txt"
XV2 Net-_R2-Pad1_ GND twosource waveform_file=w_file2

.control
tran 200n 200u
set xbrushwidth=2
plot v(Net-_R1-Pad1_) v(Net-_R2-Pad1_) + 1
.endc

.end

I have not yet translated this into a KiCad project.

With thes special and largely untested setting it might be useful for now to avoid math characters in the file names (like -*+ etc.)

1 Like

This is the KiCad version:
arbitrary_waveforms_now_ok.7z (5.0 KB)

1 Like

This topic was automatically closed after 90 days. New replies are no longer allowed.