Author Topic: [Solved] Best way to amplify a sine wave without distorsion.  (Read 32480 times)

0 Members and 2 Guests are viewing this topic.

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #50 on: January 31, 2017, 07:14:02 pm »
Attached is the LTSpice (if you don't have it, it's a fee download) file for the circuit I posted previously. I've embedded the model for the LM386. Unfortunately, there doesn't seem to be any way to embed the symbol I used for the LM386, so I had to use the 8-pin package which should come with LTSpice. I've labelled the pins, in the hope it makes it more clear.

I installed LTspice XVII(x64) under wine and it works fine. This is the Vout graph.
I do that too.

Notice how the waveform starts off slightly clipped, then the amplitude decays and it becomes smooth? This is because when power is first applied J1 is on, so it oscillates until it's limited by the supply rail. Then C5 charges via the negative voltage doubler, causing J1 to turn off which increases its resistance and reduces the gain, until the circuit reaches equilibrium. C5 could be reduced to minimise the clipping but at a cost of slightly more distortion.

Quote
As far as I can understand, you had to recreate the LM386 internals in spice! What a huge job!
Fortunately there was no need to do that. I downloaded the model from somewhere. Unfortunately it was a long time ago and can't remember where. I think it might have been the Texas Instruments website.

Quote
As soon as I test the whole project in the breadboard I'll upload the schematics and PCB. The circuit will also have an atmega328p, on-off switching transistors, a voltage regulator and some other stuff. As I've done all this things before there will be no problems.
As you're using an MCU when why not use the digital method for generating the sine wave?

If anyone is interested, I'll post the LTSpice file and LM386 model.

Thank you very much for the schematic and the calculations!! Yes! I'm interested in the spice model. You've done a big effort helping me so I would like to learn as much as I can from it.

I've uploaded the Kicad schematic to give something back to the community.
By the way, this is the first time I used Kicad so it might have some error. If someone downloads it, please check it against the spice picture.
Oh dear. Sorry, that won't work because wires aren't connected to the nodes (the circles on the components) properly.

Only connect wires to the component notes. Never try to make a connection by pushing the components next to one another. It may look like it's connected up, but when you come to making a PCB you'll find the KiCad can't see the connections. You can verify a component is connected by right clicking on it and selecting drag component.

Attached is a cleaned up version of the KiCad schematic, which should work with the PCB package.
« Last Edit: February 09, 2017, 11:52:25 am by Hero999 »
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #51 on: January 31, 2017, 08:42:55 pm »
Oh dear. Sorry, that won't work because wires aren't connected to the nodes (the circles on the components) properly.

That's strange! This is the ERC output. If the output has no errors, the connections should be OK, isn't it?

ERC report (Tue 31 Jan 2017 05:28:54 PM ART, Encoding UTF8 )
***** Sheet /
 ** ERC messages: 0  Errors 0  Warnings 0

When I opened your version Kicad warned that components library is not the last version. Is it possible that if you open a circuit with newer library version the components are disconnected?
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #52 on: January 31, 2017, 08:58:07 pm »
I guess it could be related.

I just opened a schematic in eeschema and since the size of the capacitor component changed in the official library since I created the schematic, they all got disconnected:

eeschema should probably prefer using the components from the cache file rather than reloading the component from the library, potentially doing serious damage to the the schematic.


https://bugs.launchpad.net/kicad/+bug/1435338
 

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #53 on: February 01, 2017, 12:53:23 am »
The distortion caused by the Jfet can be reduced by adding half the drain signal level to the gate.
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #54 on: February 01, 2017, 05:05:49 pm »
The distortion caused by the Jfet can be reduced by adding half the drain signal level to the gate.

Is it possible with a simple resistor? Which value it should have? Please, could you elaborate more?
Thanks!!!
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #55 on: February 01, 2017, 06:55:06 pm »
I guess it could be related.

I just opened a schematic in eeschema and since the size of the capacitor component changed in the official library since I created the schematic, they all got disconnected:

eeschema should probably prefer using the components from the cache file rather than reloading the component from the library, potentially doing serious damage to the the schematic.


https://bugs.launchpad.net/kicad/+bug/1435338
It looks like it. Does the KiCad schematic I posted earlier look alright to you?

Here's what the schematic looks like when I load it in the latest version of KiCad.


The distortion caused by the Jfet can be reduced by adding half the drain signal level to the gate.

Is it possible with a simple resistor? Which value it should have? Please, could you elaborate more?
Thanks!!!

He didn't say that it's possible to reduce the distortion by using a simple resistor (technically the filament lamp does that, but we're talking about an ordinary resistor, not a PTC resistor) rather than a J-FET. I believe he was talking about improving the existing J-FET AGC circuit by adding some negative feedback to it.
« Last Edit: February 01, 2017, 06:57:50 pm by Hero999 »
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #56 on: February 01, 2017, 07:45:06 pm »
It looks like it. Does the KiCad schematic I posted earlier look alright to you?

No, It doesn't. This is the ERC output.
ERC report (Wed 01 Feb 2017 04:13:34 PM ART, Encoding UTF8 )

***** Sheet /
ErrType(3): Pin connected to some others pins but no pin to drive it
    @ (67,31 mm,85,09 mm): Pin 1 (Power input) of component #POWER_FLAG06 is not driven (Net 1).
ErrType(3): Pin connected to some others pins but no pin to drive it
    @ (105,41 mm,60,96 mm): Pin 6 (Power input) of component U1 is not driven (Net 4).
ErrType(6): Mismatch between hierarchical labels and pins sheets
    @ (143,51 mm,50,80 mm): Hierarchical label Output is not connected to a sheet label.

 ** ERC messages: 3  Errors 0  Warnings 3

This is my kicad version. It's the latest for Mint 18.1 Serena (based on Ubuntu 16.04 Xenial Xerus)

Kicad 4.0.5+e0-6337~49~ubuntu16.04.1
Kicad-library 4.0.5+e0+1097~2~ubuntu16.04.1

and I get this warning when I open the schematic.

Here's what the schematic looks like when I load it in the latest version of KiCad.

Is it your version or mine? Look at the capacitors. They have a different symbol in my version. It's in a previous post.

I guess that's why so many people hate open source.

« Last Edit: February 01, 2017, 08:15:17 pm by HoracioDos »
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #57 on: February 01, 2017, 07:58:26 pm »
He didn't say that it's possible to reduce the distortion by using a simple resistor (technically the filament lamp does that, but we're talking about an ordinary resistor, not a PTC resistor) rather than a J-FET. I believe he was talking about improving the existing J-FET AGC circuit by adding some negative feedback to it.

LOL I imagined that the solution could not be so simple!
 

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #58 on: February 02, 2017, 12:13:19 am »
I moved R3 of the original schematic and added two resistors making a voltage divider of the signal at the drain and I fed it to the gate.
 
The following users thanked this post: HoracioDos

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #59 on: February 02, 2017, 03:15:05 pm »
I moved R3 of the original schematic and added two resistors making a voltage divider of the signal at the drain and I fed it to the gate.

I should have thought in a voltage divider when you said half of the signal. I uploaded the spice model with your changes. This is the output with and without zoom. It seems that the amplitude decreases and increases later.

This is what I did yesterday. I thought It was all wrong but look at the output. The amplitude decreases just a little bit and stays there. It seems that the clipping stops  between 260-280ms.
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #60 on: February 02, 2017, 04:11:14 pm »
I didn't realize about this before. If the oscillator gets stable somewhere between 260-280 ms I should switch on and off the output as it was in the first design due to morse code timing.

At 13 Words per Minute: Dit = 92ms, Dah = 276ms, Spacing = 92ms, Word Spacing = 644ms. So the signal will always be clipped.

Can I use still the previous method, moving the signal above 0V and usign a NPN and MOSFET transistors? Or should I use something like this?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #61 on: February 02, 2017, 09:18:01 pm »
Is it your version or mine? Look at the capacitors. They have a different symbol in my version. It's in a previous post.
The schematic I posted previously is yours. Yes, the default capacitor symbol in my library is different to yours.

Quote
I guess that's why so many people hate open source.
Many people use open source software on their phone and are totally unaware of it.

It's KiCad which is crap, not open source software in general. I hadn't used it for years and hoped it had improve but it's still rubbish.

I moved R3 of the original schematic and added two resistors making a voltage divider of the signal at the drain and I fed it to the gate.

I should have thought in a voltage divider when you said half of the signal. I uploaded the spice model with your changes. This is the output with and without zoom. It seems that the amplitude decreases and increases later.

This is what I did yesterday. I thought It was all wrong but look at the output. The amplitude decreases just a little bit and stays there. It seems that the clipping stops  between 260-280ms.
The waveform looks worse to me, than it did before.

The low frequency oscillation is caused by the AGC circuit being unstable.

I didn't realize about this before. If the oscillator gets stable somewhere between 260-280 ms I should switch on and off the output as it was in the first design due to morse code timing.

At 13 Words per Minute: Dit = 92ms, Dah = 276ms, Spacing = 92ms, Word Spacing = 644ms. So the signal will always be clipped.

Can I use still the previous method, moving the signal above 0V and usign a NPN and MOSFET transistors? Or should I use something like this?

Is the muting transistor just two NPNs back to front?

What about using an analogue switch such as the CD4066?

 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #62 on: February 02, 2017, 09:59:40 pm »
I was playing around LTSpice graphs and started to tweak resistors values just to see what it may happen and I found this strange case.

The AGC seems not to be working any more but the signal is never clipped from start to end and frequency is still about 1.1Khz. Can you check this?
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #63 on: February 02, 2017, 10:23:58 pm »
I was playing around LTSpice graphs and started to tweak resistors values just to see what it may happen and I found this strange case.

The AGC seems not to be working any more but the signal is never clipped from start to end and frequency is still about 1.1Khz. Can you check this?
All you've done is disabled the AGC by shorting the gate to the source, via a low value resistor and set the gain of the amplifier to exactly the right value. It may work in simulation but I doubt it will in real life, as the gain only has to change slightly for it to either stop oscillating or clip.

The speed of the AGC circuit can be increased by decreasing the capacitor values but there will be slightly more distortion.
« Last Edit: February 02, 2017, 11:17:34 pm by Hero999 »
 
The following users thanked this post: HoracioDos

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #64 on: February 05, 2017, 05:51:04 pm »
I built the circuit and the wave is very distorted. I checked it all many times, I replaced components and can't find if i'm doing something wrong. Frequency is very far away from it's supposed.
Any tips?
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: Best way to amplify a sine wave without distorsion.
« Reply #65 on: February 05, 2017, 05:59:45 pm »
I built the circuit and the wave is very distorted. I checked it all many times, I replaced components and can't find if i'm doing something wrong. Frequency is very far away from it's supposed.
Any tips?

Use my DAC solution? :) Just kidding, can be helpful to find the problems, if you want to learn more about analog electronics, which I don't have a clue of, and not just somehow create a sine wave.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 
The following users thanked this post: HoracioDos

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #66 on: February 09, 2017, 12:07:33 pm »
I built the circuit and the wave is very distorted. I checked it all many times, I replaced components and can't find if i'm doing something wrong. Frequency is very far away from it's supposed.
Any tips?
The LM386 appears to be oscillating at a high frequency, completely independent of the Wein bridge circuit. This isn't very surprising as the data sheet says the LM386 is only stable down to gains of 20. I'm surprised it suggested a gain of 12 for the Wein bridge circuit.

You could have a go at frequency compensation (a capacitor across R1 or between pins 2 & 3) but I suspect the easiest way is to increase the gain to >20 and adjust the other component values to compensate.
« Last Edit: February 09, 2017, 07:06:02 pm by Hero999 »
 
The following users thanked this post: HoracioDos

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #67 on: February 09, 2017, 06:07:32 pm »
I think the circuit oscillates because it is built on a solderless breadboard that has stray capacitance all over the place?
Also, it is missing some very important parts shown in the datasheet.
 
The following users thanked this post: HoracioDos

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #68 on: February 09, 2017, 07:25:03 pm »
Also, it is missing some very important parts shown in the datasheet.
Which important parts?

Whether the missing parts are required or not depends on how the amplifier is being used. The Zobel network is only necessary, if it's being used to drive a speaker. If it's driving a purely resistive load then it's not needed. Adding a bypass capacitor between pin 7 and 0V would improve the supply rejection factor but it's pointless if the circuit is run from a stabilised power supply.

Connecting pin 2 to +V, via a 1000µF capacitor, would be a bad idea because we want to set the gain using a potential divider connected between the output pin 2 and 0V, in much the same manner as an op-amp non-inverting amplifier.

There should be a 100µF capacitor connected across the supply rails, which is missing because it is not necessary when simulating the circuit, even though it's required in real life.

I didn't know the LM386 is suitable for use at gains as low as 9. Anyway, it doesn't seem to like a gain of 12, so should be more stable with a gain of 22.36, with slightly large frequency determining capacitors.
 
The following users thanked this post: HoracioDos

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #69 on: February 10, 2017, 12:33:17 am »
Connecting pin 2 to +V, via a 1000µF capacitor, would be a bad idea because we want to set the gain using a potential divider connected between the output pin 2 and 0V, in much the same manner as an op-amp non-inverting amplifier.[/quote]
My sketch shows pin 2 grounded and an important 100uF supply capacitor also connected to pin 2 which is ground.
 
The following users thanked this post: HoracioDos

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #70 on: February 10, 2017, 08:44:51 am »
My sketch shows pin 2 grounded
Sorry missed, that pin 2 was grounded. It's still a bad idea in this case, as we want the gain to be set by a potential divider between the output and pin 2: R1, R2 and R6 in series with the J-FET. Pin 2 isn't grounded on the original Wein bridge schematic on the LM386 datasheet. It is connected to the output via a potential divider, consisting of a 390R resistor and filament lamp.

Quote
an important 100uF supply capacitor.
I agree, it needs a decoupling capacitor in real life. There was no decoupling on any of schematics I posted because they were for simulation only.
« Last Edit: February 10, 2017, 08:50:19 am by Hero999 »
 
The following users thanked this post: HoracioDos

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #71 on: February 10, 2017, 09:04:37 pm »
I agree, it needs a decoupling capacitor in real life. There was no decoupling on any of schematics I posted because they were for simulation only.

There was a decoupling capacitor in the original design (at least in the breadboard). I removed it and I forgot to put it back when I switched from LM358 to LM386.  :palm: I had some problems with sensors before so I've started to use them.

About breadboard capacitance, this pic was taken without the gain capacitor, it's supposted that the oscillator shouldn't work at all without it.

I must clear my mind and start all over again.

Meanwhile I started a different approach this week with a NE555 and the LM386 spice model was the perfect excuse to learn and use it. I've got a quite nice sine wave (about 1kHz) and it takes less than 4ms to be stable. It goes from -1.5 to 1.5V and -15 to 15mA. I guess it's good enough to feed into a radio mic.

I'm not giving up with the oscillator, I've learn a lot with it. I started from the scratch today with the LM741 but including the AGC this time. It took too much time and everybody's effort to leave it behind unfinished.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #72 on: February 10, 2017, 10:55:08 pm »
Yes, you can make a sine wave from a square wave by using a filter to remove the harmonics. It will work with an RC filter too.

Why use the old 741? There are much better op-amps around and they aren't expensive.

You'll probably see lots of schematics for Wien bridge oscillators which use a dual supply. Here's one which will work from a single supply.

« Last Edit: February 10, 2017, 11:32:10 pm by Hero999 »
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #73 on: February 12, 2017, 01:47:05 pm »
Why use the old 741? There are much better op-amps around and they aren't expensive.

You are right, I don't need to go back to basics with a LM741. I'll go right ahead with a newer Op-Amp like OP07. I'll buy some of them this week.

Thanks again!!
 

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
Re: Best way to amplify a sine wave without distorsion.
« Reply #74 on: February 23, 2017, 02:01:04 am »
I've been learning about the phase shift oscillator and the buffered version in the last weeks. They are really fast and quite easy to set up within 9V. I used the TL071 in the spice model but a quad op-amp like TL074 could be used instead.

I added an op amp follower for buffering, gain and amplitude adjustment and one stage bandpass filter (1Khz - 100Hz width) designed with TI FilterPro. I've uploaded a new version with NE555 and the oscillators. All off them have a very similar output of about 1Khz.

By the way, I signed up for a basic electronics course at the end of next month and bought some books.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf