Trying to play some WAV files from an SD card in Arduino Nano, but I have noise at the output, but only after the low pass filter. This was unespected, and could not find a solution to this.
Removing the 10nF capacitor I get the PWM frequency, but no audible noise. With the 10nF the PWM freq. gets low, but I get lots of noise.
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 8 //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h> // also need to include this library...
#include <SPI.h>
uint32_t DebouceTimer = 0;
TMRpcm tmrpcm; // create an object for use in this sketch
uint8_t channel = 0;
/**************************************************************/
void setup() {
/**************************************************************/
Serial.begin(115200);
if (!SD.begin(8)) {
Serial.println("SD initialization failed!");
} else {
Serial.println("SD initialization done.");
}
pinMode(4, INPUT_PULLUP);
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
tmrpcm.play("002.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}
//******************************************************************
void loop() {
//******************************************************************
if (digitalRead(4) == 0) {
if (millis() - DebouceTimer > 500 ) {
DebouceTimer = 0;
tmrpcm.play("003.wav", 1); //the sound file "music" will play each time the arduino powers up, or is reset
}
}
}
The noise is there in both cases, you just can't hear it when the signal amplitude is high.
Once you put in the LPF, you reduce the signal amplitude and now the noise now becomes apparent.
I suspect the noise is coming from the SD card signals, when the TRMpcm library accesses the card to read in the data.
You're right, the noise must be there all along, but why can't we hear it before the LPF?
It's not the SD card. Tried removing it and the noise is exactly the same.
I've made e video of this: Video removing the cap
You 'scope is showing 90kHz and I assume that's the PWM frequency.
Of course, that's not what you're hearing.
Yeah... I think without the filter you are saturating the amplifier at 90kHz and it's putting-out a square (or rectangle) wave that you can't hear, while killing anything else that you might hear.
Something similar would happen if you saturated it with DC, "slamming" the output at the maximum DC voltage (or at 0V) so that no signal could get through.
That's kind-of hard on the amplifier. (I wouldn't connect my hi-fi amp!) With the filtering it's not getting completely filtered-out so you are still running 90kHz into it and the amplifier itself might be freaking-out and generating noise, especially if it's a class-D amplifier (which has its own PWM-like switching). Or the noise may be coming from somewhere else.
..I think someone else has a similar problem recently. They weren't getting enough volume out of the amplifier. A couple of days later I realized that the amplifier was probably saturated with PWM.
At this point I usually direct you to my Web site to a page about decoupling. Unfortunately my internet service provider has pulled the plug on all webpages implemented as part of their package and left me high and dry. I only found out when I came to post you the link.
However, this is a way round the problem and requires you to take the file attached and decompress it. There will be a folder and a browser icon when you do. Just double click on the browser icon and your web browser should open the file. Let me know if it works please.