Audio Noise: ATMEGA328P, MCP4921, and LM386

View previous topic View next topic Go down

Audio Noise: ATMEGA328P, MCP4921, and LM386

Post by kanni on Fri Dec 08, 2017 2:19 am

Get some advice for my question. 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 http://www.kynix.com/Detail/174669/LM386N-1.html  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?


//"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() {
 Serial.begin(9600);  
 // Initiate SPI in Mode 0 with MSB first, NO interrupts and a clock of F_CPU/4  
 setupSPI(SPI_MODE_0, SPI_MSB, SPI_NO_INTERRUPT, SPI_MASTER_CLK4);  
 SETUP_DAC;  
 _delay_us(100);    
}

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');    

 writeMCP492x(output,config);    
 _delay_us(125);    
}

Thank you!

kanni
New Member
New Member

Number of posts : 1
Registration date : 2017-11-27

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum