I am using the MSGEQ7 to gather audio data from my computer to drive some LEDs using the ATMega328 microcontroller. The schematic I am using to connect the MSGEQ7 to the microcontroller is the one from the MSGEQ7 data sheet.
The problem I am currently having are the appearance of random "spikes" when there is no audio data (i.e. the music is turned off). What I would like to do is eliminate these random spikes. I have tried some software solutions which have not fully worked. I am curious if anyone knows of a way I can eliminate some of the noise between the signal source and input to the MSGEQ7 and from the MSGEQ7 to the analog input using circuits/hardware.
Okay, so I did some testing. First I set up the serial monitor and began watching values of A0. Then I began by connecting the input of the MSGEQ7 to ground which resulted it little change in the values seen on the serial monitor. When I pulled A0 to ground the values went to zero. So it looks like the noise is coming from the MSGEQ7 or along the wire connecting the output of the MSGEQ7 to the analog input of the ATMega328. Then I enabled the internal pullup resistor on A0 which has has helped reduce the noise quite a bit. There are very few "spikes" when connected to the computer/iPod. However, the input to the MSGEQ7 is unplugged from the computer/iPod there is a ton of noise again. Shorting the input of the MSGEQ7 to ground reduces the "spikes" enough to barely show up. I am guessing all of this noise is just induced current in the wires from ambient EMI.
I used some RG-58A/U cable for the analog signal wire and some shielded 18-6 wire for the audio signal wires. Grounded the shield at one end and problem solved.
After looking at the msgeq7 datasheet I modified the code listed above in an attempt to get the timing closer to
tr - Reset Pulse Width
100 nS min
trs - Reset to Strobe
Delay
72 uS min
ts - Strobe Pulse Width
18 uS min
tss - Strobe to Strobe
Delay
72 uS min
to - Output Settling Time
36 uS min
int analogPin = 0; // read from multiplexer using analog input 0
int strobePin = 2; // strobe is attached to digital pin 2
int resetPin = 3; // reset is attached to digital pin 3
int spectrumValue[7]; // to hold a2d values
void setup()
{
Serial.begin(9600);
pinMode(analogPin, INPUT);
pinMode(strobePin, OUTPUT);
pinMode(resetPin, OUTPUT);
analogReference(DEFAULT);
digitalWrite(resetPin, LOW);
digitalWrite(strobePin, HIGH);
}
bufferEQ();
void loop()
{
bufferEQ();
}
void bufferEQ() {
digitalWrite(resetPin, HIGH);
digitalWrite(resetPin, LOW);
delayMicroseconds(72);
long strobePulseStart = 0;
for (int i = 0; i < 7; i++)
{
delayMicroseconds(36); // to allow the output to settle
digitalWrite(strobePin, LOW);
strobePulseStart = micros();
spectrumValue[i] = analogRead(analogPin);
delayMicros(constrain(18 - (micros() - strobePulseStart), 0, 18)); // finish strobe pulse width
digitalWrite(strobePin, HIGH);
delayMicros(constrain(72 - ((micros()-strobePulseStart) -18), 0 ,72)); // adjust for if the strobe pulse width went long
}
}
Please let me know this looks about right or if I am way off.
BTW: I had the same experience with the 0 signal with noise. I'll check out the
RG-58A/U cable for the analog signal wire and some shielded 18-6 wire for the audio signal wires
I spoke to John Ambrose (high up) at mix-sig and he reminded me that the device has a reasonable amount of amplification built in, so SOME noise at 0 is expected and should be compensated for in the code.