LTSpice OpAmp / Diode clipping simulation
-
- KVRist
- Topic Starter
- 48 posts since 26 Dec, 2009 from France
Hi everyone,
While still learning about filters and stuffs on the DSP side, I am trying to get a better understanding of electronics and circuits.
I am trying to model in LTSpice a simple 2 diodes clipping system, like in the first diagram here :
Source : http://www.bteaudio.com/articles/TSS/TSS.html
So I modeled it in LTSpice like this :
When I run the simulation with the sine @ 500mV, there is little effect. If I push it to 800mV, I get some clipping, but with some problems (explained just below). First off, here is the result of the simulation :
while the BTE website tells me I should get that :
Sorry by advance if the questions are stupid, but I searched a lot online and I haven't found clear answers (possibly because my understanding of electronics is still not so good... )
1/ First problem : There is a DC voltage which is shifting the curve to the positive values. Where exactly does it come from, and how can I remove it ? (basically, I am eventually willing to use SPICE simulations in a light manner in order to generate some soft clipping curves etc for future C++ implementation)
2/ Bigger problem : the result is obviously different from the link above (BTE website). The diodes and resistors are the same, so I am quite sure it is not coming from there. However, my analysis tends to point me to the opamp.
I have to confess having only a limited understanding of opamps, so I might have wired it incorrectly. I used a LT1001 opamp randomly, as I am not sure which one I should put. I found a PSPICE model of an opamp used in this kind of pedals but I would have to convert it (another problem lol) to the LTSpice format...
Basically, is the difference indeed coming from the opamp choice ? If so, how can I actually choose a "working" opamp when I just have the schematics of a circuit ? I mean, the differences between my results and the website are rather important, so how can I choose the opamp (or its settings) to at least come closer to the expected result ?
Thanks a lot by advance for enlightening me
All the best,
V.
While still learning about filters and stuffs on the DSP side, I am trying to get a better understanding of electronics and circuits.
I am trying to model in LTSpice a simple 2 diodes clipping system, like in the first diagram here :
Source : http://www.bteaudio.com/articles/TSS/TSS.html
So I modeled it in LTSpice like this :
When I run the simulation with the sine @ 500mV, there is little effect. If I push it to 800mV, I get some clipping, but with some problems (explained just below). First off, here is the result of the simulation :
while the BTE website tells me I should get that :
Sorry by advance if the questions are stupid, but I searched a lot online and I haven't found clear answers (possibly because my understanding of electronics is still not so good... )
1/ First problem : There is a DC voltage which is shifting the curve to the positive values. Where exactly does it come from, and how can I remove it ? (basically, I am eventually willing to use SPICE simulations in a light manner in order to generate some soft clipping curves etc for future C++ implementation)
2/ Bigger problem : the result is obviously different from the link above (BTE website). The diodes and resistors are the same, so I am quite sure it is not coming from there. However, my analysis tends to point me to the opamp.
I have to confess having only a limited understanding of opamps, so I might have wired it incorrectly. I used a LT1001 opamp randomly, as I am not sure which one I should put. I found a PSPICE model of an opamp used in this kind of pedals but I would have to convert it (another problem lol) to the LTSpice format...
Basically, is the difference indeed coming from the opamp choice ? If so, how can I actually choose a "working" opamp when I just have the schematics of a circuit ? I mean, the differences between my results and the website are rather important, so how can I choose the opamp (or its settings) to at least come closer to the expected result ?
Thanks a lot by advance for enlightening me
All the best,
V.
You do not have the required permissions to view the files attached to this post.
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
You may indeed want to use another AOP, something like a TL071 which is used quite in a lot of basic circuits (IIRC).
-
- KVRist
- 53 posts since 4 Sep, 2014
If I can find some time a little later to play around with LTSpice I'll add some thoughts then, but real quick - the turn-on voltage of a diode is around 0.7 V, or 700 mV, so you're not going to get a lot of clipping action until then. DC bias is removed by a highpass filter, so a series cap with shunt resistor with a low RC value following the circuit would do the trick.
-
Deranged Tapir Deranged Tapir https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=293257
- KVRer
- 1 posts since 30 Nov, 2012
Opamps are active devices, so plugging it in wouldn't hurt.
You have to supply positive voltage to pin on the top, and negative voltage to the pin on the bottom, in equal amounts. The datasheet says the LT1001 has an absolute max of +/- 22V, but since you're building a clipping circuit, you shouldn't need a ton. I'd probably try 15 volts (30 total) and see how it goes.
You have to supply positive voltage to pin on the top, and negative voltage to the pin on the bottom, in equal amounts. The datasheet says the LT1001 has an absolute max of +/- 22V, but since you're building a clipping circuit, you shouldn't need a ton. I'd probably try 15 volts (30 total) and see how it goes.
- KVRAF
- 2110 posts since 5 Oct, 2015 from Swedish / Living in Hong Kong
Most OpAmp's are supplied with a positie and negative DC. If you check many data sheets you can see it. This will determine the swing which basically mean top to bottom for a sine tone. You might want to add a large capacitor in series with the generator to make sure the signal from the generator is pure sine signal. All real generators normally have such DC blocking capacitor built in. That capacitor should be fairly large. Try something like 1uF. If the capacitor is too small it might start working as a high pass filter.
Win 10 -64bit, CPU i7-7700K, 32Gb, Focusrite 2i2, FL-studio 20, Studio One 4, Reason 10
- KVRist
- 298 posts since 1 Apr, 2009 from Hannover, Germany
No Cap needed, the signal source is ideal, so there's no DC to be blocked.
Given that the Opamp used here is a real one, there'll be the usual issues like offset voltages that'll lead to some asymmetry. The clipping should become symmetric if you use an ideal opamp model ("opamp"). And of course a negative supply voltage is needed here, as already pointed out.
Given that the Opamp used here is a real one, there'll be the usual issues like offset voltages that'll lead to some asymmetry. The clipping should become symmetric if you use an ideal opamp model ("opamp"). And of course a negative supply voltage is needed here, as already pointed out.
- KVRAF
- 2110 posts since 5 Oct, 2015 from Swedish / Living in Hong Kong
That should not be the case because in this software that OP have an offset set to 0 (also ideal). I took the time to download LTSpice after I made my comments because I was curious about it. I been building and designing amplifiers with real OP's and the symetry issue normally comes if you don't have equal positive and negatvie feeding to the OP. But that was already mentioned a couple of times.hugoderwolf wrote:No Cap needed, the signal source is ideal, so there's no DC to be blocked.
Given that the Opamp used here is a real one, there'll be the usual issues like offset voltages that'll lead to some asymmetry. The clipping should become symmetric if you use an ideal opamp model ("opamp"). And of course a negative supply voltage is needed here, as already pointed out.
Win 10 -64bit, CPU i7-7700K, 32Gb, Focusrite 2i2, FL-studio 20, Studio One 4, Reason 10
-
- KVRian
- 690 posts since 17 Sep, 2007 from Planet Thanet
Here's an LTSpice model set up of an OD250. Remove any bits that are superfluous for your needs and move clipping diodes to the feedback loop
http://gaussmarkov.net/wordpress/tools/ ... drive-250/
http://gaussmarkov.net/wordpress/tools/ ... drive-250/
-
- KVRAF
- 3080 posts since 17 Apr, 2005 from S.E. TN
Hi ValentenValenten wrote:I am trying to model in LTSpice a simple 2 diodes clipping system, like in the first diagram here :
Source : http://www.bteaudio.com/articles/TSS/TSS.html
So I modeled it in LTSpice like this :
When I quote your message, the forum software does not display the second image, of your interpretation of the first circuit image.
The first schematic will work as expected with fairly symmetrical clipping. In such a circuit opamp input offsets are not extreme except at rather large gain. In the real world there could be slight asymmetries because the diodes are not exactly matched. But unless one had severely mis-matched diodes, the asymmetry from diode mismatch would also be small.
The first schematic assumes that the opamp is powered by +15 volts and -15 volts, or some other level of bipolar power supply, with ground in the middle between the supply rails. Actually, unless your signal gets big enough to approach the power supply rails, opamps are fairly tolerant of mis-matched power supply rails. For instance the first circuit should work about the same with +15 volt and -9 volts supplies or whatever.
Your second gif, showing your interpretation of the circuit, is using +15 and 0 volt supplies. Or + some voltage, it isn't specified. So the opamp might work "about as expected" on the OUTPUT positive wave cycle. The circuit is inverting, so a negative input wave cycle causes the positive output wave cycle.
But a negative OUTPUT wave cycle, the opamp will clip at zero volts. I think the reason that the spice output shows a negative wave at all, is because the resistors and diodes passively pass negative signals thru to the output without any help from the opamp. EDIT: Maybe it is a spice bug showing that output waveform, because my previous explanation should be showing a full-wave-rectified shape, one positive halfwave inverting amplified, and a smaller positive halfwave passed non-inverted by the input and feedback resistors. EDIT2: Or perhaps spice is accurately modeling the behavior of that opamp with both inputs centered on the negative supply rail-- Doing nothing in response to one half-wave input swing, and doing nearly-nothing in response to the other half-wave input swing.
In a real circuit, I suspect it would work worse than that. I'd even be fearful that letting the input go significantly negative of the power supply rails might damage some kinds of opamps, though the opamp's internal input protection diodes along with the input resistor might protect the opamp without frying the tiny opamp internal input protection diodes.
In the real world, your +/0 volt supply would at best work like a half wave rectifier, clipping the top of the half-wave which is amplified. It might depend on the exact configuration of each model of opamp's internal differential input stage.
So you can make your circuit work as expected by powering it with +/- 15 volts. You can probably go as low as +/- 5 volts and this circuit would still work with most opamps. Some opamps would do the right thing with even lower voltage rails.
With uni-polar power supplies, such as stomp boxes powered by a 9 volt battery-- The opamp would run on +9/0 volts, but the opamp inputs would be referenced to a virtual ground. For instance, add to your circuit--
Add two resistors and a capacitor-- 100 kohm resistor connected to + volts, connected to another 100 kohm resistor, connected to ground. Put maybe a 10 uf electrolytic capacitor in parallel with the second 100 kohm resistor. Connect the midpoint between the two resistors to the Plus opamp input (rather than grounding the plus opamp input). This provides the plus input with a virtual ground halfway between the power supply rails. The capacitor smooths any voltage variations in case the stomp box is connected to a suck wallwart 9 volt DC power supply, rather than running off battery, which minimizes hum in your circuit.
Now put about a 10 uF electrolytic capacitor in series with the 4k7 input resistor, between the signal source and resistor. With the + terminal of the cap pointing to the resistor. This keeps DC from the ground referenced signal from messing with the virtual ground reference inside your stompbox.
Also, add about a 10 uF electrolytic capacitor in series with the opamp output, to block the DC from your circuit from getting out to further circuitry. With the + terminal facing the opamp.
Put about a 10 kohm resistor from the back side of the output capacitor to ground, to ground-reference the final output. Put about a 200 ohm up to 1 kohm resistor in series with the back side of the output capacitor, to the stompbox output jack. This final output resistor is to protect the opamp from being destroyed by high voltage static discharges and such accidentally caused by the guitarist walking on carpet and sparking the plug when he is attaching the stompbox to his amp. The opamp has output protection diodes inside, but they are tiny, so you have to limit the current of incoming spikes, to protect the protection diodes.
The output resistor would also offer some protection for the opamp if the guitarist connects a bad shorted cable to the stompbox output. To keep the opamp from trying to deliver more current than it can handle, and melting the tiny output transistors. But many opamps have good enough built-in current-limiting that operating the output into a short might not hurt the opamp, though it might get kinda hot after awhile. Better safe than sorry.
Code: Select all
Virtual Ground for unipolar supply:
To Opamp NonInvert Input
|
|-> 10 uF ->|
| |
+ volts -> 100 kohm ->|-> 100 kohm |-> GND
Input DC Blocking:
Input signal -> 10 uF -> 4k7 input resistor -> Opamp Invert Input
Output DC Block and protection and output impedance setting:
Opamp Output -> 10 uF -> | -> 1 kohm -> Output Jack
|
| -> 10 kohm -> GND
-
- KVRist
- Topic Starter
- 48 posts since 26 Dec, 2009 from France
Hi everyone,
Took the time to study your answers and make some tests before answering again, for the sake of clarity.
First, please let me thank you for the numerous and detailed answers (especially JCJR :p), it was really helpful.
If you want to skip my comments and go to my new problems, just scroll down to the "results" part in my message
Thank you for all the other details, I've saved them and will keep reading them, it's still a bit difficult for me to understand everything in that part
== RESULTS ==
Okay let's jump to the results. After plugging correctly the opamp :
Happy me, it's working. I kept reading the BTE article and added a 47nF capacitor in series with the resistor in order to add that LPF which is inducing phase distortion.
It worked, as far as I remember. I kept going, modified and tried a few things, and then I tried to go back to the LPF addition state... except that now it's not working anymore (unless I boost the capacitor to 47uF (and not nanofarad)... I must be blind as I can't find my mistake
Any idea anyone ?
The result being a 500mV sine wave without any clipping visible (whereas it is visible as shown above without the 47nF capacitor).
Thanks a lot
Took the time to study your answers and make some tests before answering again, for the sake of clarity.
First, please let me thank you for the numerous and detailed answers (especially JCJR :p), it was really helpful.
If you want to skip my comments and go to my new problems, just scroll down to the "results" part in my message
I'll keep that in mind, thanks for the info. I managed to "somehow" make things work with the LT1001 and also with an LTSPICE component called "universal opamp", which seems to be an optimal opamp.Miles1981 wrote:You may indeed want to use another AOP, something like a TL071 which is used quite in a lot of basic circuits (IIRC).
Actually the ones I put are not germanium but silicon, so they're clipping around 0.5V. Now, of course, stupid me, of course I could put a HPF ! Thanks for reminding me !sault wrote: the turn-on voltage of a diode is around 0.7 V, or 700 mV, so you're not going to get a lot of clipping action until then. DC bias is removed by a highpass filter, so a series cap with shunt resistor with a low RC value following the circuit would do the trick.
That did the trick (even if I have other problems explained below). Thank you so much !Deranged Tapir wrote:Opamps are active devices, so plugging it in wouldn't hurt.
Thanks for the input - I kinda solved the sine generator DC problem by plugging the opamp. TBH I have little idea where the DC came from, but anyways. I'll keep your advice in mind though.ATN69 wrote:You might want to add a large capacitor in series with the generator to make sure the signal from the generator is pure sine signal. All real generators normally have such DC blocking capacitor built in.
Yup, got it. However in my more recent tests, I think the assymetry I had noticed before was really a problem linked to the opamp being plugged.hugoderwolf wrote:Given that the Opamp used here is a real one, there'll be the usual issues like offset voltages that'll lead to some asymmetry. The clipping should become symmetric if you use an ideal opamp model ("opamp").
Yes, saw this one, that's actually why I had plugged the negative pole of my opamp to the ground, initially. Since then I replaced it by the picture above.resynthesis wrote:Here's an LTSpice model set up of an OD250. Remove any bits that are superfluous for your needs and move clipping diodes to the feedback loop
Thank you for the clarification. I was really... baffled by the fact that all the opamps in LTSpice had 5 "pins" whereas in this scheme there were only 3 pins. Now it' s more clear !JCJR wrote:The first schematic assumes that the opamp is powered by +15 volts and -15 volts, or some other level of bipolar power supply, with ground in the middle between the supply rails. Actually, unless your signal gets big enough to approach the power supply rails, opamps are fairly tolerant of mis-matched power supply rails. For instance the first circuit should work about the same with +15 volt and -9 volts supplies or whatever.
Yeah, in fact it was buggy because I had incorrectly plugged the opamp. I think it should not show a rectified wave when I measure the output though.JCJR wrote:EDIT: Maybe it is a spice bug showing that output waveform, because my previous explanation should be showing a full-wave-rectified shape, one positive halfwave inverting amplified, and a smaller positive halfwave passed non-inverted by the input and feedback resistors.
Thank you for all the other details, I've saved them and will keep reading them, it's still a bit difficult for me to understand everything in that part
== RESULTS ==
Okay let's jump to the results. After plugging correctly the opamp :
Happy me, it's working. I kept reading the BTE article and added a 47nF capacitor in series with the resistor in order to add that LPF which is inducing phase distortion.
It worked, as far as I remember. I kept going, modified and tried a few things, and then I tried to go back to the LPF addition state... except that now it's not working anymore (unless I boost the capacitor to 47uF (and not nanofarad)... I must be blind as I can't find my mistake
Any idea anyone ?
The result being a 500mV sine wave without any clipping visible (whereas it is visible as shown above without the 47nF capacitor).
Thanks a lot
You do not have the required permissions to view the files attached to this post.
-
- KVRAF
- 3080 posts since 17 Apr, 2005 from S.E. TN
I'm not familiar with LTSpice implementation, and so maybe I'm mis-reading your illustrated hookups.
For instance, if one wanted to bi-polar power an opamp with two 9 volt batteries-- One would connect the minus of one battery to the plus of the other battery, and then attach that junction to ground.
And then one would connect the plus of the "top" battery to the + power pin of the opamp, and connect the minus of the "bottom" battery to the - power pin of the opamp.
This would put GND in the middle, with +9 facing the Opamp Pos terminal and -9 facing the Opamp Neg terminal, and 18 volts between the opamp Pos and Neg terminals.
Assuming the downward facing triangles in your spice pictures are GND, I'd have thought that your power supply for the opamp NEG power pin, would need (-) facing the opamp, and (+) facing GND. Since you have two voltage supplies illustrated, then it would be like connecting two batteries, as in the above explanation.
But maybe it is because I misunderstand LTSpice conventions, and it really should work the way you have the power wired.
It looks like in your wiring, that you have the pos of one 9 V battery connected to Opamp POS power terminal, the pos of the other 9 V battery connected to Opamp NEG power terminal, and both battery neg terminals grounded. I don't understand how that would work. It might somehow weirdly work because of the opamp responding "oddly" to this powering setup, but would not be the usual way to do it.
For instance, if one wanted to bi-polar power an opamp with two 9 volt batteries-- One would connect the minus of one battery to the plus of the other battery, and then attach that junction to ground.
And then one would connect the plus of the "top" battery to the + power pin of the opamp, and connect the minus of the "bottom" battery to the - power pin of the opamp.
Code: Select all
[Opamp Pos Power Pin] -> (+) 9 volt batt (-) -> | -> (+) 9 volt batt (-) -> [Opamp Neg Power Pin]
|
GND
Assuming the downward facing triangles in your spice pictures are GND, I'd have thought that your power supply for the opamp NEG power pin, would need (-) facing the opamp, and (+) facing GND. Since you have two voltage supplies illustrated, then it would be like connecting two batteries, as in the above explanation.
But maybe it is because I misunderstand LTSpice conventions, and it really should work the way you have the power wired.
It looks like in your wiring, that you have the pos of one 9 V battery connected to Opamp POS power terminal, the pos of the other 9 V battery connected to Opamp NEG power terminal, and both battery neg terminals grounded. I don't understand how that would work. It might somehow weirdly work because of the opamp responding "oddly" to this powering setup, but would not be the usual way to do it.
-
- KVRian
- 653 posts since 4 Apr, 2010
Trivial detail, but...sault was referring to silicon diodes when he said 0.7v (some would say 0.6-0.7v, but it's common to use 0.7 as a rule of thumb), but that's for a typical circuit, since it's a function of current. Germanium diodes are more like 0.3v.Valenten wrote:Actually the ones I put are not germanium but silicon, so they're clipping around 0.5V.sault wrote: the turn-on voltage of a diode is around 0.7 V, or 700 mV, so you're not going to get a lot of clipping action until then. DC bias is removed by a highpass filter, so a series cap with shunt resistor with a low RC value following the circuit would do the trick.
My audio DSP blog: earlevel.com
-
- KVRist
- Topic Starter
- 48 posts since 26 Dec, 2009 from France
My bad, thanks a lot for correcting meearlevel wrote:Trivial detail, but...sault was referring to silicon diodes when he said 0.7v (some would say 0.6-0.7v, but it's common to use 0.7 as a rule of thumb), but that's for a typical circuit, since it's a function of current. Germanium diodes are more like 0.3v.
Well I am not much more aware than you of LTSpice conventions as I'm still a beginner with it, but I had copied this type of design on other stuffs I found online. In the end, I was supplying a negative voltage to the NEG terminal of the opamp, so it seemed okay to me.JCJR wrote:This would put GND in the middle, with +9 facing the Opamp Pos terminal and -9 facing the Opamp Neg terminal, and 18 volts between the opamp Pos and Neg terminals.
However I implemented your proposition as well, and noticed also that other people are doing like that. All good for me, same results it seems (I didn't compare them but visually the signal seems completely similar). To give more details and to show you what I did, here is my circuit with the simulation result :
Now, as I am supposed to, I add a 47nF capacitor in series to make a HPF :
As you can see, there is no visible distortion on the signal due to the HPF phase shift, whereas it should be what I get : http://www.bteaudio.com/articles/TSS/TSS.html
"Surprisingly", if I put a 47uF capacitor instead of 47nF, I get a signal distortion that looks closer to the result. So somehow I was expecting the error to come from a mistake in my circuit, like a 10^3 missing somewhere, but I can't seem to find it. I double checked the 47nF value elsewhere on the net and it seems to be correct.
With 47uF I get that :
This is slowly driving me crazy but I still have hope understanding what is wrong
Thanks again for the help to everyone,
V.
You do not have the required permissions to view the files attached to this post.
-
- KVRist
- 379 posts since 4 Oct, 2002
Input signal frequency might be a place to start looking. At 1Hz TS behaves like (nondistorting) unity gain follower. Try it with 200Hz sine wave.Valenten wrote:
like a 10^3 missing somewhere,
-
- KVRist
- Topic Starter
- 48 posts since 26 Dec, 2009 from France
Just did it, indeed I can see some phase shift :urosh wrote:Input signal frequency might be a place to start looking. At 1Hz TS behaves like (nondistorting) unity gain follower. Try it with 200Hz sine wave.
However, since the HPF's cutoff frequency is around 720Hz, there should be a 90 degrees phase shift at 1Hz...
Can you clarify why the response at 1Hz would be non-distorting ?
You do not have the required permissions to view the files attached to this post.