Spice simulation

winetricks trick: load only one download at a time. if a dll or something messes up wine, you know which one did it...

Now you tell me, uncle Jed!

Anyway, Dimitri from Russia told me to change my comctl32 dll setting from native to builtin (that's in winecfg -> Libraries). Sure enough, that fixed my problem.

Thanks guys.
 
Last edited:
Simulating THD

I'm looking at the total harmonic distortion results from my simulation and am a little perplexed. I'm getting really high numbers at low frequencies... like over 70% THD. THD is around 0.5% at 1kHz. So I tried the "audioamp.asc" example that keantoken referenced, and I get similar results. I'm using a 100Hz signal in a 100ms transient analysis for a full 10 cycles.

Any ideas why the results are like this? Should they be?

In the audioamp.asc example circuit that keantoken posted, what is the purpose of V4? Is it just measuring point A? Is that the same as replacing V4 with a wire, and adding a net labeled "A" to the top of R14?

On another topic...

Uncle Jed recommended the Linux gEDA suite for schematic/simulation/layout in an older thread. Is this still a good recommendation? Any comments? I've searched diyaudio and have seen people mention it, but would like to hear something from people who actually use it.

Does gEDA have an autoplace / autorouter? I thumbed through the docs and didn't see any mention of that.

many thanks
 
V4 is used to measure the open-loop gain of the amplifier. There are two loopgain.asc files in the examples folder, which will tell you how to do this.

Attached is the setup I use for testing my amplifiers. This turns off compression, doubles bit accuracy, uses Gear integration method for RF accuracy, and sets the number of samples automatically depending on FFT size, test frequency, and number of cycles to run. It will also automatically make a THD measurement, as long as the output node on your circuit is named Vout.

Copy the simulation commands and input sources to your amplifier (after deleting the commands you've already put there). It is likely you'll have questions, no need to refrain.

If this doesn't fix your problem, we will need to see the schematic...

- keantoken
 

Attachments

  • ampsim2.asc.txt
    3.3 KB · Views: 139
I will try to work on what you posted yet tonight, but it will be later. I doubt it's a settings issue.

The circuit I'm using is the one you mentioned earlier in this thread. It's the audio amp in the example / education files that came with the LTspice install. The settings I'm using are the same as in the example. The only thing I changed was the frequency to 100 Hz.

What kind of THD do you get in your circuit simulations?
 
Try the attached, at 100Hz you should measure 0.290691% THD

As well as adding the parameters suggested by keantoken I also reduced the input level to 0.75V (1V runs this design into clipping) and changed the input source to use the frequency specified by the parameters. Look in the spice error log once you have run the simulation - THD is the sum of the first 9 harmonics.
 

Attachments

  • audioamp.asc.txt
    5.7 KB · Views: 61
the gEDA suite is made up of several different programs, that use a common set of files. the documentation you read is probably for the schematic editor gschem, which produces the schematic, then there are tools for converting the schematic into a netlist, and then the PCB layout editor uses the netlist. there are auto placement and autorouting commands within the PCB program. unfortunately, if you have a very large schematic with several hundred wires, and most of them terminate at a 196 pin BGA chip, it seems like the autorouter gives up without trying... i haven't tried NgSpice yet to try an analog simulation of an amp, but apparently it can do several different common types of simulation, including Verilog digital sims. but these tools aren't as simple and seamless as some of the windows based packages out there, and require a steep learning curve. for instance, if you plan on making a PCB from a schematic, you must take meticulous care to properly label wire names, pin names and numbers, and pre specify device footprints correctly. in a project i'm working on i had to create new device footprints and schematic symbols using text files and scripts. once past the learning curve, and with proper entry of data into the schematic, things tend to go rather smoothly after that...

i'm still using LTSpice for analog sims. setting the correct options, such as turning off data compression, will allow you to get the distortion figures down. if you run a plot on just a pure sine wave across a resistor, you can see how the compression has a big effect on distortion. with compression on, for instance, a sine wave source can show 2nd and 3rd harmonics as bad as -30 to -50db (depending also on time step settings and how many cycles the sim is run) if you're not thinking about it, you'll probably think something is seriously amiss with your design, that is until you measure the voltage source and find it's almost as badly distorted as your circuit output.

I'm looking at the total harmonic distortion results from my simulation and am a little perplexed. I'm getting really high numbers at low frequencies... like over 70% THD. THD is around 0.5% at 1kHz. So I tried the "audioamp.asc" example that keantoken referenced, and I get similar results. I'm using a 100Hz signal in a 100ms transient analysis for a full 10 cycles.

Any ideas why the results are like this? Should they be?

In the audioamp.asc example circuit that keantoken posted, what is the purpose of V4? Is it just measuring point A? Is that the same as replacing V4 with a wire, and adding a net labeled "A" to the top of R14?

On another topic...

Uncle Jed recommended the Linux gEDA suite for schematic/simulation/layout in an older thread. Is this still a good recommendation? Any comments? I've searched diyaudio and have seen people mention it, but would like to hear something from people who actually use it.

Does gEDA have an autoplace / autorouter? I thumbed through the docs and didn't see any mention of that.

many thanks
 
Last edited:
If you think compression is causing false distortion readings, you can check by taking an FFT of the input voltage. This trace must be directly across the voltage source pins and the source cannot have an internal series resistance.

This can be done automatically by adding the following command:

.four {freq} V(Vin)

Where Vin is the input node of your amplifier. The input source should not have internal series resistance and the negative terminal should be connected directly to ground. Rarely will this not be the case.

- keantoken
 
Thanks again for the replies. They were very illustrative and saved me a week of reading. I was able to figure out that my big issue was the wrong <frequency> in the .four command. I did not change it to 100 from 1k. By only changing that value my THD went from 73.4% to 0.621%. It only makes sense.

Adding the options:

.options plotwinsize=0
.options method=gear
.options numdgt=7

Lowers the simulated THD by about half to 0.317%.

I really appreciate the examples that show how to compute the fourier parameters based on frequency, and especially learning that you can use the variable {Freq} inside the signal generator. That is really cool and simplifies much.

I have one question, why is FFT=32786? I would have expected a power of two which would be 32784.

Uncle Jed, thank you for the great synopsis of gEDA. It does not sound like the tool set for me. After a bit of research, I picked DIPtrace. Something about its interface works the way I think. I've been able to enter some schematics and get it through PCB -- nothing as complex as the 196-pin BGA. But if I have to lay out a 196-pin BGA, all I can say is someone's got the wrong man for the job! ::)

What I want to avoid is drawing the schematic twice. DIPtrace can import netlists, and LTspice can export them. Unfortunately, I haven't been able to get much of that to work. Period.
 
Allright, making good progress now & have a question about the pearl script ltspdisto. It's not what you're thinking, I was able to finally get it to work. The big trick there was to run the script from where my netlist/schematic were located. But now that I have all the data, how to interpret the results?

I was hoping to get a %THD plot vs frequency but that's nowhere to be found. I see voltage plots and such. My disto.thd and disto.raw have all the FFT point values but not the THD. I know that the plot viewer can draw expressions using data from the raw file. Is there a simple expression that will draw the THD in % as a function of frequency (or whatever the disto variable I choose)?

thanks
 
The LTSpice plotter is missing some important features. There are some 3rd party tools which can do some of these things, but I could never get them to work. You will have to ask on the yahoo group about that.

I used Openoffice/excel to make THD plots, but I had to input the data manually.

- keantoken
 
I just thumbed through Helmut's pearl source and it looks like the percent THD is written into the raw file as V(THD). I checked the value that's written against what I get when I run .four at that same frequency and they are the same.

So the %THD data are there, but the Y-axis units are shown as Volts (mV in my case). I have searched and can't find a way to change the displayed units to a percentage. Is there a way to do this?

The easiest way is to edit the raw file, and the line that has the V(THD) in it:

0 F1 param
1 V(THD) voltage
2 V(AC_1) voltage
3 V(DC) voltage


Alas, I tried a variety of different things and can't make % appear on the Y axis.

Any ideas? If there's a way to put % on the axis, it would be easy to modify the script to write it automatically.

I just noticed that all of the Voltage values are most likely percentages. Look at V(k1). That's the normalized voltage at the fundamental frequency. It's always 100.
 
Hey Buckeye, here is OS's Mongrel AX simulation file. Questions about the amplifier design should be asked in this thread:

http://www.diyaudio.com/forums/solid-state/169590-mongrel-supersym-ii.html

This is a thoroughly modern amplifier. When I wondered if there was a better example for you to use, rather than mostly obsolete designs, this instantly came to mind.

- keantoken
 

Attachments

  • mongrel_AX1.3.asc.txt
    15.9 KB · Views: 99
Yeah, that's a fine amp design. I'm mostly looking for quick & simple, while learning to use LTspice. Hate to say it but as for modern goes, class D is where it's at. Did anyone see the article about class D in the IEEE Spectrum January issue? The Spectrum staff picked class D as one of the top 11 technologies of the decade for their 2011 New Year issue. Class D is up there on the pedestal with technologies like smartphones, social networking, VOIP, LED lighting, etc. Here's the link: IEEE Spectrum 1/2011.

Anyway, my simulations are working fine and I'm using Helmut's disto Pearl script. There are some other very cool THD analysis tools on the LTspice Yahoo group.

But you are right. The amp I'm working with is not audiophile quality. I call it the Cheap150, and It's got a bit of distortion. The key word here is Cheap, not audiophile. I posted some info about my simulation results in the forum where this amp concept was first described. It's here:

http://www.diyaudio.com/forums/solid-state/103632-cheap-100-150-watt-amp-12.html#post2469455
 
Yeah, that's a fine amp design. I'm mostly looking for quick & simple, while learning to use LTspice. Hate to say it but as for modern goes, class D is where it's at. Did anyone see the article about class D in the IEEE Spectrum January issue? The Spectrum staff picked class D as one of the top 11 technologies of the decade for their 2011 New Year issue. Class D is up there on the pedestal with technologies like smartphones, social networking, VOIP, LED lighting, etc. Here's the link: IEEE Spectrum 1/2011.

Anyway, my simulations are working fine and I'm using Helmut's disto Pearl script. There are some other very cool THD analysis tools on the LTspice Yahoo group.

But you are right. The amp I'm working with is not audiophile quality. I call it the Cheap150, and It's got a bit of distortion. The key word here is Cheap, not audiophile. I posted some info about my simulation results in the forum where this amp concept was first described. It's here:

http://www.diyaudio.com/forums/solid-state/103632-cheap-100-150-watt-amp-12.html#post2469455

Hi Buckeye,

You're right about class D - it is the wave of the future and in fact it is here now for many important applications, including HT receivers and professional audio amplifiers. It has a ways to go for high-end audio, but great progress has been made in that department as well, especially in the last 5 years.

You may be interested in the class D section in my book, which goes from the basics to some in-depth technical discussion of the various types of class D amplifiers. There are four chapters devoted to class D:

28 - Class D amplifiers
29 - Class D design issues
30 - Alternative class D modulators
31 - Class D measurement, performance and efficiency

The detailed table of contents can be found on my web site at CordellAudio.com - Home.

Cheers,
Bob