Electronic – LTSpice sim with PWL data from multiple files

ltspice

I want to run an LTSpice simulation with data acquired from an actual, real circuit. I have multiple files containing data from different scenarios and I need to consider them all. Is there a way to run the simulation multiple times, using data from a different file each time?

Here's a simplified schematic to illustrate what I've tried – it doesn't work (I get an error: Could not open file "c:\data" in PWL):

Schematic for illustration

The folder C:\Data\ contains ten files, named 10.txt, 20.txt, …, 100.txt. The sim works fine if I specify an actual file name in PWL file.

Any suggestions how I can make this work? It would really help my task to see the data from the various scenarious (different motor speeds) in one diagram.

Thanks a lot!

merendo

Best Answer

You can do it, but you have to adapt a bit. First, make sure that your filenames are strictly numeric and have no extensions. Windows, in particular, tends to hinde, by default, the extensions, and the filenames appear to have none, but they do.

With these in mind, suppose you have two files that you need to .step. Then rename the first 1, and the second 2. Or 314 and 666, it doesn't matter as long as they are numbers. This is needed because .step cannot perform evaluation, only substitution:

.step param x {a} {b}   ; does not work, needs numeric literals

Then you have to move them in the same folder as the schematic. If the schematic is test.asc, then a listing will show:

1
2
test.asc

This is also important, since now the source loading the files needs to be like this:

PWL file={x}
.step param x list 1 2   ; or 314 666, or ...

If there is a path before {x}, it will not work:

PWL file=/path/to/{x}   ; error: "Cannot open ''/path/to'' in PWL"
PWL file={/path/to/x}   ; also error

Now it will work:

test