I am trying to create project using ESP 32 with arduino IDE which turns on when a snap is detected. I will be using using spw2430 mems mic datasheet here :Mems MIC Datasheet
Right now I using the Adafruit SPW2430 mems mic breakout board for testing purpose product site here
100 to 10kHz frequency resp VPP= 200mV Dc bias= 700mV Zout=450 Ohm
The problem I am facing is whenever i snap my fingers or clap my hand the output voltage goes up (as expected) BUT it takes a 4-5 seconds to come back to normal reading . Ideally it should not take that much amount of time to come back to normal reading. It should take 10 ms to come back to normal readings.
I am polling every 500 microseconds and the attenuation of the ESP32 has been set to 0 db so that the REF voltage scale is in 0 - 1V. this similar problem is happening with arduino uno (with same set of test conditions) . The input of adc is connected to the DC pin of the Breakout Board. (Which does NOT have any capacitor in between the o/p of mic and I/p of adc.)
I also have a voltmeter. I connected one probe to GND and OTher one to DC pin output of MEMS Mic. The voltage reading is 700mV. When I snap my finger it reaches 800mV immediately But It takes 4-5 seconds to come back to 700mV
Here is the code I am using
#include<esp32-hal-adc.h>
#define ANALOG_PIN 4
void setup()
{
pinMode(ANALOG_PIN,INPUT);
Serial.begin(115200);
/*
* typedef enum
{
ADC_0db, // 0 to 1 v
ADC_2_5db, // 0 to 1.27 v
ADC_6db, // 0 to 1.75 v
ADC_11db // 0 to 3.3 v
} adc_attenuation_t; // changes Ref Voltage Scale
*/
analogSetPinAttenuation(ANALOG_PIN,ADC_0db);
// Set the attenuation for particular pin currently 0-1 v
}
void loop()
{
int raw_value = 0; // to store raw value of mic
raw_value = analogRead(ANALOG_PIN); // Reading the op voltage of mic
Serial.print("Raw value is : ");
Serial.println(raw_value);
delayMicroseconds(500); // Sampling every 500 uSec
}
Your sample rate is low and the Serial prints are probably slowing-down your loop even more.
It shouldn't take seconds... If it's taking seconds you don't have audio... For example, a 1kHz tone has 2000 zero-crossings per second.* Your meter won't respond at audio-speed so it's not really helpful unless you're using continuous test-tones. Your meter will also be unpredictable with mixed AC & DC (which is what you have).
Of course, with the ~700mV bias you won't have zero-crossings but it should pass-through 700mV twice per cycle and you can subtract-out the bias in software. Half of your readings should be above the bias and half below the bias.
You should NOT have a series capacitor (and you shouldn't be using the AC connection) because the ADC can't read the negative half of the AC audio waveform.
P.S.
Here's what I'd suggest as an experiment... Make a "fast loop" (no delays) and take 100 or 1000 readings and just save maximum (throwing-way or ignoring any lower readings). Then print the result, reset 'maximum' to zero, and start your main-loop over. Do you know how to do that?
Alternatively, you could run the fast-loop for 100ms or 1 second, etc., using millis() timer.
I'd use the ac connection, and bias the arduino analog input side with 2 10k resistors - 5v rail, analog input, gnd.
That's not the problem...
The Adafruit description says the DC output is biased at 0.67V and the signal can go up to 1V peak-to-peak. That means the DC biased output can swing between 0.17 and 1.17V. Changing the bias would only change the bias. (I think the ESP32 runs at 3.3V so the equal-value resistors would give you 1.65V.)
I looked at the schematic and the only difference between the AC & DC outputs is a series capacitor on the AC output.
The Adafruit description says the DC output is biased at 0.67V and the signal can go up to 1V peak-to-peak. That means the DC biased output can swing between 0.17 and 1.17V. Changing the bias would only change the bias. (I think the ESP32 runs at 3.3V so the equal-value resistors would give you 1.65V.)
I looked at the schematic and the only difference between the AC & DC outputs is a series capacitor on the AC output.
Thank you for your answer But i think this problem is with the mems mic itself.Even without sampling for audio, just connection a dmm I was able to reproduce this error every time . I also have another mic . it is also showing the same behavior in both ac and dc pins.
"I also have a voltmeter. I connected one probe to GND and OTher one to DC pin output of MEMS Mic. The voltage reading is 700mV. When I snap my finger it reaches 800mV immediately But It takes 4-5 seconds to come back to 700mV"
this happens with both ac and dc pins . my only problem is why the output of the mems mic itself is taking time to reach the bias voltage. whether i snap loudly or quietly. It itself is acting like a slowly discharging capacitor.
I have removed the adc from the equation. The mic's op is connected the dso probe and dmm . i am able to view this even in the dso's output.
this happens with both ac and dc pins . my only problem is why the output of the mems mic itself is taking time to reach the bias voltage. whether i snap loudly or quietly. It itself is acting like a slowly discharging capacitor.
The AC output shouldn't have any DC voltage and it should read (nearly) zero volts with (near) silence.
But, you might need a load (~10k or 100k to ground) to kill any DC leakage through the on-board capacitor.
Another strange thing... There is no amplifier on the board. The specs for the microphone say -42dBV (about 10mV) at 94dB SPL. Your finger-snap isn't that loud so I don't know why you're seeing a 100mV jump when you snap your fingers.
It would take 20dB more (114dB SPL) to get 100mV. (Those are RMS voltages, so the peak would be greater, but it should have to be very loud to get 100mV added to the bias.)
The mic's op is connected the dso probe and dmm . i am able to view this even in the dso's output.
DVDdoug:
The AC output shouldn't have any DC voltage and it should read (nearly) zero volts with (near) silence.
Yes When dmm probe is connected to AC pin . It is working as expected. the reading is 0 in near silence. When i snap my finger the reading immediately reaches to 50 . BUT again it takes 4-5 sec to return back to 0 .
DVDdoug:
Another strange thing... There is no amplifier on the board. The specs for the microphone say -42dBV (about 10mV) at 94dB SPL. Your finger-snap isn't that loud so I don't know why you're seeing a 100mV jump when you snap your fingers.
I am snapping my fingers 10 cm from the mic.
I also have a Bc 547 transistor to use as an amp if i want to amplify the signal to detect snaps from longer range.(Right now i am not using it .ALL the readings are raw output for the mic itself)
DVDdoug:
But, you might need a load (~10k or 100k to ground) to kill any DC leakage through the on-board capacitor.
Thank you i will try this with small medium and large resistance value and see if my problem is solved.
Where should i attach this to ? Shall i attach this to the mic's output ?
manveen_singh:
I also have a voltmeter. I connected one probe to GND and OTher one to DC pin output of MEMS Mic. The voltage reading is 700mV. When I snap my finger it reaches 800mV immediately But It takes 4-5 seconds to come back to 700mV
You shouldn't care at all about the DC value, its an audio signal. High pass filter your sampled stream to the
audio band, since its range is 100--10kHz, perhaps a 50Hz high pass filter will do.
This can be done using the existing AC output coupling cap. Connect it to two 680 ohm
resistors, one going to ground and the other to Vcc. Also connect it to your analog input
implace of the DC pin.
Your samples are now centred mid-rail, and high pass filtered with a cutoff about 50Hz, so that
the DC recovery slope you see will all but vanish from the readings.
MarkT:
Your samples are now centred mid-rail, and high pass filtered with a cutoff about 50Hz, so that
the DC recovery slope you see will all but vanish from the readings.
Thank you for your suggestion . I will try this. Can you explain how will this remove (or reduce) the recovery time ?
is it because the ac ripples that slow down the recovery time have low frequency and can be filtered out by the Cap and those 2 resistors ?
I also would like to share one obeservation .
VCC is 3.3V and fully noise free. and nothing is connected to GND pin. I have connected the DMM probe to the DC pin .
Surrounding is silent and quiet.
Reading on DMM is 700 mV .
I snap my finger
Reading reaches 760mV
now it starts decreasing quickly .after 3 sec it reaches 710mV
then after 6 seconds (after snap) it reaches 705mv
then after 10 sec (after snap) it reaches 702mV
After 13 sec it reaches 700 mV.
this happens every time . I also have another dev board . that one also shows same behaviour every time
I have attached My schematic and breakout board schematic and circuit image on my original question .
Right now there is no discharge path. but i have experimented in finding various discharge path.
I have tried
connecting 10k ,1.2k , 330 ohm resistor between DC pin and gnd.
connecting 10k ,1.2k , 330 ohm resistor between AC pin and gnd.
connecting 1uF cap between dc and gnd and ac and gnd.
using resistors caused a dc shift and nothing else . the problem of slowly returning did not go away
using cap did nothing.
Can you please suggest me what component (and its value) should i place. And where should it place for a discharge path ?
I have attached My schematic and breakout board schematic and circuit image on my original question .
No you didn’t, you attached two seemingly unrelated schematics an a picture of something on a bread board. They are quite meaningless, they do not show all the components and how they are wired up. In fact the Arduino isn’t even on there.
Grumpy_Mike:
No you didn’t, you attached two seemingly unrelated schematics
Thanking for taking time and viewing these pictures . Buts that's what is have been telling that the circuit doesn't have anything connected .
The first schematic is the schematic of the breakout board i have been using .That is for anyone who would want to see the internals off the breakout .
The 2nd schematic is the schematic of the circuit i am testing on . As you can see Breakout board is connected to 3.3v Vin and GND and the Probes are connected to DC pin. Nothing else is connected on the Breadboard. No arduino , no resistors , no caps.
The 3 image is the picture of the whole circuit. That consisted of an empty bread board with 3.3V and GND connected to Power rails (Horizontal rails). and at one end only the breakout board is connected to power and gnd and dc pin is connected to the probes.
the image literally shows all the components connected to the board.
Grumpy_Mike:
In fact the Arduino isn’t even on there.
yes i wanted the isolate the source of the problem . so i removed literally everything else. Including arduino . And i found the the mic itself is exhibiting this behavior
Grumpy_Mike:
Have you tried what Allen said in reply #3?
Yes I have tried . that only changed the bias . Instead of reducing the recovery time.
Seems Adafruit has used a coupling capacitor with a too high value (10uF).
With a 10k:10k voltage divider (5k impedance), I calculate a high-pass corner frequency of about 3.2Hz.
Try a 10k:10k divider between 3.3volt and ground of the ESP, with the tap connected to the analogue pin.
And a ~220n coupling capacitor between sensor output and analogue pin.
Doesn't matter if you use the AC or DC output.
Leo..