|Software Tools SPICE, PCB CAD, speaker design and measurement software, calculators|
Please consider donating to help us continue to serve you.
Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
||Thread Tools||Search this Thread|
|18th August 2014, 06:15 AM||#11|
Thanks Frank I'm sure there are countless ways as you say. Trouble is, I'm at the beginner end of that spectrum when it comes to that
|18th August 2014, 07:03 AM||#12|
Join Date: Jun 2012
Location: NSW, Australia
Blog Entries: 13
I wouldn't be fussed about dividing users into a range, from beginner to that impressive sounding, "advanced" category, - LTspice is a tool, and one just learns to use it well enough to get what you want out of it; that's the way I approach everything, keep banging away at the thing until it does the job you want it to do.
I could be reasonably sharp in some areas of the program's use, and really dumb in my approach doing other bits - so long as a means of getting meaningful results is possible, that's the important thing ...
|18th August 2014, 09:46 AM||#13|
Join Date: Jul 2004
Location: Scottish Borders
I taught woodwork at school.
I found that about 20% knew how to use a hammer to knock in a panel pin.
The other 80% had to be taught how to hammer that pin in.
What did surprise me (and maybe shows I am a little bit sexist) was seeing one girl (only ever this one) know how you get that pin in straight and without bending it and NO TEACHING required.
I don't need to imagine, I know the same learning and teaching is required for all skills, even using simulators.
regards Andrew T.
Sent from my desktop computer using a keyboard
Last edited by AndrewT; 18th August 2014 at 09:49 AM.
|19th August 2014, 11:06 AM||#14|
Simulating a one transistor Amplifier.
To put what we learned so far into practice our next simple simulation will be a simple one transistor amplifier. We will explore and build on this to put into practice some of LT's more useful features.
This is the circuit we will attempt to simulate. Its the kind of thing you might draw on a scrap of paper and wonder how it might all work in practice.
Using what we have learnt, open LT and create and save a new blank file called "One transistor amp" Using the "component" symbol on the top line select and NPN transistor, click OK, and drop it onto the workspace.
Now do the same for a resistor. We need five resistors so having selected the resistor, drop it onto the workspace and then while the "resistor" is still attached to the cursor drop another four onto the workspace. Now do the same for the caps. We need two.
Information... for caps and resistors we can use the R and C symbols on the top line for ease. Also when dropping the caps first drag the attached cap to the "Rotate" symbol on the top line and click it.
It should look something like this.
Now using the scroll wheel zoom it all out a little and using the "hand" symbol, the "wire" symbol and "scissors" try and connect it all up. Remember you can use the <Edit> button to undo anything. Remember to add a ground symbol. Also you need to add a voltage supply as we have covered in the first part. You can either wire the ground line to the voltage source or do as I have done here an added a second ground directly on the voltage source. Finally we need an input source added in exactly the same way.
It should look something like this.
Now add the component values to match my final circuit diagram below.
Set the supply to 12 volts DC. Set the input source to be a 1kHz sine of 0.1 volt amplitude. For the transistor we will use one of LT's models. Hover over the transistor (a hand symbol appears) and right click the transistor. A new window appears that has a "pick new transistor" option. Click it and select the 2N2222 which is top of the list.
And you should end up with something like this.
We are now going to set some simulation options for LT because at the moment it doesn't know what to do with the circuit.
So do you remember how we right clicked the blanked workspace and selected the "edit simulation" window to appear. We do that now, and firstly select "transient" and enter a stop time of 10ms. Click OK. PLace the now attached command on the workspace. Again select edit simulation and this time select "AC Analysis" Set the options as follows, click OK and drop the new command onto the workspace.
The final simulation diagram should have all these ingredients.
Information... when you enter the edit simulation window and click an option... DC op pnt, AC Analysis etc, that option becomes the point of focus that the simulation will run. If you look at the options as they appear on the diagram you will see that the prefix is a semicolon for all inactive options and the active option changes that to a decimal point.
At this point we are ready to investigate the behaviour of the circuit under simulation and that comes next. And we are going to do some neat tricks with it......
|19th August 2014, 11:10 AM||#15|
I have attached the simulation file to the end of the above post but I would really urge anyone following this to attempt to build the simulation up from scratch as you will learn far more.
|20th August 2014, 08:43 AM||#16|
So lets begin and see what we can do with LT and see how the simulation compares with traditional circuit calculation methods.
Open the "One transistor amplifier" simulation file and right click the workspace. Select the <DC op pnt> tab and click OK. That has brought that command into focus such that when we run the simulation it will be running the DC conditions sim. So go ahead and run the simulation. As before, a window with all the circuit nodes and voltages and currents appears. We just close that as before as we are moving beyond that.
And just as in the first sims, hovering over circuit lines and nodes shows the DC conditions. We will elaborate on that and actually "click and attach" voltages to the diagram.
Notice how the emitter voltage is untidy. Because it is attached to a node we can't physically move it or rotate it with the hand symbols etc... well we can but it won't do as you want. So what we do is add a spur to the point of interest and attach the voltage to that. First though, use the scissors and cut that voltage from the diagram. Now add a spur using the "wire" tool. Drag the spur a suitable distance and left click to show where it finishes. Now right click to attach the spur and right click again to exit the "wire" tool. First few attempts take practice. Try it on various parts of the diagram. You can always undo with <edit> Now run the sim again and attach the emitter voltage to the spur.
If you alter any value and run the sim again you will see all the attached voltages change to the new values.
How do those voltages compare with basic theory. Lets see.
We have a voltage divider of 270k and 39k across 12 volts. That gives 1.51 volts at the junction of the divider. LT says nearer 1.4. Why is that ? Well the base current of our transistor is being taken from that divider and so it actually pulls the voltage down a little. We'll carry on though...
So 1.51 volts on the base. What would be on the emitter ? Well it will be 1.51 volts less the base/emitter drop of around 0.7 volts. So the emitter would be at 0.81 volts give or take. LT says 0.74 Again that is because the transistor base voltage was a little lower due to the base current of the transistor. LT has accounted for that, I haven't in the simple calculation. What about the collector voltage. Well with a calculated 0.81 volts across 1k we have a current of 0.81ma flowing.
Remember these from text book days. The current relationships in the base, emitter and collector.
Ie = Ic + Ib
Ic = Ie - Ib
Ib = Ie - Ic
Because Ib is small we can "ignore" it for this calculation and say that the voltage across the 10k collector resistor Ie * 10,000 which is 8.1 volts. If we have a 12 volt supply then the collector voltage is 12 - 8.1 which is 3.9 volts. LT says 4.58. Its in the ballpark... just.
That calculation was at the most basic level. The unknown is the transistor base current which depends on the device selected. If you tried that calculation again but this time reduced the two bias resistors by a factor of ten, then I suspect it would be a lot closer because the bias current would (relatively speaking) be a much smaller percentage of what is flowing in the bias network.
For interest you can right click the transistor and select a different device. Try a 2N3055 which is in the list of models. Just scroll down to find it. Now run the sim again and look at the voltages. The old low gain device is taking lots of base current and that is relected in the final voltages.
What is the base current ? hover over the base of the transistor and read the value off at the bottom left of the screen. Its 11.5ua for the 2N3055 vs 3.6ua for the 2N2222.
How about frequency response ? Thats interesting to look at. Again, we right click the workspace and this time select the <AC Analysis> tab to bring that into focus. (Remember to set the sim back to the 2N2222 and correct anything you altered earlier)
Run the sim and then use the probe to look at voltage on the top of R5 which is the load. You should see this.
We can see the response falls away at both top and bottom end. The lower end is caused by the coupling caps, the top end by circuit limitation.
At this point we are going to make the circuit and displayed waveforms a bit easier to use and interpret. Look on the top line and click
the <label net> symbol.
A new window opens. Type a name for the input voltage (I've used Vin) and click OK. The label is now attached to the cursor. Move it over the input line and click it to attach.
(The question marks (???) are showing because I haven't run the simulation yet having just reopened it to work on)
Now follow the same procedure and attach another "net label" to the top of R5 which is the load.
We will now run the simulation again, so make sure that AC Analysis is in focus (by opening <edit simulation> and clicking the <AC Analysis> tab). Probe the now labelled input and output of the amplifier. Probe the input first followed by the output. (That just keeps it consistent as to what we all see) and you should see the following.
This should be much easier to follow now and so we can look at what the diagram is actually telling us. Note how the top line of the scope traces now have our labels attached.
Vin is the input. Because that was probed first it has become a kind of reference. You will see it is just a line at zero db level. The voltage source in LT is perfect and so the response starts from DC and goes ever upward......
Vout is our amplifier output. We can see straight away the effect of the two coupling caps in that the response falls away at the lower end. Hover your cursor over the solid trace corresponding to the output voltage and you can read off at the bottom the amplitude as a figure of gain in db. So at midband around 1Khz we have around 18.5db gain. If we wanted the -3db point we simply follow the trace and look for a level of 15.5db. That seems to be around 6.9Hz. (the frequency is also displayed at the lower left)
Phase shift. At the right of the screen is phase angle together with a corresponding dotted line trace on the scope. That dotted line is the phase of the output (the trace is the same colour as the output showing it relates). Hover over midband (1Khz) again and you can see that the phase is showing -180 degrees. Why ? because out simple amplifier is inverting of overall phase. At the higher and lower frequencies the phase shift moves away from that ideal, at the lower end because of the caps and at the higher end because of the hf limitations of the circuit.
If you smartly double click the input voltage line you will get a single trace of 0db. The phase shift is zero from DC to infinity (because LT is perfect). Smartly double click the output and you get just the one trace.
(You can display as many points in a cirsuit as you wish and label as many nodes as you wish to make it easier to follow)
|20th August 2014, 05:31 PM||#17|
Join Date: Oct 2013
Thank you so much mooly.
Without your greatly appreciated help in other threads i woudn´t have been able accomplish any diy-audio-related project.
For the simulation of the filters i build i still use the ltspice-settings from the data you once sent me.
I´m pretty sure this thread will bring my skills to the next level.
I will follow these instructions very carefully.
Thank you for putting so much effort into helping lousy noobs like me!
|20th August 2014, 06:32 PM||#18|
Thanks for the kind words, and I'm pleased its being of some help.
We still have quite a bit more to explore with this simple one transistor circuit and that hopefully will come in the next day or two.
|21st August 2014, 11:13 AM||#19|
Distortion and FFT's.
We will now look a little further into the AC performance of our little amplifier and check out its distortion. To get you used to manipulating the commands for LT we shall look at the distortion for a frequency of 4khz. This is what we do...
Open the simulation and set the input voltage to be a sinewave of 4kHz. We can keep the amplitude the same as before, so all we need do is right click the input voltage and change the frequncy to 4000 and click OK.
Can you also make sure that you have the output line (R5) with a Vout label attached (as we covered in the previous sections). Ignore the other commands I have added for now.
For distortion measurements the <Transient> tab must be brought into focus. So right click the workspace and select <edit simulation> and click the <transient> tab. You should see the previously entered stop time of 10ms which we now need to alter. If we didn't then this is what happens. Our 10 cycles of 4kHz are over before the 10ms has run its course.
So how long do we need ? Well taking the reciprocal of 4000 gives 0.25ms, the period of one cycle. We would like to display all 10 and so we set the stop time to 2.5ms. So enter 2.5ms as the new stop time and click OK.
If you now run the sim and probe the input and then the output you should see this,
Although it looks good it tells us little of the actual distortion. LT has the wonderful ability to run a Fast Fourier Transform or FFT on any of the displayed waveforms and so that is what we are going to do next... and show the pitfalls along the way.
Setting the options for LT to do this needs care and we need basic information to set this up. One trick we can use though is to make these settings easily available to use again (which we wil cover shortly).
A standard LT command that we haven't used yet is .option plotwinsize=0 which stops LT compressing the calculations. Setting this option will give better results.
To enter a command into LT we use the .op command on the top line. Click this and enter the .option plotwinsize=0 text. (You can copy and paste it) Click OK and drop the command onto the workspace. Make sure you include the DOT. Its .option
Now we need to set the all important "Timestep" and again I must credit Bob Cordell for his excellent explanation of this (Designing Audio Power Amplifiers). The timestep relates the length of time the sample runs for, together with the frequency or period of the signal of interest. So this number needs to be altered for testing at different frequencies. I'm going to start with LT's default number of sample points which is 262144. This will all make more sense as we progress and run the simulation.
So, we take our simulation run time which is 2.5ms and we divide that by 262144. The result, 0.00953674us is the value we enter for our "Maximum Timestep".
To enter this value, open the <edit simulation> window and select the "Transient" tab. Enter the value just calculated.
We can now run our simulation and as before, look at the output voltage waveform. Notice how the sim runs slower because of the plot winsize command.
Now place your cursor into the waveform window (anywhere) and right click and select FFT from the flyout options. Goto <view> at the bottom and then select FFT. A new window opens and now you will see the 262144 number displayed. That is the default setting for current version of LT. You will see that because we probed the Vout line, that this is now automatically selected and all that remains is for us to click OK.
You should now see a new graph appear showing the FFT. (You can maximimse any individual window of course to get a better view)
Remember how I mentioned some "pitfalls" at the start of this section. Well you are looking at them... a lack of detail and resolution. There are two main causes here, firstly the FFT just hasn't run for long enough. 2.5ms doesn't allow things to stabilise. Secondly, the coupling caps are skewing the trace.
So this is what we do...
Close the FFT and scope windows and go back to the basic circuit. Alter the input voltage (right click the input) to provide more cycles. You don't need calculate anything, just make sure there are going to be enough for a longer run. We had 10, so lets make it 1000. That allows the sim to run for 250ms if we wish.
Now let us alter the <transient tab> to stop after 250ms.
We will also look at the last 20 cycles of the complete run (and ignore all up to that point) which should give more accuracy and detail. There are a couple of ways of doing this. First we recalculate the timestep. 20 cycles at 4kHz take 5 ms. (Reciprocal of 4000 times number of cycles). We divide that by 262144 and arrive at a timestep of 0.0190734us. Enter that value into the <transient> settings window.
Make sure the settings look like this.
Now run the simulation again. This time nothing seems to happen but look at the lower part of the screen. The sim is running and its progress is shown. It will take a couple of minutes to complete PC depending... When it gets to a point that would correspond to 230ms (the point we actually want to start looking from), the 'scope window opens. You can now click the output node as before and see the waveform build up as time progresses. You are lookin now at the 20ms of a 250ms run.
Again, we right click the 'scope window and select View and FFT from th flyout menus.
You should see this.
Immediately we can see there is much more resolution available. Look how the harmonic structure of the distortion appears, 2nd marmonic, 3rd and so on. (The scale is a bit unbelievable too, going below -200db)
We still have a major problem though. Although we attended to the issue of a short run time we can see the trace still slopes away hiding detail. This is caused by the time constant of the caps being small. Thats an easy fix. Go back to the asic circuit and right click them and change the value to 800,000uf (an arbitrary figure). Now rerun the sim again and look at the FFT.
I hope some of that all makes sense... its a lot to take in in one go. Importantly, I hope it shows how to set the FFT up to run correctly and how we kept improving the resolution.
|21st August 2014, 01:52 PM||#20|
Lets now look at getting a figure as a percentage for the distortion. Lets us first of all change the simulation to run a little quicker. In the <transient> tab of the edit simulation window we can change the stop time to 10ms. That will allow just 40 complete cycles to display. The Maximum Timestep is now calculated as 10ms/262144 which is 0.0381469us.
So set the following data.
We now introduce a new command that is entered using the .op button (on the top line at the right) This is a .four command which tells LT to run a distortion calculation on the FFT result. We need to specify this command exactly and so it becomes .four 4khz 10 10 v(vout) The kHz refers to our input source, the 10 means the first 10 harmonics (F, F1, F2 etc) are to be used for the calculation, and the final 10 that the last ten cycles of the run will be used. The v(vout) specifies the tag we attached to the diagram earlier. That is the point that the distortion will be calculated on.
Information... we now encounter a problem due to the timestep size calculated. To see this in action make sure your sim looks like this and then run it. Make absolutely sure the options are correct.
Information 2... if an option needs altering you can also right click the command as it appears on the diagram and that will open the appropriate window for you to alter that parameter.
You will find it almost freezes and runs incredibly slowly. Click the output node and observe the waveform and the progress at the bottom right. Thats no good so right click the circuit diagram workspace (not the traces above) and select <halt>.
So what went wrong ? Well it was the timestep setting. Lets use Windows calculator to get a few more digits.
Lets try that as a timestep. Its 0.03814697265625us Copy and paste that number into the <maximum timestep> box and rerun your sim. It should run much quicker. Now right click a blank area on the 'scope trace workspace and select <view> and then <spice error log>
Hopefully you should see this.
So as you can see, accuracy when calculating the timestep is vitally important. Actually, just adding the next digit in the sequence would have sufficed but when have the resolution... use it.
Put your own numbers in and have a go at simulating at 1kHz or 20kHz and see what you get.
|Thread Tools||Search this Thread|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Meistersinger VFA-200, A beginner’s first try in LTSpice||nattawa||Solid State||34||29th January 2016 01:58 PM|
|Need help installing LTSpice||rif||Software Tools||4||30th May 2013 01:59 AM|
|BSC with 2 way advanced PI?||F1 FAN||miniDSP||2||14th November 2011 07:26 PM|
|More advanced marketplace||peranders||Swap Meet||0||14th August 2002 08:03 AM|
|New To Site?||Need Help?|