Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Noise in playback using PWM on STK600 (ATmega2560)

Status
Not open for further replies.

Mandar Joshi

Member level 2
Joined
Mar 4, 2015
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
445
I am using STK600 (ATmega2560). I have configured timer 1 for 8-bit fast PWM and system clock is 4 MHz and PWM frequency is 15625 Hz. My wav file is sampled at 3906 Hz and it 8-bit unsigned PCM mono wav file.

First I connected speaker directly between PWM o/p pin and GND. This produces humming sound noise in background, it remains as long as playback is active.

Then I connected low pass RC filter such that R=680 Ohm and C=0.01uF i.e. cut off is 23405 Hz. But still noise appears. The original wav file doesn't produce any noise on PC. What could be the reason? Do I need to change filter?

I can post code if required. What could be the reason behind noise? Because original wav file doesn't contain any noise. Is it because other components present on STK600?
 

PWM frequency should be at least 10 times higher than sampled signal and low pass filter should be calculated for intermediate frequency between signal and pwm. Also, analog amplifier should isolate filter output from load to prevent resistance affect on signal.
 

Okay I will try by these calculations. Do you mean cut off should be between 3906(sample rate) and 15625(pwm frequency) in that case?
 

Actually I forgot to add one more thing I am using speakers with buit in power supply and amplifier.
 

Actually I forgot to add one more thing I am using speakers with buit in power supply and amplifier.

I have recently been working on something similar. I sampled at 11k2 8bit and wrote a PC app to package the audio files into a hex file for uploading into a serial flash memory of 32Mb. I was looking to have a meter read out is values and to provide audio prompts for calibration screens. In the pic I used a 11k period with about 3k6 steps in the period. I scaled the 8bit sample data to 3600/256 to get the best range.
The pwm interrupt fetches a byte from the serial flash each period and has an index to the position in the serial flash for each word to be spoken.
The output pin on the pic drives a bs170 mosfet which in turn drives a small speaker directly. The speaker is tied to 5v on one leg and the other is pulled low by the mosfet. There is a 27ohm resistor in series with the speaker and a reverse diode across it for protection.

As simple as it is it provides very acceptable audio for the use and is very easy to implement. The speaker itself filters much of the noise because of its poor response and this is helpful.

In your case you are using a powered speaker and this arrangement will bring out all the rubbish in the signal so you have to approach it as suggested by others by using a faster period, more sample bits and a couple of stages of filtering.

Regards,
John.
 

John, do you mean I have to use higher sampling rate for my WAV file?
 

Faster sampling and higher bit rate improve sound but in embedded micros your pwm is usuall quite limitted so you use what you have got.
I used 11.75kHz and 8bit in a PIC 18F2553 because that is the nearest I cound get to ideal. In a dsPIC33F128MC802 I used 11K and that yielded a steps per period of around 3k6 so had to scale the 8 bit value up to utilise this. I did a floating point operation here to yeld the best result.
Both pics sounded the same.
Have a good read of the processor manual for your device and particularly the dividers to get to you desired frequency while still attaining you desired sample bit size.

Regards John.
 

Well, in my case highest possible PWM frequency is 31250 Hz. One thing I observed is almost no noise when sampling and PWM both are 31250 Hz or sampling is 15625 Hz and PWM is 31250 Hz.
But this question has always puzzled me, what should be the relation between sampling frequency and PWM frequency for better audio quality?
 

Higher sampling frequency is always better but your little micro has to be able to handle it. If so then fine. In many cases with smaller processor you have to do the best you can and in most cases it is ok. Don't forget the telephone is only 8bit at best and I think 8kHz and for the purpose is OK.
There is plenty of info on the web about all this kink of thing.
Regards,
John.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top