# LTSpice Automation

I have a battery-powered boost converter and I'm attempting to measure the maximum input (battery) voltage droop under various load conditions of high current draws (different duty-cycles/periodicities) in addition to over several battery types (various voltages/internal resistances). Since I'm simulating such a (relatively) large amount of operational time the simulation files are getting pretty substantial, not to mention they take a while. I would like to automate LTSpice so that I can change component values programatically and rerun simulations and capture data (values of things like voltage or current). I know that:

• WAV files can be used to input/output data from the program
• The program can be run from the command line

So far my best option seems to use a combination of these two options along with my own code/script in a fashion that accomplishes my goals, but I just wonder if there is a better way already out there.

Has anyone automated LTSpice or know if there has been any kind of automation API written for it (either by the manufacturer or by 3rd parties)?

Ideally I would like to have a solver, such that I gave it the desired parameters and it tried various component values until it found the "optimal" solution to my constraints.

• What did your Linear FAE say? I'd ask them first. – Brian Carlton Oct 13 '11 at 0:22
• Do you know about the .STEP and .PARAM commands? Not sure if it would achieve exactly what you want, but I will post an answer with a couple of examples if you are interested. – Oli Glaser Oct 13 '11 at 10:49
• This question appears to be off-topic because it is not about electronic design. – Leon Heller Jun 18 '14 at 18:18
• @LeonHeller on WHAT planet is SPICE not a part of design? – placeholder Jun 18 '14 at 18:21
• You'll find that Monte Carlo options are perfectly suited to this. You can Schmoo different parameters and it also can display the variations. LT-Spice MAY have disabled this by SPICE natively supports this. Start there – placeholder Jun 18 '14 at 18:23

Running a simulation multiple times and changing multiple component values is a bit more involved than just changing one (which is not so bad)

Here is the concept for changing one value:

• Add a .param statement using the SPICE directive icon on the far right, e.g. for a resistance value .param X=R
• To use it you would enter {x} into the resistor value, then include e.g. .step param X 100 500 50 to step the value between 100 and 500 in increments of 50.

Example:

Result:

For multiple values, the only way I found to work was using a list of values for X, and using the table statement. This is probably best explained with an example (reading the help for the commands used will probably be helpful here). But note that the table command syntax is in the form table(index, x1, y1, x2, y2, .... xn, yn), takes index as input and returns an interpolated value for x=index based on the supplied x,y pairs.

In one of my simulations I needed to perform 12 simulations whilst changing 3 different component values, here are the commands:

.step param X list 1 2 3 4 5 6 7 8 9 10 11 12
.param Rin1 = table(X, 1, 1,1p, 2, 1p, 3, 1p, 4, 4478, 5, 4080, 6, 3400, 7, 2200, 8, 1p, 9, 1p, 10, 1p, 11, 1p, 12, 1p)
.param Rin2 = table(X, 1, 4997, 2, 4997, 3, 4997, 4, 499, 5, 897, 6, 1577, 7, 2777,  8, 4997, 9, 4997, 10, 4997, 11, 4997, 12, 4997)
.param Tval = table(X, 1, 56, 2, 56, 3, 27, 4, 1G, 5, 1G, 6, 1G, 7, 1G, 8, 1G, 9, 330, 10, 330, 11, 120, 12, 120)
.param Kval = table(X, 1, 316, 2, 147, 3, 147, 4, 6340, 5, 6340, 6, 6340, 7, 6340, 8, 6340, 9, 6340, 10, 825, 11, 825, 12, 316)


Result:

Hopefully you get the idea, you could maybe produce a script that would produce the necessary SPICE commands when you fill in your desired values. Or just create a template (e.g. I just copied and pasted the above into a few different simulations and changed the values)

If the above doesn't do what you want, then maybe look at something like NI's multisim (I think it has some batch simulation options, although I'm not sure how useful they are) It may also be helpful to ask on the LTSPice forum and see if someone knows of a better way of doing things.

• This is not as clean as I'd like it to be, but for free software, I can only be grateful that they threw me a bone. Thanks for demonstrating this technique. This will definitely get me closer to what I'm looking for. – Joel B Oct 25 '11 at 15:41
• Thank you, this helped me figure out my simulation. Now I have to figure out how to put a legend on the plot so I can tell which simulation is which. – user59731 Dec 5 '14 at 0:40

I think it is actually possible to run LTSpice from the command line and have it run a transient simulation:

On windoze:

cd <wherever LTSpice is installed on your computer>


On Linux:

cd ~/.wine/drive_c/Program Files (x86)/LTC/LTspiceIV

• This is an excellent find! I'm now brainstorming how i can use this for automated design. – Joel B Dec 31 '14 at 17:37
• @JoelB : yes, that's also what I use it for. There are unfortunately a few shortcomings: 1) Unlike in the GUI, the solver runs single-threaded, so it's slower 2) You don't have any "progress report" like in the GUI – blondiepassesby Jan 6 '15 at 11:00

LTSpice can be run in batch mode with the -b command line switch.

From the LTSpice Help file:

-b: Run in batch mode. E.g. "scad3.exe -b deck.cir" will leave the data in file deck.raw

How to read and interpret the .raw output is left as an excercise for the reader.

Also note, among the command line switches:

-ascii: Use ASCII .raw files. Seriously degrades program performance.

• How exactly do I run it though? In command line mode that is. I'm not usually a windows user and have no idea how to do this on a windows machine. – Tropical_Peach Jun 18 '14 at 20:56
• I've never run it that way. You'll have to try it out for yourself. You can either open a command window ('cmd.exe' on the Start menu) or run it from whatever language you are using to sequence your tests. – The Photon Jun 18 '14 at 21:09
• If your using matlab, they have a script to convert .raw files mathworks.com/matlabcentral/fileexchange/… – Voltage Spike Oct 6 '17 at 17:31

Did you already check at "LTSpice Queue Manager"? (The link redirects to my own website where you can download the software but I'm not its author, who originally shared the program on a forum that is today closed. Sharing it through my website is a way to revive it).

This tool has been of much help to me in the past. You can prepare many simulation files and run them in a queue fashion.

• Queuing is not automation. – Harry Svensson Mar 16 '18 at 19:26
• If the automation you need is queuing, it certainly is! This addresses OP's problem directly. – Daniel Mar 16 '18 at 19:34
• If this is closed-source software that you didn't write, I would expect users to be understandably leery of running it. – Dave Tweed Mar 18 '18 at 11:21

If it just has to be LT Spice and you can't get past the GUI I would recommend the script program AutoIt. I've used it to automate some critical Windows applications which were lacking active-x-DDE-COM.dll-whatever. You can set it up to wait for files, push windows buttons, menuitems, call programs with arguments, etc.

Have a look at:

http://www.autoitscript.com/site/

http://www.autoitscript.com/forum/

I would go for Winbatch if you want to pay for a script program.