Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How to write a Diractive to LTSpice using MATLAB

636 views
Skip to first unread message

Abdul Moiz

unread,
Dec 21, 2015, 7:41:13 AM12/21/15
to
Hello Ali,

I am also working on automating the LTSpice call via MATLAB. Could you please give me an idea how to do this or suggest any good article.

Best Regards,
Abdul Moiz

Ali Shahabi

unread,
Dec 21, 2015, 10:50:10 AM12/21/15
to
Hi Abdul,

You can automate LTSpice using the command prompt or MATLAB. In MATLAB, you need to write the following line in your script to run your LTSpice simulation from MATLAB:

system(scad3.exe YourFileName.asc -run -b)

(Note that for the above command, you need to copy the "scad3.exe" file and "lib" folder from the main root of LTSpice to where you simulation file is. Alternatively, you can write some commands to let MATLAB know where scad3.exe is located. )

Instead of "YourFileName" you need to put the name of the file you want to simulate. This command envokes LTSpice and run the simulation silently and saves the data in a .raw file. Then using the following script, you are able to import you data into MATLAB:

http://www.mathworks.com/matlabcentral/fileexchange/23394-fast-import-of-compressed-binary-raw-files-created-with-ltspice-circuit-simulator/content/LTspice2Matlab.m

This was a quick summery on how you automate LTSpice. I hope it helps you.. However, as to my previous question of writing a directive in LTSpice using MATLAB, I still don't know how to do it! I couldn't find the answer. I was hoping that someone here had any idea about it.

Regards,

Felipe Garza

unread,
Jun 2, 2016, 10:57:19 AM6/2/16
to
"Ali Shahabi" <asha...@crimson.ua.edu> wrote in message <n3g66f$fac$1...@newscl01ah.mathworks.com>...
> I'm working on automating LTspice using MATLAB (I could call LTSpice from MATLAB and run my simulation.) However, I need to add a directive in LTSpice from MATALB (I need this for a general-purpose automation. I can add the directive to the simulation file myself, but in that case whenever the simulation file is changed, the directive should be add again manually. I want an automated way.) For example, I need to add the following directive to my LTSpice simualtion file using MATLAB so that I don't have to add a directive manually whenever the simulation file is changed:
>
> .inc setup.txt
>
> I would be thankful if anyone could help me. thanks.

Ali, I have not tried adding spice analysis lines (such as .tran .ac) in a text file, but I have added parameter definitions (such as .param PARAM1=X ) in a .txt file which I include in my ltspice schematic using (.inc filepath/filename.txt). I am able to run my simulation manually just fine. Thus, the work around for updating a spice directive in LTSPICE would be to write a script in matlab that updates a .txt document (which I'm assuming is possible) and then call LTSPICE from MATLAB as described by the other answers in this thread. The .txt file you are updating in matlab should be included in your LTSPICE schematic.

Hope this helps,
Felipe

Zack Sheffield

unread,
Jul 21, 2017, 1:11:16 PM7/21/17
to
"Ali Shahabi" wrote in message <n3g66f$fac$1...@newscl01ah.mathworks.com>...
> I'm working on automating LTspice using MATLAB (I could call LTSpice from MATLAB and run my simulation.) However, I need to add a directive in LTSpice from MATALB (I need this for a general-purpose automation. I can add the directive to the simulation file myself, but in that case whenever the simulation file is changed, the directive should be add again manually. I want an automated way.) For example, I need to add the following directive to my LTSpice simualtion file using MATLAB so that I don't have to add a directive manually whenever the simulation file is changed:
>
> .inc setup.txt
>
> I would be thankful if anyone could help me. thanks.

LTspice files are simple text files... Open on up in a text editor to see for yourself.

For .asc schematics, just append a line to the .asc file with the following format:
TEXT <xcoord> <ycoord> <justification> <fontsize> !<spice_directive>
where <xcoord> and <ycoord> are the x and y coordinates where you want to place the line in the schematic,
<justification> can be one of the following: Left Right Center Top Bottom Invisible,
<fontsize> is an array index (0-based) into the following array: [0.625, 1.0, 1.5, 2, 2.5, 3.5, 6, 7],
<spice_directive> is your ".inc setup.txt"

Note that if you want to just include a comment it is a semicolon ; instead of an exclamation mark !

Alternatively, you can just generate a .net from your .asc (using the -netlist command line switch), which is also just a simple text file, and add the your spice directive before the .end.

If you don't want to change the original file, then just copy it to a file with a different name and modify that one instead.

The best way to figure this out is to play with the text version of the .asc and then open it in LTspice and see what happens. Note that I'm using LTspiceXVII, not IV. There may be some differences but I doubt it.

amatt...@gmail.com

unread,
Mar 18, 2019, 2:22:40 PM3/18/19
to
Here is a Medium article that describes how to do it.

https://medium.com/@amattmiller/running-ltspice-from-matlab-630d551032cc
0 new messages