how to amplify digital audio signal that is fed into an analog speaker?

Go To Last Post
32 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I built a simple wav player at (http://www.technoblogy.com/show?...).  It plays nicely; however, I would like to amplify the digital signal.  The article says below.

 

" There's no amplifier, so the volume depends on the supply voltage, VIN, and the sensitivity of the loudspeaker; generally, larger is better. Note that if you want to feed the output to an audio amplifier you should include a simple low-pass filter; otherwise the 250kHz carrier could damage the amplifier: "

 

I put in the low pass filter as shown in the image attached, and whipped up an LM386-1 amplifier circuit with VCC as 5V input.  The speaker now connected to the LM386's amplified output pin, but all I hear is garbles!

 

I did the same with the PAM8403 amplifier chip.  Still just garbled stuff heard.

 

Attached also is the LM386 amplifier circuit used.

 

Thanks for any suggestion/tip/help.

Attachment(s): 

Last Edited: Sun. Dec 20, 2020 - 05:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may want to post the amplifier circuit you used. ie

 

The speaker now connected to the LM386's amplified output pin, but all I hear is garbles!

Via,say, 220uf electrolytic cap??

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

You may want to post the amplifier circuit you used. ie

 

The speaker now connected to the LM386's amplified output pin, but all I hear is garbles!

Via,say, 220uf electrolytic cap??

 

Here is the amplifer circuit used.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That looks good, may want to double check your wiring around the low pass filter then.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your posted schematic amplifies your signal by 200. If your LM386 is powered at 5V your input signal maximum would be 25mV (single supply referenced) to stay below saturation of the amplifier.

I would expect the signal to the amp is greater than 25mV, so you will get in saturation. You can check whether this happens by looking at the output signal (e.g. with an oscilloscope) or

you could create a very silently audio file and check whether the output is clear than. To solve this problem your LM386 amplification must be decreased (see LM386 datasheet), e.g. remove cap between pin 1 and 8 of the LM386 will result in a gain of 20.

To get a louder volume you will have to increase the voltage for the LM386 from 5V to 12V (maximum of LM386).

 

Hope this helps

 

Flo1991

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Please see Tip #1 in my signature, below, for how to put the pictures in the post,  where we can see them - like this:

 

 

unebonnevie wrote:
I would like to amplify the digital signal

the amplifier you've shown is an analogue amplifier - a digital amplifier would just be a switch, switching a higher voltage than your microcontroller's output...

 

As  Flo1991  said, a 5V input is likely to overload & distort that amplifier

 

Flo1991 wrote:
an oscilloscope

+1

 

as we're talking audio here, a PC soundcard could be used ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know if you apply Ohms law it will say this is a no-no but if you simply put an 8 Ohm speaker on a PWM pin with no filter, no amp, no nothing it actually works pretty well. Even better if you use a "sound chamber" which consists on an empty plastic cup over the speaker.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
if you apply Ohms law it will say this is a no-no 

if you take the "8 ohms" as purely resistive - but  there's also inductance and the speaker is, essentially, being a motor...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I know if you apply Ohms law it will say this is a no-no but if you simply put an 8 Ohm speaker on a PWM pin with no filter, no amp, no nothing it actually works pretty well.

 

Well, each time you see a resistor that's precious power being wasted, so it's normal that it works well. The speaker itself acts as filter, after all it has inductance, resistance and mechanical drag that will filter high frequencies (the PWM carrier frequency and its harmonics).

Anyway, to do things "properly" the OP should read about class D amplifier output stages. Class D are the amplifier types that use PWM, there is plenty of literature around. Though normally they use 2 complementary PWM waves to increase power output (like we often do to drive piezo buzzers), while the OP circuit has only one PWM output.

Some circuit examples and equations to calculate component values can be found here, for instance:

https://www.maximintegrated.com/en/design/technical-documents/app-notes/6/624.html

Last Edited: Sun. Dec 20, 2020 - 04:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  As far as I can tell, your circuit is emulating a Class-D audio amplifier.   The timer has been set using a special PLL mode to count from 0 to 255 about 10,000 times a second.  At the 00 count, the output is set to logic high.   A single WAV sample is fetched from the file.  It's range is 0-255.  When the timer count reaches the WAV sample value, the output pin goes low.  The count continues up to 255.  This is a PWM signal that uses a 10K sweep/second instead of the @400 sweep/second PWM that normally gets made by a Tiny85 timer.

 

  When the output pin is filtered through the 220uF cap and the inductance of the speaker, you hear a faint but clear audio reproduction of the WAV file. 

On the LM386, the cap between pins 1 and 8 really boosts your signal.  So turn the input pot very low for starts. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Flo1991 wrote:

Your posted schematic amplifies your signal by 200. If your LM386 is powered at 5V your input signal maximum would be 25mV (single supply referenced) to stay below saturation of the amplifier.

I would expect the signal to the amp is greater than 25mV, so you will get in saturation. You can check whether this happens by looking at the output signal (e.g. with an oscilloscope) or

you could create a very silently audio file and check whether the output is clear than. To solve this problem your LM386 amplification must be decreased (see LM386 datasheet), e.g. remove cap between pin 1 and 8 of the LM386 will result in a gain of 20.

To get a louder volume you will have to increase the voltage for the LM386 from 5V to 12V (maximum of LM386).

 

Hope this helps

 

Flo1991

 

 

 

Thank you! I decided to remove all the 10uF capacitors, especially the one between pins 1 and 8, of the LM386. I also remove the 250uF, 0.05uF, and 10ohm resistor at the output of the LM386.  The only thing left is the low pass filter at the input to the LM386.   IT WORKS! BUT, a couple problems observed.

 

Also, my LM386 circuit on a breadboard!

 

 

1) there is a hissing sound in the background at the output, only when the music plays.  It's like that 60hz sound from a power supply. I would need to put a high pass filter at the output to get rid of that 60hz?  Wondering if this is because of the breadboard.  But I think this is more because a breadboard is used.  With proper background plane on a real board, this noise should go away?

 

2) My speaker is an 8ohm speaker, so if I crank it up more than mid way of the potentiometer, distortion starts to take place.  OR if the song gets loud, distortion.  I would have turned down (via the potentiometer) a bit to get rid of the distortion.  So, obviously the LM386 puts out too much for the little 8ohm speaker, when the music output's wave amplitude is high.

 

3) If I hook up a 2nd 8ohm speaker to the output of the LM386, where the first speaker is hooked up, things get messed up badly, just garbled sound.

 

All, thank you also for your input that you have posted.

 

I am think of using a TDA7052A.

 

 

or the MP7705

 

Last Edited: Sun. Dec 20, 2020 - 06:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I'd suggest that you really need a scope. For audio it doesn't need a huge bandwidth so even a low cost ebay thing offering 1MHz should be able to resolve 0..20kHz audio.
.
For example £12 gets this fun DIY project..
.
https://uk-m.banggood.com/Wholesale-Warehouse-Original-JYETech-DSO138-DIY-Digital-Oscilloscope-Unassembled-Kit-SMD-Soldered-13803K-Version-wp-Eu-984002.html?rmmds=search&act_poa=SKU243635&cur_warehouse=UK

Last Edited: Sun. Dec 20, 2020 - 06:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

unebonnevie wrote:
 there is a hissing sound in the background at the output, only when the music plays.  It's like that 60hz sound from a power supply.

That would normally be called "hum"; a "hiss" would describe a high frequency sound - like the sound of steam escaping under pressure.

 

I would need to put a high pass filter at the output to get rid of that 60hz?

That depends where it's coming from.

 

It could be coming from ripple on your power supply - in which case you need to fix the power supply.

 

Or it could be getting picked up from nearby fields. However, from your other comments,  it sounds like you have a high signal level - so the hum would have to be really bad to be heard above it.

 

As others have said, you really need an oscilloscope so that you can see what's going on.

 

 Wondering if this is because of the breadboard. 

Quite possibly - post some good, clear, in-focus pictures of the setup for people to comment.

 

obviously the LM386 puts out too much for the little 8ohm speaker

Not necessarily. As already noted, if you drive an amplifier's input too hard, that will cause distortion.

 

3) If I hook up a 2nd 8ohm speaker to the output of the LM386, where the first speaker is hooked up, things get messed up badly, just garbled sound.

That means you effectively have a 4-ohm load - which may be overloading the amplifier's output.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

BTW one way to do both scope and spectrum analysis on a PC is to use a DAW (for example Bandlab Cakewalk is now free) then plug in some scope and/or spectrum analysis VSTs into it (many good ones also free). This all just relies on a Mic/Aux audio input (Mic is just millivolts while Aux is "line level"). You can see me using scope and spectrum in this...
.
https://youtu.be/x_MWsZiLSOM?list=PLW9AmuscfjxmuEqHPQ2YzZ2lz7ehf6p1g
.
As my laptop doesn't have aux/mic I was using this at the time...
.
https://www.amazon.co.uk/dp/B07B628J7V?ref=ppx_pop_mob_ap_share

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd imagine Audacity could be used ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the source of your problems is the 5v used for the amp, a higher voltage is needed to get louder sounds!

Try using 12v for your amp supply.

 

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

That would normally be called "hum"; a "hiss" would describe a high frequency sound - like the sound of steam escaping under pressure.

 

You're correct.  It's more like hum.  Attached is my entire setup.  Both the ceramic caps on for the LM386 setup on the breadboard is 0.1uF, one for pin 6 and the other for the low pass filter.  The board, which has ground planes for both top and bottom, pushes out the PWM wave (the music) at 250Khz.

 

Quote:

It could be coming from ripple on your power supply - in which case you need to fix the power supply.

 

Or it could be getting picked up from nearby fields. However, from your other comments,  it sounds like you have a high signal level - so the hum would have to be really bad to be heard above it.

 

As others have said, you really need an oscilloscope so that you can see what's going on.

 

Will need to borrow a scope from a friend.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I think the source of your problems is the 5v used for the amp, a higher voltage is needed to get louder sounds!

Try using 12v for your amp supply.

 

I can try with 9V first to see how that goes.  Thanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What's that section that you've blanked out of the photo?

 

Please crop the extraneous bits.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote:
It could be coming from ripple on your power supply

One way to rule that out would be to try running it from batteries ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Some circuit examples and equations to calculate component values can be found here, for instance:

https://www.maximintegrated.com/en/design/technical-documents/app-notes/6/624.html

 

That is helpful, El Tangas!  Thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found what can help my problem.

 

https://www.sparkfun.com/tutoria...

 

The  TPA2005D1 is a class D amplifier for 250khz signal!

 

* I fixed your link. Ross *

Last Edited: Mon. Dec 21, 2020 - 06:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

that takes an analogue input signal, digitises it, and then amplifies it digitally.

 

You have a digital signal to start with - so you really don't need all of that.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The LM386 will do what you want if you pay attention to the circuit design. Forget all this talk of digital amplifiers; you don't need them. Your output is analogue so use an analogue amplifier.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
Your output is analogue

Well, the output from the ATtiny85 is digital - so that can be "amplified" digitally with nothing more than a simple switch.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I'm with Brian on this, the PWM output is digital, but using it as a DAC, after filtering out the high freq digital pulses, the OP has an analog signal with a 0-5 range, this is fed into a pot to act as an attenuator  to reduce the volume to be fed into the amp, But it still has a 0-5 volt range as shown.  Feeding this signal into the amp, at some point, 1/2 or 3/4 volume it will overload the input to the amp.

I would suggest the OP add a voltage divider to his PWM output after the LP filter/cap to bring the max volume to 1v peak to peak.

Then any line voltage amp should give the volume the OP needs, but as stated above, may need a higher voltage to reach the output watts needed without distortion.

 

Jim

 

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Brian Fairchild wrote:
Your output is analogue

Well, the output from the ATtiny85 is digital - so that can be "amplified" digitally with nothing more than a simple switch.

 

I'd suggest that you'd want to keep as much energy out of the 250kHz square waves as possible unless one of the project goals is to blot out most of the RF signals in the area.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Should be easy to find a 1v p-p line in amp prebuilt and ready to use.

 

FF = PI > S.E.T

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


 

Something like this...

 

Input to the LM386 with the volume control at full...

 

 

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

Last Edited: Mon. Dec 21, 2020 - 02:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you wanted to be really clever then you could treat the LM386 as a power op-amp and build an active filter around it to achieve a better filter.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR335 - just sayin' ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
AVR335 - just sayin' ;-)

AKA: AN 1456  https://www.microchip.com/wwwApp...

 

FF = PI > S.E.T