I am trying to build a simple audio circuit. The goal is to store .wav files in the form of hex files in the ATMEGA328P's flash memory, and output the audio through a small speaker by using an MCP4921 DAC and an LM386N-1 Op Amp.

I uploaded a portion of my EAGLE schematic. The value of AMP_FIL_R is actually 0.05uF, instead of the 100uF indicated on the Eagle Schematic, and this is per the LM386 datasheet. Also, the code that I am running is attached. I started off with the code from here and added some code to play my hex file.

The Problem: Although I am able to output a meow, it is coming out with a lot of noise. So, it sounds like the final sound I actually desire is fully there, but high frequency noise is added on top of it.

The Question: What could be causing this noise? I have read a number of things could cause this. First, the LTC1514-5 power regulator I am using is in the 650kHz switching frequency range, so not sure if it is affecting the audio? Second, the LM386 op-amp itself, should it be farther away from the speaker? Unreliable connections in the breadboard? Proximity to bench equipment such as oscilloscope/meter/DC power supply?

Eagle Schematic

//"meow.h" file is stored as PROGMEM, char type variable

#include "avr/io.h"
#include "util/delay.h"
#include "HRL_SPI.h"
#include "HRL_MCP492x.h"
#include "meow.h"

void setup() {
  // Initiate SPI in Mode 0 with MSB first, NO interrupts and a clock of F_CPU/4   

int config = 0x30; //Mono, unbuffered, 1xGain, SHDN off  
word output = 0;  
word a=0; //index for meow array 

void loop() {

  if(a==sizeof(meow)) {Serial.print("again!"); delay(2000); a=0;}  
  output = pgm_read_byte(&(meow[a++]))*16; //Multiplied by 16 to go from 8 to 12 bits  

//  Serial.print("index:");  
//  Serial.print(a,DEC);  
//  Serial.print('\n');     
//  Serial.print("output:");  
//  Serial.print(output,DEC);  
//  Serial.print('\n');  
//  Serial.print('\n');    

  • \$\begingroup\$ What is the supply voltage for the LM386? You are aware that the 386 has a lot of gain, right? You are giving it a fairly high amplitude signal and amplifying it in the 386. Maybe you just have distortion from extreme clipping. \$\endgroup\$
    – JRE
    Oct 9, 2017 at 5:53
  • \$\begingroup\$ I am supplying it with 7V, 0.1 A from a DC Supply. Yes, I am aware of the high gain, but I did not understand how it actually amplified the signal. I'm understanding that now from the answer below. See my comment to the answer below for my adjustments. \$\endgroup\$ Oct 9, 2017 at 19:11

2 Answers 2



You connected the reference voltage of MCP4921 to its \$V_{DD}\$, through a filter. This means that \$V_{REF}\$ is either 3.3V or 5V (I guess 5 V, because of your LTC1514-5).

This means that your analog signal has a maximum 5V peak to peak value. The LM386 in that configuration has a gain between 20 and 200. Assuming a gain of only 20 (which I doubt, as there is a \$10\ \mu F\$ cap), you get \$100\ V_{pp}\$, which of course can't be achieved, also because the LM386 maximum operating voltage is 12V.

You can try:

  • inserting a resistor in parallel to DEC_C6, to reduce the reference voltage (it can be as low as 0.04V). Still noise performance will drop I guess.
  • Attenuate Vout_A. But again, not only the noise performance will drop, but it would be a very inefficient solution: you attenuate the signal and the you amplify it back.
  • or use some non amplifying speaker driver configuration, so that it won't saturate.

Anyway keep the 386 away from the switching regulator. In fact the 386 is very non linear outside its bandwidth, and therefore the 650 kHz noise could be picked up and brought in band.

  • \$\begingroup\$ Your answer definitely helped me get a better quality of output. I guess it wasn't noise but just clipping because of the high gain. I used a voltage divider like you suggested to get 0.25V at Vref, as well as open on the gain pins of the LM386 in order to get the default 20 gain. Still, the output of the speaker I am using sounds very quiet. I'm not sure why this is? I'm getting 5.2-5.6V peak to peak when I measure the output at the (+) side of the speaker with an oscilloscope. \$\endgroup\$ Oct 9, 2017 at 19:23
  • \$\begingroup\$ What is the maximum value of your sample in meow.h? \$\endgroup\$
    – next-hack
    Oct 9, 2017 at 19:42
  • \$\begingroup\$ 197 (unsigned char) \$\endgroup\$ Oct 10, 2017 at 1:05
  • \$\begingroup\$ The maximum peak to peak voltage you can achieve with 7V is about 5V @8 Ohm load. (figure 3 on datasheet. In agreement with your measurement. Notice that you are still close to saturation!). At 8 Ohm this means a maximum power (considering a square wave!) of 0.78W (beware: your speaker is 300mW!!). Your "meow" sample will likely have a much smaller power density, so you might be getting only 200-300 mW, or even less, which may appear as very low. \$\endgroup\$
    – next-hack
    Oct 10, 2017 at 6:08
  • \$\begingroup\$ Could you please explain how you came up with 0.78W? Also, what would be your recommendation to increasing power output? \$\endgroup\$ Oct 11, 2017 at 23:05

Posting a new answer to add to the accepted anser since I don't have the karma to comment:

@next-hack had a great answer regarding fixing the circuitry around the DAC, and there is room for improvement/tuning around the amplifier also.

They key is to measure/probe at the junctions of each block of the chain:

  • signal to DAC

  • signal from DAC which is signal to amp

  • signal from amp which is signal to speaker

  • ...etc.

Without having more details of the noise it is hard to pinpoint. As another question points out (link: LM386 audio amplifier not amplifying) and @next-hack alludes to, you have potential noise from propagation from another source (e.g. power supply) or from other coupling. If the power is from a battery or a linear regulator to the opamp and the DAC then you are more likely in good shape. If from a switching supply, or biased by one, then there is room for noise to creep in.

  • \$\begingroup\$ All good points. I actually got better results once I hooked up a 9V Lithium Ion Battery to the power supply, instead of using a DC Power Supply. Thanks, Raj. \$\endgroup\$ Oct 12, 2017 at 17:49
  • \$\begingroup\$ @user2608147 - If you're getting more noise with the DC Power Supply plugged in, check out the grounding scheme of your setup and also monitor the noise on the positive rail itself to see if it is a noise source. Also, this may suggest that you're susceptible to noise on the power source, so adding some filter caps there could help (common values: 10uF, 1uF, 100nF all in parallel). \$\endgroup\$
    – Raj
    Oct 12, 2017 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.