11
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ What did your Linear FAE say? I'd ask them first. \$\endgroup\$ – Brian Carlton Oct 13 '11 at 0:22
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Oli Glaser Oct 13 '11 at 10:49
  • 1
    \$\begingroup\$ This question appears to be off-topic because it is not about electronic design. \$\endgroup\$ – Leon Heller Jun 18 '14 at 18:18
  • 12
    \$\begingroup\$ @LeonHeller on WHAT planet is SPICE not a part of design? \$\endgroup\$ – placeholder Jun 18 '14 at 18:21
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – placeholder Jun 18 '14 at 18:23
14
\$\begingroup\$

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:

Step Example

Result:

Graph

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:

Gain Example

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.

\$\endgroup\$
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – Joel B Oct 25 '11 at 15:41
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – user59731 Dec 5 '14 at 0:40
8
\$\begingroup\$

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>
scad3.exe -Run -b MyCircuit.asc

On Linux:

cd ~/.wine/drive_c/Program Files (x86)/LTC/LTspiceIV
wine ./scad3.exe -Run -b MyCircuit.asc
\$\endgroup\$
  • 1
    \$\begingroup\$ This is an excellent find! I'm now brainstorming how i can use this for automated design. \$\endgroup\$ – Joel B Dec 31 '14 at 17:37
  • 1
    \$\begingroup\$ @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 \$\endgroup\$ – blondiepassesby Jan 6 '15 at 11:00
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Tropical_Peach Jun 18 '14 at 20:56
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – The Photon Jun 18 '14 at 21:09
  • \$\begingroup\$ If your using matlab, they have a script to convert .raw files mathworks.com/matlabcentral/fileexchange/… \$\endgroup\$ – laptop2d Oct 6 '17 at 17:31
3
\$\begingroup\$

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.

LTSpice queue manager

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

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.

\$\endgroup\$

protected by Community May 16 '15 at 4:21

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.