EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: blewisjr on October 06, 2013, 02:47:17 pm

Title: electret mic conversion to dc
Post by: blewisjr on October 06, 2013, 02:47:17 pm
Hello everyone

I understand an electret mix emitts an analog signal which is in the low millivolt range.

I need to hook up the mix to a uC analog input pin to trigger an interrupt when sound comes in.

the issue is see is that I need to
a) amplify the signal
b) filter out the neg voltages
c) filter further to remove signals below a threshold.

I am new to this stuff and I have no clue where to even begin.

My first thought was to use a voltage doubler to amplify which should remove the neg voltages.  I have no clue where to move from there.  Any thoughts?
Title: Re: electret mic conversion to dc
Post by: Thor-Arne on October 06, 2013, 03:45:37 pm
This page (http://www.alanmacek.com/usb/) shows how to hook up a electret microphone to a PIC microcontroller.

There's no negative voltage if the mic is connected like this, so it only needs to be amplified.

A diode and small RC network could provide some peak-hold (see EEVblog #490 (http://www.eevblog.com/2013/06/29/eevblog-490-peak-detector-circuit/)), if you need that.
The rest of the "filtering" can be done in software, just ignore the readings below a certain reading.
Title: Re: electret mic conversion to dc
Post by: blewisjr on October 06, 2013, 03:56:53 pm
From what I see from that it is already amplified.  So if I am thinking right I can just run the signal through a single opamp bandpass filter and be good?
Title: Re: electret mic conversion to dc
Post by: Thor-Arne on October 06, 2013, 04:04:59 pm
Yes, you can use a bandpass filter between that amp and the microcontroller.
Title: Re: electret mic conversion to dc
Post by: blewisjr on October 06, 2013, 04:36:15 pm
Ok thanks I will experiment with that on a simple example before I go all out on my project thanks again.
Title: Re: electret mic conversion to dc
Post by: blewisjr on October 08, 2013, 12:43:38 am
Ok I ran some tests and ran into nothing but issues haha.  The uC code works fine no issues there as it is technically possible for me to manually trigger the interrupt which switches the LED on.

From what I can see it seems as if the microphone is either...

a) not enough oomph (hard to get a reading with my multimeter seems really low)
b) not working at all   (not something I can really test I can read voltage on the other side of it)

Basically what I am doing here is feeding the mic power (uses the same pin for both input voltage and output voltage)

The output of the microphone is going through a single opamp (LM741) band-pass filter and then out to the micro input pin.

Not sure what is going on if I tap R1 with a multimeter just right I can get the interrupt to actually fire off.

I will attach the schematic for you guys to look at. Keep in mind this is built out on a breadboard.

Hopefully someone can pin point what is wrong probably my circuit or something because the code is fine it is just not getting the voltage it needs for the uC to recognize the pin change.
Title: Re: electret mic conversion to dc
Post by: Hideki on October 08, 2013, 01:07:00 am
You have connected the microphone right across the power rail, and the signal you send to the opamp is the 5V power, directly.
Now, that 5V is unlikely to change much even if you scream into the microphone. Let's hope the capsule survived the shock (it may be dead now).

What you need to do is to have a resistor from 5V to the mic. Ideally of a value that biases the output somewhere the middle (2.5V). It is then usually coupled into the next section through a capacitor, just like you see in Thor-Arne's link or here http://en.wikipedia.org/wiki/Electret_microphone (http://en.wikipedia.org/wiki/Electret_microphone).
Title: Re: electret mic conversion to dc
Post by: blewisjr on October 08, 2013, 02:23:39 am
still not having any luck with this.

The mic should be fine as it is rated to take a hit up to 10V max according to the data sheet.  However I still have the issue.  Right now with the way it is set up the output from the opamp is sitting around 2.8v and no sound at all even loud music will get the voltage to change going into the opamp.  I have it hooked up similar to what you see in Thors link except the resistor goes right to the rail instead of a controller pin.  Maybe I should try powering it via the controller instead?
Title: Re: electret mic conversion to dc
Post by: Skaface on October 08, 2013, 02:48:16 am
maybe you should listen to what hideki said
Title: Re: electret mic conversion to dc
Post by: blewisjr on October 08, 2013, 03:03:29 am
yes I did that.  The drop to the mic bias' around 2.4 volts actually then goes through a capacitor into the amplifier which comes out of the opamp again at 2.5 volt's ish.  When you tap, clap, or even play loud music there is no change at all anywhere so the interrupt never gets triggered but yet you can trigger it by tapping a resistor with a multimeter.

I apologize if I am not getting the point all this stuff is still new to me and I do not understand a lot of it.
Title: Re: electret mic conversion to dc
Post by: Psi on October 08, 2013, 03:05:45 am
Depending on your application, sound quality required and the MCU you're using you may be able to reduce your component count and remove the preamp by using the MCU's differential ADC channel with programmable gain.

Quite a few attiny/mega chips with an ADC also have differential channels and some gain options. 10x, 20x, 100x, 200x etc.

With one of the differential inputs connected to half VCC and the other connected to the electret mics output cap you should be able to read the MIC AC waveform from the mcu adc directly.
You can then rectify the signal in software if needed. Ignoring sounds below a threshold can also be done in software.
Title: Re: electret mic conversion to dc
Post by: blewisjr on October 08, 2013, 03:13:55 am
What I can see all this amp stuff is not working at all.  I do not have a adc with this chip I am using however only a analog comparator.  So I doubt this method would work.  I might be able to cut the voltage going into the mic and feed it into the comparator but I doubt the waveform would have a high enough amplitude to break the reference voltage to trigger the interrupt.

Another option may be to use a npn transistor circuit to gate the system to trigger the interrupt but I am not sure if I can get enough current to get the gate to flip either.

Sound quality is not what I need.  Basically I am trying to simulate what you would call a audio trigger.  The Controller senses the signal and then reacts by flipping a bit to turn on the led in this simple case. So for instance as you say clap the led toggles on and off.

This is just a experiment to see if I can get the simple case to work before it goes into my sound triggered stopwatch I am planning.

All I know is right now I am getting discouraged because nothing is working right  :'(

EDIT:  I decided what the heck lets lose the band-pass filter and try the gate strategy with the NPN transistor.  Figured what the hell everything else did not work.  BINGO!!!!! simplifying the preamp to use just a NPN gate did the trick with the digital input pin.  Thanks Psi for making me think a bit simpler by mentioning less parts.
Title: Re: electret mic conversion to dc
Post by: geraldjhg on October 14, 2013, 07:30:59 pm
an electret mic conected to vcc via a resistor with NO capacitor is all positive going and
will generate enough for an adc input via some 10k res for protection, not easy to
use as an interrupt source
once the idea works see how much you have to shift and or amplify it
Title: Re: electret mic conversion to dc
Post by: deth502 on October 14, 2013, 08:00:43 pm
im working on something similar and have had similar results. i had it working great with the transistor amplifying it, but wante more sensitivity (gain) and tried it with an op-amp. cant get the op-amp circuit to work for shit. if i have any epiphanies, ill let you know, but most likely ill give up and fall back to the bjt solution.