Thanks to Mike for picking up the idea brougth up by Martin Griffith
in the thread "Dumb SPICE question" in the newsgroup
sci.electronics.design.
The free SPICE software SwitcherCADIII can be dowloaded from
http://www.linear.com/software/ .
If you already have SwitcherCADIII, you must upgrade to the latest
version 1.13p. The man who manage and do the work on SwitcherCADIII
is Mike Engelhardt working for Linear Technology.
Best Regards
Helmut
Appendix:
---------
This is the summary of the threads regarding SwitcherCADIII
implementation of the .wave command.
The original threads can be found in "Dumb SPICE question"
in the newsgroup sci.electronics.design.
General decription from Mike:
-----------------------------
I just made it up an implemented it in LTspice/
SwCADIII (I'm the author of the program) The syntax
means create a file with absolute path "C:\output.wav"
and digitize nodes left and right into with 16 bit
resolution and a sample rate of 44000 samples per
second. You just place the command on the schematic
as a SPICE directive. You can read the .wav file
into another simulation by giving a voltage source a
value of wavefile=C:\ouput.wav instead of something
like 5V or PULSE(...) By default it will pick the
first channel which is called channel 0. To pick the
second channel set the value of a voltage source to
wavefile=C:\ouput.wav chan=1
Mor e details about the syntax from Mike:
-----------------------------------------
To play a .wav file, give a voltage source a value of
wavefile="C:\input.wav" To play the right channel of a stero
track, add chan=1 to the above. Then to save a nodes as .wav
file, add the spice directive
.wave C:\ouput.wav 16 44K V(left) V(right)
Additional explanations
-----------------------
Example for the values of voltage sources for left and rigth cahnnel.
Value of first source:
wavefile="c:\test.wav" chan=0
Value of second voltage source:
wavefile="c:\test.wav" chan=1
The parameter chan=0/1 uses left/rigth channel of the .wav file.
Define the simulation time as usual.
.TRAN x
The x is the time in seconds.
The 16 mean 16 bits. 1 to 32bits are allowed. The 44K means
sample 44,000 times per second. Each node name puts another
channel in the file.
You can also play it as .wav file into your sound
card, but beware that most PC codes won't, e.g.,
play more than 16 bits, so you have to be careful
to pick something you can play, like 8 or 16 bits and
mono or stereo, while the .wav format and LTspice
can do 1 to 32 bits and 65536 channels.
The syntax allows double quotes around the file name
so you can use names that include spaces. You don't
need absolute path names, but can default to computing
path path off the the source schematic(or netlist).
Example: .wave "C:\out put.wav" 16 44K V(left) V(right)
Example from Mike Engelhardt:
-----------------------------
It generates a .wav file in SPICE.
*
V1 left 0 sine(0 1 1K)
V2 right 0 sine(0 1 2K)
.wave C:\output.wav 16 44K V(left) V(right)
.tran .1
.end
If you use a file name with a space in it, use double quotes.
You do need the latest version of SwCADIII, though. Look on
the "help about" box. Check if you see today's date.
My example:
-----------
It reads the left and rigth channel of a .wav file into the simulation
and feed the signals to two filters. The filtered output is written
again to a two channel(stereo) .wav file.
First put two voltage sources on the schematic and then add an
R/C-filter to each source.
The value(V) of the voltge sources have to be changed to
wavefile="c:\test.wav" chan=1
wavefile="c:\test.wav" chan=0
You must name the output nets of the R/C-filter e.g. left and rigth.
Then add with the .op button the two SPICE commands:
.wave C:\ouput.wav 16 44K V(left) V(right)
.TRAN 1
That's all. Let's RUN.
This examples plays and records 1 second of your .wav file.
>The free SPICE software SwitcherCADIII can be dowloaded from
>http://www.linear.com/software/ .
>If you already have SwitcherCADIII, you must upgrade to the latest
>version 1.13p. The man who manage and do the work on SwitcherCADIII
>is Mike Engelhardt working for Linear Technology.
>
>Best Regards
>Helmut
I have just started using this and I really never cease to be amazed at the
speed and versatility of thing !
Chris
Just a question:
How to write a model for spice that can read data from a file and write data
in a file in a specific format the same that is done in SwitcherCad? Is
there any document on this matter?
Regards
"Helmut Sennewald" <HelmutS...@t-online.de> wrote in message
news:acnndh$mik$05$1...@news.t-online.com...
Are you referring to SC or generic spice? In standard spice you can not
do this. Sone vendor specific spices have additional features e.g.
PSpice can read stimulus files and output in excel format. SwitcherCad's
output file is propriety. i.e. no f'ing idea what it is.
In a certain sense, you can cheat a bit with a "clever" minipulation of
bog standard XSpice to construct a model that uses a table as a transfer
function, which would technically be in a seperate file:-)
The method is shown here:
http://www.anasoft.co.uk/EE/index.html at the XSpice core link.
What specifically do you have in mind?
Kevin Aylward
ke...@anasoft.co.uk
http://www.anasoft.co.uk
SuperSpice, a very affordable Mixed-Mode
Windows Simulator with Schematic Capture,
Waveform Display, FFT's and Filter Design.
> ...
> Just a question:
> How to write a model for spice that can read data from a file and write
data
> in a file in a specific format the same that is done in SwitcherCad? Is
> there any document on this matter?
>
Hello mansourahmadian,
I hoped that Mike from LT would answer this question, but he didn't.
Here is my proposal for dealing with data files in SwitcherCADIII.
Reading data:
-------------
The only way I know is defining a PWL source in a text file.
Then put on your schematic the command line .include filename.txt .
If you give the PWL source symbolic net names in the text file,
you can easily refer to those in the schematic.
Writing data:
-------------
The output of the nets is always written to a name.raw file.
Normally, only the header is in ASCII and the data is in binary format.
If you select ASCII data type, then all the data will be in ASCII.
As I know, Mike has not disclosed his binary and ASCII-format.
I hope that Mike will tell us whether we can rely on the now
implemented but undocumented ASCII-format for the future or not.
The workaround:
---------------
Mark in the menu "Control Panel->Compression" the field ASCII
data file. Now the result file is completely written in ASCII format.
You can dramatically reduce the amount of data in this filewith
the .SAVE command. This allows you to save only the data you
really need.
The structure of the ASCII output file:
---------------------------------------
...
Flags: real forward -> only one real value for each net
or ( complex forward -> real value followed by imaginary value )
No. Variable: Number of different variables
No. Points: Number of data sets(points)
Offset: ???
Variable: Names of variables
Values: Datas start here
0 value(variable-0)
value(variable-1)
...
1 value(variable-0)
value(variable-1)
...
2
In case of "Flags:complex" there are two values seperated by ",".
I don't know what the parameter "forward" means, but I have never
seen any other value like "backward".
Now you know the structure and it is time to write a program in C,
Basic or whatever to read the data from this output file.
I tried this with a quick and dirty C-Programm and it is really
working.
Hope that helps.
Best Regards
Helmut
Appendix: Two examples of .raw output files
==========================================
Real value example, e.g. .TRAN analysis
---------------------------------------
Title: * D:\Daten\Ltc_spice\Audiotransformer\Draft1.asc
Date: Tue May 28 22:23:59 2002
Plotname: Transient Analysis
Flags: real forward
No. Variables: 13
No. Points: 272
Offset: 0.0000000000000000e+000
Command: Linear Technology Corporation LTspice
Variables:
0 time time
1 V(n002) voltage
2 V(n001) voltage
3 V(in) voltage
4 V(out) voltage
5 V(gen) voltage
6 I(L2) device_current
7 I(L1) device_current
8 I(R4) device_current
9 I(R3) device_current
10 I(R2) device_current
11 I(R1) device_current
12 I(V1) device_current
Values:
0 0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
0.000000000000000e+000
1 8.000000000000002e-011
9.370536034181940e-007
6.296525675779597e-008
9.413196062763501e-007
5.812177546873475e-008
1.005309649148692e-006
-9.686962578122449e-011
1.066500714539029e-010
-1.066500714539026e-010
Complex value example, e.g. .AC analysis:
-----------------------------------------
Title: * D:\Daten\Ltc_spice\Audiotransformer\Draft1.asc
Date: Tue May 28 22:34:29 2002
Plotname: AC Analysis
Flags: complex forward
No. Variables: 13
No. Points: 100
Offset: 0.0000000000000000e+000
Command: Linear Technology Corporation LTspice
Variables:
0 frequency frequency
1 V(n002) voltage
2 V(n001) voltage
3 V(in) voltage
4 V(out) voltage
5 V(gen) voltage
6 I(L2) device_current
7 I(L1) device_current
8 I(R4) device_current
9 I(R3) device_current
10 I(R2) device_current
11 I(R1) device_current
12 I(V1) device_current
Values:
0 1.000000000000000e+000,0.000000000000000e+000
4.604347189496316e-005,6.479207647324860e-003
5.069219417698089e-005,7.133372846434286e-003
1.250431657549015e-001,6.074257169367056e-003
4.679279462490544e-005,6.584651858247034e-003
2.000000000000000e+000,0.000000000000000e+000
-7.798799104150899e-008,-1.097441976374505e-005
3.124928057075164e-003,-1.012376194894510e-005
-3.124928057075164e-003,1.012376194894510e-005
7.798799104150907e-008,1.097441976374506e-005
-7.798799104150901e-008,-1.097441976374505e-005
3.124928057075165e-003,-1.012376194894510e-005
-3.124928057075164e-003,1.012376194894510e-005
1 1.109090909090909e+001,0.000000000000000e+000
5.629046339144184e-003,7.142027413701604e-002
6.197376051614750e-003,7.863113392024604e-002
I have had a look at the SC ASCII format, and it appears to be a
completely standard Spice output file, with one extra header line named
"offset". Indeed, even the node names and device currents are in the
same order as the standard spice output. The actual names for currents
have been cleaned up a bit, as the standard spice ones are a bit obtuse
e.g. "qn1#emitter voltage" and "@qn1[ri] voltage", the last one
referring to a current not a voltage!.