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

0 Members and 1 Guest are viewing this topic.

Offline HoracioDosTopic starter

  • Frequent Contributor
  • **
  • Posts: 344
  • Country: ar
  • Just an IT monkey with a DSO
[Solved] Best way to amplify a sine wave without distorsion.
« on: January 26, 2017, 12:02:13 am »
Hello.

I'm building a Capacitive Touch Morse Keyer with an Arduino and a MPR121 module.

I managed to make a Wien bridge oscillator with all calculations to generate a quite nice 860-960Hz sine wave. Later I moved the wave above 0V and turn it on and off with a PWM, now I want to amplify it to feed a VHF handheld radio mic with a minimum distorsion. The circuit is attached.

Radio's in/out interface is done. It was a previous project and the arduino programming is also finished.

I thought I could use a class AB amplifier circuit like this.


I have read the pros and cons of A, B and AB amplifiers circuits but as I still don't fully understand transistors and it's calculations, I used a LM386 with a 20 gain config (I guess it's a class A) but I found some problems.

There is always a hiss on the output when the input signal is off and I can't hear the output when the signal is on but there is no hiss and the wave in the scope is very distorted.

Also found that I can hear a commercial radio when the IC input is not wired. I didn't know it was possible.

Should I keep using the IC and make it work or should I use the class AB transistor amplifier circuit? What is best or easier or both?

Thanks in advance!
« Last Edit: March 03, 2017, 08:18:55 pm by HoracioDos »
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: Best way to amplify a sine wave without distorsion.
« Reply #1 on: January 26, 2017, 12:44:33 am »
I don't know the answers to your questions, but your attached Fritzing circuit diagram is difficult to understand. Some obvious problems: You should remove the long bottom wire from -5V to the output of the negative voltage power supply IC, it is sufficient to show that it is connected if you use on both sides the -5V symbol. For C5 you should not connect it to the same GND symbol as used for the neg input of the LM386, place an additional ground symbol, because it has nothing to do with the neg input.

The outputs of the LM358 are not connected, are you sure this is what you built? And would be nice to have standard OpAmp symbols for the two OpAmps in the LM358. I don't know Fritzing, but better PCB CAD programs like KiCad or Eagle don't limit the number of independent symbols per IC packages. You should use one of those programs, if Fritzing doesn't support it.
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

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: Best way to amplify a sine wave without distorsion.
« Reply #2 on: January 26, 2017, 12:50:49 am »
PS: if you really use a PWM signal to switch your sine wave on an off, it will produce a lot of distortions. Just use a digital out pin of your Arduino and set it to 1 or 0.
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

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #3 on: January 26, 2017, 01:38:33 am »
Like most audio amplifiers, the LM386 is class-AB. It has hiss because it is cheap. Its internal gain is 4500 times and it uses negative feedback to reduce the gain to a useable amount and cancel most of its distortion. With a 5V supply its output power before clipping distortion into an 8 ohm speaker is only 0.14W which is almost nothing. It works best with a 9V supply then its output is 0.5W.

Your transistor "amplifier" has a gain of only a little less than one and it has plenty of distortion. 
 
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 #4 on: January 26, 2017, 02:46:06 pm »
Thank you for your comments

You should remove the long bottom wire from -5V to the output of the negative voltage power supply IC, it is sufficient to show that it is connected if you use on both sides the -5V symbol.

I know it's easier to follow it in the way you describe. Fritzing saves the breadboard view, schematic and pcb traces in only one file and creates ratsnets lines in the PCB tab, but if I wire this ways it's easier to convert the netlist to traces in the pcb designer tab later.

For C5 you should not connect it to the same GND symbol as used for the neg input of the LM386, place an additional ground symbol, because it has nothing to do with the neg input.

The circuit has a 20 gain config just like it's shown in the datasheet. I can't find any obvious error on this. Am I missing something?
https://iamzxlee.files.wordpress.com/2014/05/gain-20.jpg
Here is another example.
https://iamzxlee.files.wordpress.com/2014/05/lm-386-main.jpg?w=736&h=424

The outputs of the LM358 are not connected, are you sure this is what you built? And would be nice to have standard OpAmp symbols for the two OpAmps in the LM358. I don't know Fritzing, but better PCB CAD programs like KiCad or Eagle don't limit the number of independent symbols per IC packages. You should use one of those programs, if Fritzing doesn't support it.

Yes, I'm aware of that. Pins 1,7 and 8 are not needed. I'm trying to slowly move from Fritzing to Kicad. I'm sure it's a better EDA tool it's not as friendly as Fritzing and the learning curve is steep.
 

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 #5 on: January 26, 2017, 02:58:15 pm »
Hello!

PS: if you really use a PWM signal to switch your sine wave on an off, it will produce a lot of distortions. Just use a digital out pin of your Arduino and set it to 1 or 0.

As far as I understand for a non-PWM pin, analogWrite() with a value below 128 is the same a digitalWrite(LOW) and analogWrite() with a value above 127 is the same a digitalWrite(HIGH). I'll check the program again to verify what i'm doing, but I don't get a distorted signal. Here is the output before it goes to the amplifier stage.
 

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 #6 on: January 26, 2017, 03:33:53 pm »
Like most audio amplifiers, the LM386 is class-AB. It has hiss because it is cheap. Its internal gain is 4500 times and it uses negative feedback to reduce the gain to a useable amount and cancel most of its distortion. With a 5V supply its output power before clipping distortion into an 8 ohm speaker is only 0.14W which is almost nothing. It works best with a 9V supply then its output is 0.5W.

That's a problem. I want to power it with a usb port or cell phone charger. I only need the minimum power required to feed a VHF handheld mic.

Your transistor "amplifier" has a gain of only a little less than one and it has plenty of distortion.

I found this circuit that I want to test. Would you say that the tone could not be a clean sine wave before I build it?
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: Best way to amplify a sine wave without distorsion.
« Reply #7 on: January 26, 2017, 04:13:57 pm »
For C5 you should not connect it to the same GND symbol as used for the neg input of the LM386, place an additional ground symbol, because it has nothing to do with the neg input.

The circuit has a 20 gain config just like it's shown in the datasheet. I can't find any obvious error on this. Am I missing something?
https://iamzxlee.files.wordpress.com/2014/05/gain-20.jpg

There is nothing wrong with the netlist, only how it is drawn. In your version at first glance it looks like C5 has something to do with the neg input of the LM386, even if that's not the case. That's why I suggested to use 2 GND symbols, one for C5 and one for the neg input of LM386. Sorry when my phrasing is a bit odd, I'm German :)
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

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 #8 on: January 26, 2017, 04:22:08 pm »
Sorry when my phrasing is a bit odd, I'm German :)

LOL!! No problem. I feel the same many times!!!. English is not my mother language either or mother tongue or whatever..
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #9 on: January 26, 2017, 06:27:27 pm »
Pins 1,7 and 8 are not needed. I'm trying to slowly move from Fritzing to Kicad. I'm sure it's a better EDA tool it's not as friendly as Fritzing and the learning curve is steep.
I think you'll find that pin 1 (the output of the first amplifier) is needed. You must mean pins 5, 6 & 7 aren't needed. The unused op-amp should be correctly terminated, not simply left unconnected, which can cause trouble. Configure the unused op-amp as a unity gain buffer, with the input grounded. Connect the inverting input (pin 6) to the output (pin 7) and the non-inverting (pin 5) input to 0V.

I seriously doubt you actually built the circuit as drawn. What is Q2 supposed to do? Its gate is just connected to the source so it will be off all the time.

As drawn, there's no automatic gain control on the oscillator so the signal will either slowly fade away or clip to form a horribly distorted waveform. Perhaps Q2 is supposed to be the gain control.

Why not AC couple the signal from the Wein bridge oscillator to the LM386 amplifier?

It should also be possible to build a Wein bridge oscillator using a single power supply so you can eliminate U3. Heck, I'd consider removing the U1 and using the LM386 to make the Wein bridge oscillator. There's even an example on the data sheet.
http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/Labs/LM386.pdf
« Last Edit: January 26, 2017, 06:30:52 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 #10 on: January 26, 2017, 06:33:04 pm »
An LM386 power amplifier has negative feedback so that its gain is only 20 but without negative feedback its gain is about 4500. Its datasheet shows that a capacitor added between pin 1 and pin 8 reduces the negative feedback so that the gain becomes 200.

Your first circuit with many problems drives an 8 ohm speaker.
Your last circuit drives a whopping high signal into a very low level microphone input. Its needs an attenuator.

Your last twin-T filtered "sinewave" oscillator has no automatic-gain-control so its output will probably rise high enough for the transistors to cause clipping that is almost a squarewave.
 
The following users thanked this post: HoracioDos

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: Best way to amplify a sine wave without distorsion.
« Reply #11 on: January 26, 2017, 06:55:03 pm »
If you are only sending out a single tone, I would just make a classic L/C or R/C filter which could take your 5V square wave and make a nice sine-wave out of it.  No fooling around with linear amplification etc.
 
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 #12 on: January 26, 2017, 08:28:28 pm »
Pins 1,7 and 8 are not needed. I'm trying to slowly move from Fritzing to Kicad. I'm sure it's a better EDA tool it's not as friendly as Fritzing and the learning curve is steep.
I think you'll find that pin 1 (the output of the first amplifier) is needed. You must mean pins 5, 6 & 7 aren't needed. The unused op-amp should be correctly terminated, not simply left unconnected, which can cause trouble. Configure the unused op-amp as a unity gain buffer, with the input grounded. Connect the inverting input (pin 6) to the output (pin 7) and the non-inverting (pin 5) input to 0V.

I seriously doubt you actually built the circuit as drawn. What is Q2 supposed to do? Its gate is just connected to the source so it will be off all the time.

As drawn, there's no automatic gain control on the oscillator so the signal will either slowly fade away or clip to form a horribly distorted waveform. Perhaps Q2 is supposed to be the gain control.

Why not AC couple the signal from the Wein bridge oscillator to the LM386 amplifier?

It should also be possible to build a Wein bridge oscillator using a single power supply so you can eliminate U3. Heck, I'd consider removing the U1 and using the LM386 to make the Wein bridge oscillator. There's even an example on the data sheet.
http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/Labs/LM386.pdf

Hello!

I'm a little bit confused. Let's go by parts...

I wrote that LM386 pins 1,7 and 8 are not needed, not the LM358.

I didn't use the LM386 for a Wien bridge for these reasons:

a) I first began using a LM741 to generate a sinewave and then switched to a LM358.
b) I didn't want anything with a light bulb.
c) LM386 was introduced later in the design as an audio amplifier.

Yes, I'm aware I'm not using the 2nd op-amp in the LM358 based on reason a) and I can't see why it should be a problem. There's an image of the sine wave before going to the LM386 amplifier stage and it's clean.

I decided to use a LM386 to amplify the sine wave because I have read in many websites that a LM358 is not an audio amplifier and It shouldn't be used as one.

Also, I don't fully understand the calculations to build a class ab amplifier with transistors and I didn't want to do it by trial and error. So a low power amplifier should do it easily with less components.

R5 and R6 move the signal above 0V to avoid the transistors could clip the signal. I tested it without the resistors and the sine wave was awful. If I'm wrong I would like to fix that.

Q1 and Q2 was the best way I found to turn on and off the sinewave from the arduino without any distorsion. Arduino pin is always HIGH and switched to LOW when the keyer is touched. If there's a better way, I'll love to learn it.

Yes, You are right, there's no automatic gain control to fade away the signal when it's cut off. I never thought it should be necesary. Perhaps it's a big mistake. I attached an image from the DSO when it happens.

The circuit was built exactly as it's described. I'm sure it can be optimized to be more simple with less components.

First I have to find out how to do the calculations with the proposed circuit and replace the light bulb with something else to get a 800hz sine wave.

In the mean while I would like to find out how to amplify the signal and take advantage of what I've done.  Once it's working I'll try to replace the LM358 with the LM368, drop the ICL7660 and leave only one IC.
 

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 #13 on: January 26, 2017, 08:40:15 pm »
An LM386 power amplifier has negative feedback so that its gain is only 20 but without negative feedback its gain is about 4500. Its datasheet shows that a capacitor added between pin 1 and pin 8 reduces the negative feedback so that the gain becomes 200.

Thanks for the explain. I saw the 200 gain config in the datasheet.

Your first circuit with many problems drives an 8 ohm speaker.

Ok, I could try to use 9 volts as you told me previously or try something else.

Your last circuit drives a whopping high signal into a very low level microphone input. Its needs an attenuator.
Your last twin-T filtered "sinewave" oscillator has no automatic-gain-control so its output will probably rise high enough for the transistors to cause clipping that is almost a squarewave.

I thought the output could be too high for the input mic but as It's a published circuit in a Ham Radio Magazine, well I guess I was wrong.
 

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 #14 on: January 26, 2017, 08:45:11 pm »
If you are only sending out a single tone, I would just make a classic L/C or R/C filter which could take your 5V square wave and make a nice sine-wave out of it.  No fooling around with linear amplification etc.

LOL!. That was my very first option and I failed miserably. Large story with capacitors, inductors and calculations.
Do you have some circuit at hand?
 

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 #15 on: January 26, 2017, 09:28:06 pm »
Your last circuit drives a whopping high signal into a very low level microphone input. Its needs an attenuator.

I was reading your comment again, Do you refer to the circuit that I built not the one published (The third one). If that's the case, yes, it was already in my mind, I thought in a voltage divider with a potentiometer. I don't know if it's the correct way to do an attenuator.

Thanks again!
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #16 on: January 26, 2017, 10:58:54 pm »
Pins 1,7 and 8 are not needed. I'm trying to slowly move from Fritzing to Kicad. I'm sure it's a better EDA tool it's not as friendly as Fritzing and the learning curve is steep.
I think you'll find that pin 1 (the output of the first amplifier) is needed. You must mean pins 5, 6 & 7 aren't needed. The unused op-amp should be correctly terminated, not simply left unconnected, which can cause trouble. Configure the unused op-amp as a unity gain buffer, with the input grounded. Connect the inverting input (pin 6) to the output (pin 7) and the non-inverting (pin 5) input to 0V.

I seriously doubt you actually built the circuit as drawn. What is Q2 supposed to do? Its gate is just connected to the source so it will be off all the time.

As drawn, there's no automatic gain control on the oscillator so the signal will either slowly fade away or clip to form a horribly distorted waveform. Perhaps Q2 is supposed to be the gain control.

Why not AC couple the signal from the Wein bridge oscillator to the LM386 amplifier?

It should also be possible to build a Wein bridge oscillator using a single power supply so you can eliminate U3. Heck, I'd consider removing the U1 and using the LM386 to make the Wein bridge oscillator. There's even an example on the data sheet.
http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/Labs/LM386.pdf

Hello!

I'm a little bit confused. Let's go by parts...

I wrote that LM386 pins 1,7 and 8 are not needed, not the LM358.
I apologise for the confusion.

I was indeed talking about the LM358, which doesn't have its output connected to anything, so it can't work. Clearly you are getting a sinewave out of this circuit, so the schematic you've posted here is different to what you've actually built.

Quote
The circuit was built exactly as it's described.
You must be mistaken.

Ignore the rest of the circuit for now. Focus on the Wein bridge oscillator. The output (pin 1 on the LM358 goes nowhere) therefore it can't possibly work, as drawn. If it does work, then you've built something different.

 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: Best way to amplify a sine wave without distorsion.
« Reply #17 on: January 27, 2017, 01:54:00 am »
LOL!. That was my very first option and I failed miserably. Large story with capacitors, inductors and calculations.
Do you have some circuit at hand?
Google returned many interesting options when I searched for: 3rd order notch filter
Of course you need the "opposite" of a notch filter, but it is trivial to invert a filter circuit to make a sharp (high-Q) bandpass filter.
 
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 #18 on: January 27, 2017, 05:51:45 am »
Your "keyer" changes the DC input on the LM386 audio amplifier so it will make a loud POP sound each time it is keyed and again when the key is turned off.
The LM358 is the dual version of the LM324 quad. They are low power so they are missing output biasing and create crossover distortion.
 
The following users thanked this post: HoracioDos

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: Best way to amplify a sine wave without distorsion.
« Reply #19 on: January 27, 2017, 06:10:43 am »
Your "keyer" changes the DC input on the LM386 audio amplifier so it will make a loud POP sound each time it is keyed and again when the key is turned off.
The LM358 is the dual version of the LM324 quad. They are low power so they are missing output biasing and create crossover distortion.

Interesting, I didn't know that the crossover distortion is so high for such a common OpAmp. Is there any other standard OpAmp with lower distortion? I found the OPA388, for which the datasheet says "zero-crossover", "zero-drift" and it is not too expensive, but max supply voltage is very low.
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

Offline sibeen

  • Frequent Contributor
  • **
  • Posts: 271
  • Country: au
Re: Best way to amplify a sine wave without distorsion.
« Reply #20 on: January 27, 2017, 07:54:30 am »

Q1 and Q2 was the best way I found to turn on and off the sinewave from the arduino without any distorsion. Arduino pin is always HIGH and switched to LOW when the keyer is touched. If there's a better way, I'll love to learn it.


But how does Q2 do anything? The way you have it configured it is permanently off and cannot possibly be turned on.
 
The following users thanked this post: HoracioDos

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #21 on: January 27, 2017, 08:46:14 am »
Your "keyer" changes the DC input on the LM386 audio amplifier so it will make a loud POP sound each time it is keyed and again when the key is turned off.
The LM358 is the dual version of the LM324 quad. They are low power so they are missing output biasing and create crossover distortion.

Interesting, I didn't know that the crossover distortion is so high for such a common OpAmp. Is there any other standard OpAmp with lower distortion? I found the OPA388, for which the datasheet says "zero-crossover", "zero-drift" and it is not too expensive, but max supply voltage is very low.
Most op-amps don't have crossover distortion like that. Even the old uA741 didn't have that much crossover distortion.

Fortunately it's fairly straightforward to remove the crossover distortion by ensuring only one of the transistors in the LM358's output stage is active at a time. This can be achieved by connecting a resistor between the output and either supply rail.
 
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 #22 on: January 27, 2017, 12:53:40 pm »
You must be mistaken.
Ignore the rest of the circuit for now. Focus on the Wein bridge oscillator. The output (pin 1 on the LM358 goes nowhere) therefore it can't possibly work, as drawn. If it does work, then you've built something different.

I can't stop laughing at myself. How ridiculous I'm! I've learned a lot in this thread.

When I read your first reply, I thought: "Well, he didn't like the circuit even a bit. I'm a noob. I don't have any problems with that. He knows a lot more, that's why I'm here... but ...is he suggesting I didn't build the circuit way I said in front of a lot of people? Is he really saying that? I should post a picture to prove the circuit exists. This circuit have been giving me headaches for so long that I can draw it with my left ear" ... A big avalanche was already going down the hill eating everthing in it's path....

Then I read this reply yesterday and finally the snow swallowed my pride. I was so blind worried about my own interpretation of things that I didn't see what it was so obvious for you about the LM358 connections. I was so sure that the schematic was showing the reality, I would have bet a month salary! You would have loved to see my face when I checked the breadboard! So I must say it " YOU ARE RIGHT!!!"

So, first I must check the schematic very carefully against the breadboard, make corrections in the schematic and review all the previous replies.

Thank you very much!!!
« Last Edit: January 27, 2017, 07:23:28 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 #23 on: January 27, 2017, 01:58:37 pm »
LOL!. That was my very first option and I failed miserably. Large story with capacitors, inductors and calculations.
Do you have some circuit at hand?
Google returned many interesting options when I searched for: 3rd order notch filter
Of course you need the "opposite" of a notch filter, but it is trivial to invert a filter circuit to make a sharp (high-Q) bandpass filter.

These were my first attempts to convert a square wave to a sine wave with transistors and rc network calculations and a 555 also. But the result was a triangle wave or worst.
http://www.learningaboutelectronics.com/Articles/Sine-wave-generator-circuit-with-a-555-timer.php
http://www.learningaboutelectronics.com/Articles/Square-to-sine-wave-converter-circuit.php
It could been easier for me to use an arduino to generate an square wave and find a way to convert it to a sine wave.
It have been a too long journey for such a small project.
 

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 #24 on: January 27, 2017, 02:04:04 pm »

Q1 and Q2 was the best way I found to turn on and off the sinewave from the arduino without any distorsion. Arduino pin is always HIGH and switched to LOW when the keyer is touched. If there's a better way, I'll love to learn it.


But how does Q2 do anything? The way you have it configured it is permanently off and cannot possibly be turned on.

Hero999 opened my eyes. I must check if Q1 and Q2 for sure are connected as it's shown. The circuit is obviously working but the schematic may be wrong with this too.
 

Offline LvW

  • Frequent Contributor
  • **
  • Posts: 282
  • Country: de
Re: Best way to amplify a sine wave without distorsion.
« Reply #25 on: January 27, 2017, 02:59:55 pm »
Google returned many interesting options when I searched for: 3rd order notch filter
Of course you need the "opposite" of a notch filter, but it is trivial to invert a filter circuit to make a sharp (high-Q) bandpass filter.

Did you ever try to solve such a "trivial" task? I doubt. There are specific bandpass design procedures which can (and should) be applied.
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: Best way to amplify a sine wave without distorsion.
« Reply #26 on: January 27, 2017, 04:42:49 pm »
Did you ever try to solve such a "trivial" task? I doubt. There are specific bandpass design procedures which can (and should) be applied.
Yes I have. Sorry you found it so difficult.
 

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 #27 on: January 27, 2017, 07:08:08 pm »
a) I first began using a LM741 to generate a sinewave and then switched to a LM358.

I think I found the crux of the matter in my own answer.

a) I replaced LM741 with LM358 in the last minute. As the pinouts are quite similar I made corrections in the breadboard but forgot to do them in the schematics.  :palm:
b) Q1 and Q2 were OK. Q1 Collector was connected to Q2 Gate and Q2 Source to R10. But... R10 was overlaping Q1 so it seemed that R10 was connected to Q1 Collector and to Q2 Gate.
c) Also R11 and R12 were missing.  :palm:

I updated the schematic. It should be fine now. (Finger crossed)
So I'm back on track to find out a proper way how to amplify the sine wave.
« Last Edit: January 27, 2017, 07:09:52 pm by HoracioDos »
 

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #28 on: January 27, 2017, 07:29:38 pm »
1) Your opamp used in the Wien Bridge oscillator will produce a clipped sinewave because it is missing an automatic gain control (a light bulb or a Jfet).
2) The output of the LM386 power amp will have its positive excursion clipped because it amplifies the DC from the Mosfet. A coupling capacitor to block the DC is needed between the R10 volume control and the pin 3 input of the LM386.
 
 
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 #29 on: January 27, 2017, 09:13:32 pm »
Requiescat in pace Fritzing. There is no light bulb or jfet n-channel parts. Moving to Kicad this weekend. It's going to take a while...

1) Your opamp used in the Wien Bridge oscillator will produce a clipped sinewave because it is missing an automatic gain control (a light bulb or a Jfet).

It seems that the easiest change could be replacing R4 with a 5V light bulb (light bulbs are chasing me after all) and R3 with a 100K trimpot. It will allow me to find the correct value later. If I use a JFet N-Channel. Can a 2N5457/8 or BF244A/5A be used?

2) The output of the LM386 power amp will have its positive excursion clipped because it amplifies the DC from the Mosfet. A coupling capacitor to block the DC is needed between the R10 volume control and the pin 3 input of the LM386.

I have many 0.1uF (104) capacitors. I guess It could work.
 

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #30 on: January 28, 2017, 12:14:36 am »
It seems that the easiest change could be replacing R4 with a 5V light bulb (light bulbs are chasing me after all) and R3 with a 100K trimpot.
You will not find a light bulb with a warm resistance as high as 47k ohms so the value of R3 must be reduced a lot. You probably know that the opamp gain for a Wien bridge oscillator must be about 3. Also you need to use a power amplifier to drive the light bulb instead of an opamp.

Quote
If I use a JFet N-Channel. Can a 2N5457/8 or BF244A/5A be used?
A 2N5459 or a 2N5486 has a lower range of cutoff voltage. You should also re-design the attenuator so that it has no DC voltage on it (your R6 causes a huge POP and should be removed).

Quote
I have many 0.1uF (104) capacitors. I guess It could work.
Don't guess, look at the input resistance of 50k ohms for the LM386 in its datasheet then calculate that a 0.1uF capacitor will pass frequencies above about 32Hz.
« Last Edit: January 28, 2017, 12:19:09 am by Audioguru »
 
The following users thanked this post: HoracioDos

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #31 on: January 28, 2017, 12:30:58 am »
The LM386 can be used as a Wein bridge oscillator with a J-FET AGC circuit, rather than the light bulb suggested on the data sheet.

 
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 #32 on: January 28, 2017, 01:42:45 am »
The datasheet for the LM386 says that it becomes unstable if its gain is reduced to less than 9  but here it is 3. Do you think the capacitor between pin 1 and pin 8 reduces its high frequencies enough to make it stable with a gain of only 3?
 
The following users thanked this post: HoracioDos

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: Best way to amplify a sine wave without distorsion.
« Reply #33 on: January 28, 2017, 06:58:43 am »
Another easy way to create a clean and stable sin wave is to use a DAC. I tried it with a MAX5712, a 12 bit DAC, which can be directly connected to the Arduino with SPI. This is a test with a Mega2560, which allows up to 24 kHz samplerate, here with 20 kHz samplerate, generating a sin wave of 943 Hz:



Only one small 6 pin IC, two capacitors and one resistor are needed, and you can change the frequency in software, and switch it on and off without more external parts. You can even program it in a way, that it switches it off at zero crossover and starts at zero (1/2 VDD with the current circuit), to avoid any clicks, or add an envelope. If you need more power for the output, you can still use your LM386. Depending on the output frequency and the samplerate, you need to adjust the lowpass filter with R1/C1. Unlike most audio DACs, the output of the MAX5712 can be DC. This is the filtered output for 0.1 Hz, only one variable change in the Arduino sketch:



Below is the Arduino source code. The output is generated in an interrupt, you can use the loop for other things like reading switches or analog values, blinking LEDs etc. But the interrupt uses timer 1, which means you can't use the Arduino PWM functions anymore. For low frequencies, you can even use the sinf function for calculating the DAC value in realtime, no need for the big table, but this works only up to 5 kHz samplerate. I tried this with a STM32F4 discovery kit, which has an ARM microcontroller, and it is no problem to calculate the sinf function @48 kHz samplerate in stereo and 24 bit in realtime, if running with 168 MHz CPU clock.

Code: [Select]
/**
 * Generates a sin 943 Hz wave with a MAX5712, connected with SPI. Tested with a Mega2560 Arduino.
 * Samplerate works up to 24 kHz.
 * SCK: pin 52
 * MOSI: pin 51
 */
#include "SPI.h"

// pin numbers
const int ledPin = 13;
const int csPin = 12;

// signal generator
const float samplerate = 20000.0f;
const float frequency = 943.0f;
uint32_t increment = 1024.0f / samplerate * frequency * 4194304;  // multiplicator for 22 bit shift
uint32_t sinIndex = 0;
uint16_t nextValue = 0;

// 1024 values sin table, 12 bit unsigned
const uint16_t sinTable[] = {
  0x0800, 0x080c, 0x0819, 0x0825, 0x0832, 0x083e, 0x084b, 0x0857, 0x0864, 0x0870, 0x087d, 0x088a, 0x0896, 0x08a3, 0x08af, 0x08bc,
  0x08c8, 0x08d5, 0x08e1, 0x08ee, 0x08fa, 0x0907, 0x0913, 0x091f, 0x092c, 0x0938, 0x0945, 0x0951, 0x095d, 0x096a, 0x0976, 0x0983,
  0x098f, 0x099b, 0x09a7, 0x09b4, 0x09c0, 0x09cc, 0x09d8, 0x09e5, 0x09f1, 0x09fd, 0x0a09, 0x0a15, 0x0a21, 0x0a2e, 0x0a3a, 0x0a46,
  0x0a52, 0x0a5e, 0x0a6a, 0x0a76, 0x0a82, 0x0a8e, 0x0a99, 0x0aa5, 0x0ab1, 0x0abd, 0x0ac9, 0x0ad4, 0x0ae0, 0x0aec, 0x0af8, 0x0b03,
  0x0b0f, 0x0b1a, 0x0b26, 0x0b32, 0x0b3d, 0x0b48, 0x0b54, 0x0b5f, 0x0b6b, 0x0b76, 0x0b81, 0x0b8d, 0x0b98, 0x0ba3, 0x0bae, 0x0bb9,
  0x0bc4, 0x0bd0, 0x0bdb, 0x0be6, 0x0bf0, 0x0bfb, 0x0c06, 0x0c11, 0x0c1c, 0x0c27, 0x0c31, 0x0c3c, 0x0c47, 0x0c51, 0x0c5c, 0x0c66,
  0x0c71, 0x0c7b, 0x0c86, 0x0c90, 0x0c9a, 0x0ca4, 0x0caf, 0x0cb9, 0x0cc3, 0x0ccd, 0x0cd7, 0x0ce1, 0x0ceb, 0x0cf5, 0x0cff, 0x0d08,
  0x0d12, 0x0d1c, 0x0d25, 0x0d2f, 0x0d39, 0x0d42, 0x0d4b, 0x0d55, 0x0d5e, 0x0d67, 0x0d71, 0x0d7a, 0x0d83, 0x0d8c, 0x0d95, 0x0d9e,
  0x0da7, 0x0db0, 0x0db9, 0x0dc1, 0x0dca, 0x0dd3, 0x0ddb, 0x0de4, 0x0dec, 0x0df5, 0x0dfd, 0x0e05, 0x0e0e, 0x0e16, 0x0e1e, 0x0e26,
  0x0e2e, 0x0e36, 0x0e3e, 0x0e45, 0x0e4d, 0x0e55, 0x0e5d, 0x0e64, 0x0e6c, 0x0e73, 0x0e7b, 0x0e82, 0x0e89, 0x0e90, 0x0e97, 0x0e9f,
  0x0ea6, 0x0eac, 0x0eb3, 0x0eba, 0x0ec1, 0x0ec8, 0x0ece, 0x0ed5, 0x0edb, 0x0ee2, 0x0ee8, 0x0eee, 0x0ef5, 0x0efb, 0x0f01, 0x0f07,
  0x0f0d, 0x0f13, 0x0f18, 0x0f1e, 0x0f24, 0x0f2a, 0x0f2f, 0x0f35, 0x0f3a, 0x0f3f, 0x0f45, 0x0f4a, 0x0f4f, 0x0f54, 0x0f59, 0x0f5e,
  0x0f63, 0x0f67, 0x0f6c, 0x0f71, 0x0f75, 0x0f7a, 0x0f7e, 0x0f83, 0x0f87, 0x0f8b, 0x0f8f, 0x0f93, 0x0f97, 0x0f9b, 0x0f9f, 0x0fa3,
  0x0fa6, 0x0faa, 0x0fae, 0x0fb1, 0x0fb4, 0x0fb8, 0x0fbb, 0x0fbe, 0x0fc1, 0x0fc4, 0x0fc7, 0x0fca, 0x0fcd, 0x0fcf, 0x0fd2, 0x0fd5,
  0x0fd7, 0x0fda, 0x0fdc, 0x0fde, 0x0fe0, 0x0fe2, 0x0fe5, 0x0fe6, 0x0fe8, 0x0fea, 0x0fec, 0x0fee, 0x0fef, 0x0ff1, 0x0ff2, 0x0ff3,
  0x0ff5, 0x0ff6, 0x0ff7, 0x0ff8, 0x0ff9, 0x0ffa, 0x0ffb, 0x0ffb, 0x0ffc, 0x0ffd, 0x0ffd, 0x0ffe, 0x0ffe, 0x0ffe, 0x0ffe, 0x0ffe,
  0x0fff, 0x0ffe, 0x0ffe, 0x0ffe, 0x0ffe, 0x0ffe, 0x0ffd, 0x0ffd, 0x0ffc, 0x0ffb, 0x0ffb, 0x0ffa, 0x0ff9, 0x0ff8, 0x0ff7, 0x0ff6,
  0x0ff5, 0x0ff3, 0x0ff2, 0x0ff1, 0x0fef, 0x0fee, 0x0fec, 0x0fea, 0x0fe8, 0x0fe6, 0x0fe5, 0x0fe2, 0x0fe0, 0x0fde, 0x0fdc, 0x0fda,
  0x0fd7, 0x0fd5, 0x0fd2, 0x0fcf, 0x0fcd, 0x0fca, 0x0fc7, 0x0fc4, 0x0fc1, 0x0fbe, 0x0fbb, 0x0fb8, 0x0fb4, 0x0fb1, 0x0fae, 0x0faa,
  0x0fa6, 0x0fa3, 0x0f9f, 0x0f9b, 0x0f97, 0x0f93, 0x0f8f, 0x0f8b, 0x0f87, 0x0f83, 0x0f7e, 0x0f7a, 0x0f75, 0x0f71, 0x0f6c, 0x0f67,
  0x0f63, 0x0f5e, 0x0f59, 0x0f54, 0x0f4f, 0x0f4a, 0x0f45, 0x0f3f, 0x0f3a, 0x0f35, 0x0f2f, 0x0f2a, 0x0f24, 0x0f1e, 0x0f18, 0x0f13,
  0x0f0d, 0x0f07, 0x0f01, 0x0efb, 0x0ef5, 0x0eee, 0x0ee8, 0x0ee2, 0x0edb, 0x0ed5, 0x0ece, 0x0ec8, 0x0ec1, 0x0eba, 0x0eb3, 0x0eac,
  0x0ea6, 0x0e9f, 0x0e97, 0x0e90, 0x0e89, 0x0e82, 0x0e7b, 0x0e73, 0x0e6c, 0x0e64, 0x0e5d, 0x0e55, 0x0e4d, 0x0e45, 0x0e3e, 0x0e36,
  0x0e2e, 0x0e26, 0x0e1e, 0x0e16, 0x0e0e, 0x0e05, 0x0dfd, 0x0df5, 0x0dec, 0x0de4, 0x0ddb, 0x0dd3, 0x0dca, 0x0dc1, 0x0db9, 0x0db0,
  0x0da7, 0x0d9e, 0x0d95, 0x0d8c, 0x0d83, 0x0d7a, 0x0d71, 0x0d67, 0x0d5e, 0x0d55, 0x0d4b, 0x0d42, 0x0d39, 0x0d2f, 0x0d25, 0x0d1c,
  0x0d12, 0x0d08, 0x0cff, 0x0cf5, 0x0ceb, 0x0ce1, 0x0cd7, 0x0ccd, 0x0cc3, 0x0cb9, 0x0caf, 0x0ca4, 0x0c9a, 0x0c90, 0x0c86, 0x0c7b,
  0x0c71, 0x0c66, 0x0c5c, 0x0c51, 0x0c47, 0x0c3c, 0x0c31, 0x0c27, 0x0c1c, 0x0c11, 0x0c06, 0x0bfb, 0x0bf0, 0x0be6, 0x0bdb, 0x0bd0,
  0x0bc4, 0x0bb9, 0x0bae, 0x0ba3, 0x0b98, 0x0b8d, 0x0b81, 0x0b76, 0x0b6b, 0x0b5f, 0x0b54, 0x0b48, 0x0b3d, 0x0b32, 0x0b26, 0x0b1a,
  0x0b0f, 0x0b03, 0x0af8, 0x0aec, 0x0ae0, 0x0ad4, 0x0ac9, 0x0abd, 0x0ab1, 0x0aa5, 0x0a99, 0x0a8e, 0x0a82, 0x0a76, 0x0a6a, 0x0a5e,
  0x0a52, 0x0a46, 0x0a3a, 0x0a2e, 0x0a21, 0x0a15, 0x0a09, 0x09fd, 0x09f1, 0x09e5, 0x09d8, 0x09cc, 0x09c0, 0x09b4, 0x09a7, 0x099b,
  0x098f, 0x0983, 0x0976, 0x096a, 0x095d, 0x0951, 0x0945, 0x0938, 0x092c, 0x091f, 0x0913, 0x0907, 0x08fa, 0x08ee, 0x08e1, 0x08d5,
  0x08c8, 0x08bc, 0x08af, 0x08a3, 0x0896, 0x088a, 0x087d, 0x0870, 0x0864, 0x0857, 0x084b, 0x083e, 0x0832, 0x0825, 0x0819, 0x080c,
  0x0800, 0x07f3, 0x07e6, 0x07da, 0x07cd, 0x07c1, 0x07b4, 0x07a8, 0x079b, 0x078f, 0x0782, 0x0775, 0x0769, 0x075c, 0x0750, 0x0743,
  0x0737, 0x072a, 0x071e, 0x0711, 0x0705, 0x06f8, 0x06ec, 0x06e0, 0x06d3, 0x06c7, 0x06ba, 0x06ae, 0x06a2, 0x0695, 0x0689, 0x067c,
  0x0670, 0x0664, 0x0658, 0x064b, 0x063f, 0x0633, 0x0627, 0x061a, 0x060e, 0x0602, 0x05f6, 0x05ea, 0x05de, 0x05d1, 0x05c5, 0x05b9,
  0x05ad, 0x05a1, 0x0595, 0x0589, 0x057d, 0x0571, 0x0566, 0x055a, 0x054e, 0x0542, 0x0536, 0x052b, 0x051f, 0x0513, 0x0507, 0x04fc,
  0x04f0, 0x04e5, 0x04d9, 0x04cd, 0x04c2, 0x04b7, 0x04ab, 0x04a0, 0x0494, 0x0489, 0x047e, 0x0472, 0x0467, 0x045c, 0x0451, 0x0446,
  0x043b, 0x042f, 0x0424, 0x0419, 0x040f, 0x0404, 0x03f9, 0x03ee, 0x03e3, 0x03d8, 0x03ce, 0x03c3, 0x03b8, 0x03ae, 0x03a3, 0x0399,
  0x038e, 0x0384, 0x0379, 0x036f, 0x0365, 0x035b, 0x0350, 0x0346, 0x033c, 0x0332, 0x0328, 0x031e, 0x0314, 0x030a, 0x0300, 0x02f7,
  0x02ed, 0x02e3, 0x02da, 0x02d0, 0x02c6, 0x02bd, 0x02b4, 0x02aa, 0x02a1, 0x0298, 0x028e, 0x0285, 0x027c, 0x0273, 0x026a, 0x0261,
  0x0258, 0x024f, 0x0246, 0x023e, 0x0235, 0x022c, 0x0224, 0x021b, 0x0213, 0x020a, 0x0202, 0x01fa, 0x01f1, 0x01e9, 0x01e1, 0x01d9,
  0x01d1, 0x01c9, 0x01c1, 0x01ba, 0x01b2, 0x01aa, 0x01a2, 0x019b, 0x0193, 0x018c, 0x0184, 0x017d, 0x0176, 0x016f, 0x0168, 0x0160,
  0x0159, 0x0153, 0x014c, 0x0145, 0x013e, 0x0137, 0x0131, 0x012a, 0x0124, 0x011d, 0x0117, 0x0111, 0x010a, 0x0104, 0x00fe, 0x00f8,
  0x00f2, 0x00ec, 0x00e7, 0x00e1, 0x00db, 0x00d5, 0x00d0, 0x00ca, 0x00c5, 0x00c0, 0x00ba, 0x00b5, 0x00b0, 0x00ab, 0x00a6, 0x00a1,
  0x009c, 0x0098, 0x0093, 0x008e, 0x008a, 0x0085, 0x0081, 0x007c, 0x0078, 0x0074, 0x0070, 0x006c, 0x0068, 0x0064, 0x0060, 0x005c,
  0x0059, 0x0055, 0x0051, 0x004e, 0x004b, 0x0047, 0x0044, 0x0041, 0x003e, 0x003b, 0x0038, 0x0035, 0x0032, 0x0030, 0x002d, 0x002a,
  0x0028, 0x0025, 0x0023, 0x0021, 0x001f, 0x001d, 0x001a, 0x0019, 0x0017, 0x0015, 0x0013, 0x0011, 0x0010, 0x000e, 0x000d, 0x000c,
  0x000a, 0x0009, 0x0008, 0x0007, 0x0006, 0x0005, 0x0004, 0x0004, 0x0003, 0x0002, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001,
  0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, 0x0004, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009,
  0x000a, 0x000c, 0x000d, 0x000e, 0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001a, 0x001d, 0x001f, 0x0021, 0x0023, 0x0025,
  0x0028, 0x002a, 0x002d, 0x0030, 0x0032, 0x0035, 0x0038, 0x003b, 0x003e, 0x0041, 0x0044, 0x0047, 0x004b, 0x004e, 0x0051, 0x0055,
  0x0059, 0x005c, 0x0060, 0x0064, 0x0068, 0x006c, 0x0070, 0x0074, 0x0078, 0x007c, 0x0081, 0x0085, 0x008a, 0x008e, 0x0093, 0x0098,
  0x009c, 0x00a1, 0x00a6, 0x00ab, 0x00b0, 0x00b5, 0x00ba, 0x00c0, 0x00c5, 0x00ca, 0x00d0, 0x00d5, 0x00db, 0x00e1, 0x00e7, 0x00ec,
  0x00f2, 0x00f8, 0x00fe, 0x0104, 0x010a, 0x0111, 0x0117, 0x011d, 0x0124, 0x012a, 0x0131, 0x0137, 0x013e, 0x0145, 0x014c, 0x0153,
  0x0159, 0x0160, 0x0168, 0x016f, 0x0176, 0x017d, 0x0184, 0x018c, 0x0193, 0x019b, 0x01a2, 0x01aa, 0x01b2, 0x01ba, 0x01c1, 0x01c9,
  0x01d1, 0x01d9, 0x01e1, 0x01e9, 0x01f1, 0x01fa, 0x0202, 0x020a, 0x0213, 0x021b, 0x0224, 0x022c, 0x0235, 0x023e, 0x0246, 0x024f,
  0x0258, 0x0261, 0x026a, 0x0273, 0x027c, 0x0285, 0x028e, 0x0298, 0x02a1, 0x02aa, 0x02b4, 0x02bd, 0x02c6, 0x02d0, 0x02da, 0x02e3,
  0x02ed, 0x02f7, 0x0300, 0x030a, 0x0314, 0x031e, 0x0328, 0x0332, 0x033c, 0x0346, 0x0350, 0x035b, 0x0365, 0x036f, 0x0379, 0x0384,
  0x038e, 0x0399, 0x03a3, 0x03ae, 0x03b8, 0x03c3, 0x03ce, 0x03d8, 0x03e3, 0x03ee, 0x03f9, 0x0404, 0x040f, 0x0419, 0x0424, 0x042f,
  0x043b, 0x0446, 0x0451, 0x045c, 0x0467, 0x0472, 0x047e, 0x0489, 0x0494, 0x04a0, 0x04ab, 0x04b7, 0x04c2, 0x04cd, 0x04d9, 0x04e5,
  0x04f0, 0x04fc, 0x0507, 0x0513, 0x051f, 0x052b, 0x0536, 0x0542, 0x054e, 0x055a, 0x0566, 0x0571, 0x057d, 0x0589, 0x0595, 0x05a1,
  0x05ad, 0x05b9, 0x05c5, 0x05d1, 0x05de, 0x05ea, 0x05f6, 0x0602, 0x060e, 0x061a, 0x0627, 0x0633, 0x063f, 0x064b, 0x0658, 0x0664,
  0x0670, 0x067c, 0x0689, 0x0695, 0x06a2, 0x06ae, 0x06ba, 0x06c7, 0x06d3, 0x06e0, 0x06ec, 0x06f8, 0x0705, 0x0711, 0x071e, 0x072a,
  0x0737, 0x0743, 0x0750, 0x075c, 0x0769, 0x0775, 0x0782, 0x078f, 0x079b, 0x07a8, 0x07b4, 0x07c1, 0x07cd, 0x07da, 0x07e6, 0x07f3,
};

// send a word to the DAC
void sendDacWord(uint16_t word)
{
  digitalWrite(csPin, LOW);
  SPI.transfer(word >> 8);
  SPI.transfer(word & 0xff);
  digitalWrite(csPin, HIGH);
}

void setup()
{
  // init pins
  pinMode(ledPin, OUTPUT);
  pinMode(csPin, OUTPUT);
  digitalWrite(csPin, HIGH);

  // init SPI
  SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
  SPI.begin();  // additional begin is required, otherwise the second call to SPI.transfer hangs

  // send wakeup command to DAC
  sendDacWord(0xf000);
 
  // initialize timer1
  noInterrupts(); // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 16000000.0f / samplerate; // compare match register for IRQ with selected samplerate
  TCCR1B |= (1 << WGM12); // CTC mode
  TCCR1B |= (1 << CS10); // no prescaler
  TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
  interrupts(); // enable all interrupts
}

// timer 1 interrupt
ISR(TIMER1_COMPA_vect)
{
  sendDacWord(nextValue & 0x0fff);
  nextValue = sinTable[sinIndex >> 22];
  sinIndex += increment;
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}

Code to generate the sin table:

Code: [Select]
#!/usr/bin/python

import math
import sys

length = 1024

for i in xrange(length):
    s = math.sin(2 * math.pi * i / length) * 2047 + 2048
    sys.stdout.write("0x" + format(int(s), '04x') + ", ")
    sys.stdout.flush()
    if i % 16 == 15: print("")
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

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 #34 on: January 28, 2017, 08:17:17 am »
Cool! I read something like this some time ago.

But the interrupt uses timer 1, which means you can't use the Arduino PWM functions anymore.

I guess an 8 bit fast pwm could be still available on timer 0. (Uno, Mega, etc)
 

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 #35 on: January 28, 2017, 11:07:35 am »
It seems that the easiest change could be replacing R4 with a 5V light bulb (light bulbs are chasing me after all) and R3 with a 100K trimpot.
You will not find a light bulb with a warm resistance as high as 47k ohms so the value of R3 must be reduced a lot. You probably know that the opamp gain for a Wien bridge oscillator must be about 3. Also you need to use a power amplifier to drive the light bulb instead of an opamp.

I didn't know the resistance values for a light bulb. According to this, it's 115 ohms @ 5V. As the gain should be equal or greater than 3. R3 should not be greater than 200 ohms, that's why R4 is 47K? almost 1/2 of R3 with 100 Kohms?. Is that correct? So 100 Kohms is too high. I didn't know that an Op-Amp can't drive a ligh bulb.


I have many 0.1uF (104) capacitors. I guess It could work.
Don't guess, look at the input resistance of 50k ohms for the LM386 in its datasheet then calculate that a 0.1uF capacitor will pass frequencies above about 32Hz.

It should be about 0.0033uF for a 964hz frequency. I feel I'm at school again. is it correct?
« Last Edit: January 28, 2017, 11:11:50 am 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 #36 on: January 28, 2017, 11:37:31 am »
The LM386 can be used as a Wein bridge oscillator with a J-FET AGC circuit, rather than the light bulb suggested on the data sheet.



So options are:

1) Use LM358 and AGC with a JFET
2) Use LM386 and AGC with a light bulb
3) Use LM386 and AGC with a JFET
4) Use MAX5712.

I like them all and would like to build them for a learning aim but option 3 is quite tempting to finish this project. I can't see the RC network so clearly to calculate it's frequency but everything between 800-1200 Hz is fine. Does it require something else like an attenuator?
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: Best way to amplify a sine wave without distorsion.
« Reply #37 on: January 28, 2017, 11:44:42 am »
Hmm,

Am I the only one who has noticed this in the OPs post (emphasis mine)?

Quote
I want to amplify it to feed a VHF handheld radio mic with a minimum distorsion

Something like a LM386 is an enormous overkill there that will overdrive the radio. More likely what you need is a simple buffer for the oscillator/DAC/whatever you use to generate the signal and then an attenuator (= voltage divider). Microphone inputs take very small signals (in the order of milivolts), because there is an amplifier right there.

 
The following users thanked this post: HoracioDos

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: Best way to amplify a sine wave without distorsion.
« Reply #38 on: January 28, 2017, 12:23:59 pm »
Yes. If the OP needs only microphone-level, he doesn't need ANY kind of amplification at all.  If he has a 5V square wave (or even a 3.3V square wave), he can easily make a sharp (High-Q) filter to create a nice sine wave for a fixed frequency.  And even then likely require an attenuator (like a simple pot) to create mic-level.

OTOH, he also mentioned driving a speaker which was acoustically-coupled (?) to the transmitter microphone. Although that logic-level signal would likely drive a small dynamic speaker transducer.

Ham radio forums and websites are rich sources of exactly this kind of tone-generator.  This is a rather common project an the amount of pathos and drama here seems overwrought for such a simple task.
 

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 #39 on: January 28, 2017, 01:30:58 pm »
Ham radio forums and websites are rich sources of exactly this kind of tone-generator. 

I agree, there are a lot of circuits out there but not everything works as it is said. I attached a design in a previous post from QST Magazine for a Modulated CW keyer with transistors but It has a lot of distortion. I have another "proven" design with too many components, a lot more than the current circuit in discussion, are them really necesary?

Little example: Last month I've built two input/output radio interfaces (one for a yaesu and the other for a baofeng). I'm sure you know them (very easy project). Internet is full of them. They have a lot of low pass filters that are not needed or it's values doesn't make sense at all and in many cases are very risky. I made my own design with the components that are really necesary and they work just fine.

Google is not heaven.

This is a rather common project an the amount of pathos and drama here seems overwrought for such a simple task.

I love drama I'm a latin. It makes people to be humans.
 

Offline Audioguru

  • Super Contributor
  • ***
  • Posts: 1507
  • Country: ca
Re: Best way to amplify a sine wave without distorsion.
« Reply #40 on: January 28, 2017, 03:22:02 pm »
I didn't know that an Op-Amp can't drive a ligh bulb.
5V/115 ohms is an average current of 44mA and a peak of 62mA. The datasheet of the opamp tells you that its maximum output current is much less.

Quote
It should be about 0.0033uF for a 964hz frequency.
3.3nF into the 50k input of an LM386 produces a cutoff frequency of about 970Hz (I round it off a little) but then the fundamental frequency level is reduced to 0.707 times but the distortion frequencies remain at full level. Use a capacitor value 5 times more for no attenuation.
 
The following users thanked this post: HoracioDos

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #41 on: January 28, 2017, 05:27:47 pm »
The datasheet for the LM386 says that it becomes unstable if its gain is reduced to less than 9  but here it is 3. Do you think the capacitor between pin 1 and pin 8 reduces its high frequencies enough to make it stable with a gain of only 3?

I got the circuit off the datasheet but modified it, swapping the lamp for a J-FET. Unfortunately I made a mistake. I missed that the frequency determining resistors are different: 4k7 & 47k, so the gain needs to be much higher than 3 and the resonant frequency is 1kHz with C1 & C2 = 10nF and R1 = 4k7 & R2 = 47k.
 
The following users thanked this post: HoracioDos

Offline orolo

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: es
Re: Best way to amplify a sine wave without distorsion.
« Reply #42 on: January 28, 2017, 06:55:15 pm »
Last week I built a Wien bridge oscillator with an LM358 and a JKL 7210, miniature 5V 30mA light builb. It worked, giving a very clean sinewave. I think I still have the protoboard somewhere in the lab. I used a pot to set the gain; the circuit oscillates a little below the bulb's threshold of visibility. After building the circuit I thought it was doubtful anyone would care about that circuit, and just a week later there is a post about that very same thing! BTW, unless you want a very low distortion sinewave, why don't you try some of the many alternatives? In this page there is a great discussion about Wien bridge oscillators. I found they use far stouter bulbs than I used.
 
The following users thanked this post: HoracioDos

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16276
  • Country: za
Re: Best way to amplify a sine wave without distorsion.
« Reply #43 on: January 28, 2017, 08:10:14 pm »
Built one years ago, and, while I do actually have a RA53 or two around somewhere, I used a small 28VDC wire ended grain of wheat bulb as a control element. 28V 20mA IIRC, and it runs at a non glowing voltage, but still enough to give a good control of level in the oscillator.
 
The following users thanked this post: HoracioDos

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #44 on: January 28, 2017, 10:28:39 pm »
It seems that the easiest change could be replacing R4 with a 5V light bulb (light bulbs are chasing me after all) and R3 with a 100K trimpot.
You will not find a light bulb with a warm resistance as high as 47k ohms so the value of R3 must be reduced a lot. You probably know that the opamp gain for a Wien bridge oscillator must be about 3. Also you need to use a power amplifier to drive the light bulb instead of an opamp.

I didn't know the resistance values for a light bulb. According to this, it's 115 ohms @ 5V. As the gain should be equal or greater than 3. R3 should not be greater than 200 ohms, that's why R4 is 47K? almost 1/2 of R3 with 100 Kohms?. Is that correct? So 100 Kohms is too high. I didn't know that an Op-Amp can't drive a ligh bulb.
Using the correct circuit on the data sheet. The value of the bulb's resistance can be calculated.

See the formulae on Wikipedia:
https://en.wikipedia.org/wiki/Wien_bridge_oscillator#Wien_bridge

And compare the schematic to the one on the LM386 data sheet.






C1 = C2 = 10nF = 10×10-9
R1 = 4k7 = 4700
R2 = 47k = 47×103

Rf/Rb = 10×10-9/10×10-9 + 47×103/4700 = 1 + 10 = 11

The bulb is Rb and the 390R resistor Rf.

Therefore:
Rb = 390/11 = 35.5R

In real life RB needs to be slightly less because the amplifier has an open loop gain of much less than infinity: 200 in the LM386's case.

Quote
I have many 0.1uF (104) capacitors. I guess It could work.
Don't guess, look at the input resistance of 50k ohms for the LM386 in its datasheet then calculate that a 0.1uF capacitor will pass frequencies above about 32Hz.

It should be about 0.0033uF for a 964hz frequency. I feel I'm at school again. is it correct?



F = 1/(2pi(C1×C2×R1×R2)½)

F  = 1/(2pi(10×10-9×10×10-9×4700×R2 = 47k = 47×103)½) = 1.07kHz

Here's the correct version with the J-FET, based on the data sheet schematic.


If anyone is interested, I'll post the LTSpice file and LM386 model.
« Last Edit: January 29, 2017, 11:08:21 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 #45 on: January 29, 2017, 06:28:57 pm »
Shouldn't the RC frequency of the lowpass be the same as the RC frequency of the highpass?
 
The following users thanked this post: HoracioDos

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #46 on: January 29, 2017, 11:07:26 pm »
Shouldn't the RC frequency of the lowpass be the same as the RC frequency of the highpass?
No. The cut-off frequencies of both RC circuits don't have to be the same. They normally are the same because it makes the calculations and designing the circuit easier. If the two RC circuits are different, then it will still work but the attenuation factor at the resonant frequency is no longer 3.
 
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 #47 on: January 30, 2017, 07:50:13 pm »
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.
« Last Edit: January 30, 2017, 07:55:13 pm by HoracioDos »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #48 on: January 30, 2017, 11:43:17 pm »
I don't have KiCAD installed on this PC at the moment, so can't view that file now. I'll do tomorrow.

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.
 

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 #49 on: January 31, 2017, 12:09:47 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.
As far as I can understand, you had to recreate the LM386 internals in spice! What a huge job!

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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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!!!
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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?
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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?
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • 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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19491
  • Country: gb
  • 0999
Re: Best way to amplify a sine wave without distorsion.
« Reply #75 on: February 23, 2017, 09:05:49 am »
I'm glad to here that.

By the way, the symbols you used for the TL071 are not in the standard LTSpice library so others might not be able to see them. Fortunately it's possible to use one of the standard op-amp symbols in the LTSpice library and embed the model directly in the .asc file.

Use the symbol named opamp2 in the schematic, right click on it and set its value to TL071.

Open up TL071.sub (normally saved in LTspiceXVII\lib\sub) in a text editor. I use LTSpice's built-in text editor.

Select the whole file and copy it to the clipboard.

In the schematic, insert a SPICE directive, by clicking on the .op button, on the far right hand side of the tool bar.

Paste the file into the text box.

Click OK.

Place the text in a convenient part of the schematic, away from any symbols.

Now you can be sure you can post it on the Internet and others will still be able to read it.

Attached is the 555 timer version of the schematic you posted but with the TL072 model I have on my computer.
 

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 #76 on: February 23, 2017, 11:34:54 am »
Done! Thanks!!!
 

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 #77 on: February 23, 2017, 01:55:15 pm »
I want to order the op-amps. I can't find any difference now between TL07x and TL08x series. They are low noise now. What's I'm missing?

http://www.ti.com/assets/js/compareParts/compare.html?familyId=1562&parts=TL071,TL081&cols=o1,p480,p1261min,p1261max,p23typ,p22typ,p78,p2max,p1typ,p7typ,p1498,p1192,p2954,p1130&lang=en

A TL081 opamp is for  "general purpose". A TL071 is a TL081 selected for low noise (an audio opamp).
« Last Edit: February 23, 2017, 05:07:12 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 #78 on: March 03, 2017, 08:18:08 pm »
Bunch of oscillators
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf