Arduino Forum

Using Arduino => General Electronics => Topic started by: nickgammon on Oct 05, 2013, 07:27 am

Title: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 05, 2013, 07:27 am
Now that we have the microphone experts here, can I ask a question?

I have a couple of microphones (I think) that look like this:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191223a.png)

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191223b.png)

I'm not at all sure how to wire them up, but I used this circuit for a sound detector and it seemed to work:

(http://www.gammon.com.au/images/Arduino/Flash_Detector_Circuit.png)

If there are any egregious errors, please let me know. :)

This particular circuit was for firing a flash, full description here:

http://www.gammon.com.au/forum/?id=11671
Title: Re: How to make a pre-amp for a electret? microphone
Post by: MarkT on Oct 06, 2013, 02:51 am
For audio amplification I think you need to provide a virtual ground near mid-supply
to allow decent signal swing without clipping - not an issue for a sound detector.  The LM358
has an input noise voltage of 40 nV/sqrt-Hz, so not low-noise.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: dc42 on Oct 06, 2013, 10:07 am
To expand on Marks' reply, for the "virtual ground" I suggest you add a 220K resistor between pin 3 of the LM358 and +5V, and put a 10uF capacitor in series with R1. This will keep the LM358 in the linear region. The reason for using 220K rather than 100K is that the LM358 does not have rail to rail output, instead its output can go from just above zero to about +3V (depending on load) when running from a 5V supply.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 06, 2013, 11:20 am
Virtual ground, right.

If you want to suggest a better op-amp, I'm all ears. :)

Your advice may help me with my grandfather clock tick-detector.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: MarkT on Oct 06, 2013, 12:20 pm

To expand on Marks' reply, for the "virtual ground" I suggest you add a 220K resistor between pin 3 of the LM358 and +5V, and put a 10uF capacitor in series with R1. This will keep the LM358 in the linear region. The reason for using 220K rather than 100K is that the LM358 does not have rail to rail output, instead its output can go from just above zero to about +3V (depending on load) when running from a 5V supply.


No, that's not right, both opamp inputs refer to ground, and virtual ground has to be
stiff.   The traditional way is to split supply with a resistor divider (plus a decoupling
capacitor to true ground), use a unity-gain opamp stage to stiffen it up (make a low-
impedance virtual ground)

This diagram I found is the idea
(http://tangentsoft.net/elec/bitmaps/vgrounds/vfb-opa.png)
(but you need to decouple the lower resistor in the divider or you have
a large noise-source!  The output resistor isn't useful either.  The opamp
used should be low-noise if your circuit needs to be low-noise.

In the original circuit the feedback network has a 1k resistor to ground from pin 2 - that also
needs to go to virtual ground and that ground has to source/sink current without
changing, hence the need for an actively buffered virtual ground.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: dc42 on Oct 06, 2013, 08:25 pm


To expand on Marks' reply, for the "virtual ground" I suggest you add a 220K resistor between pin 3 of the LM358 and +5V, and put a 10uF capacitor in series with R1. This will keep the LM358 in the linear region. The reason for using 220K rather than 100K is that the LM358 does not have rail to rail output, instead its output can go from just above zero to about +3V (depending on load) when running from a 5V supply.


No, that's not right, both opamp inputs refer to ground, and virtual ground has to be
stiff.   The traditional way is to split supply with a resistor divider (plus a decoupling
capacitor to true ground), use a unity-gain opamp stage to stiffen it up (make a low-
impedance virtual ground)


Mark, why do you think the virtual ground needs to be "stiff"? It only needs to be stiff if a load is placed between the output and the virtual ground - and I don't think Nick is proposing to do that. In which case, there is absolutely no need to use an op amp to generate a virtual ground.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: fungus on Oct 06, 2013, 10:06 pm
What accuracy do you need? Electrets work quite well without pre-amps if all you need to do is detect noises.

Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 06, 2013, 10:11 pm
I was hoping to detect a clock ticking.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 06, 2013, 10:28 pm
Not very sensitive without a preamp or amp. On the order of 1mV out at conversation levels. Are you sure you aren't thinking of piezo mics?
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 06, 2013, 10:38 pm
Just an idea of something to experiment with ... after all, analog electronics is a lot about tweaking until it works the way you want.

Try an LM386 for the gain amp. May be too noisy running off the same v.reg as a cpu, but if it works ok, and you laid out a pcb for this, then more or less the same ckt with a few component changes could be used for either electret amp'ing or speaker output. Just a thought.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 06, 2013, 10:41 pm
How about this?

http://www.newcircuits.com/circuit.php?id=aum002 (http://www.newcircuits.com/circuit.php?id=aum002)

It is missing a bypass cap from pin 3 to ground, I'd guess about 0.1uF will work.

http://www.newcircuits.com/chimage.php?s=cir_aum002.gif&w=600 (http://www.newcircuits.com/chimage.php?s=cir_aum002.gif&w=600)
Edit: dunno why that would not load as an image, try it as a link. It is just the schematic from the link above.

The problem with an LM358 is that it isn't great at approaching Vcc. Runs out of steam about 1.5V below it.

Just about any reasonable rail to rail Op Amp will work. You aren't building a mixing console, so noise isn't really an issue.

You are only interested in the waveform envelope, correct? The LM358 inputs can go down to ground, as can the output. So wire it up with ground as the reference, inverting amplifier. The Op Amp will only amplify the negative going part of the mic output, only going positive for them. Up to 3.5V on 5V power. Send that through an RC smoothing circuit, it'll end up being a max of about 1.5 to 2V. Now use the internal 1.1V analog reference. Adjust the microphone preamp accordingly.

Oh, yeah, lots of bypass caps on Vcc. Maybe even an RC network on Vcc to the Op Amp Vcc.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 06, 2013, 11:23 pm
I've not breadboarded this:

(http://www.polyphoto.com/tutorials/ElectronicsGeneral/LM358ElectretEnvelope.jpg)

10mVpeak 1kHz sine wave, offset 1.5V to simulate a rather loud sound in an electret mic.

The LTSpice file:

http://www.polyphoto.com/tutorials/ElectronicsGeneral/LM358ElectretEnvelope.asc (http://www.polyphoto.com/tutorials/ElectronicsGeneral/LM358ElectretEnvelope.asc)

You'll also need this LM358 file:

http://www.polyphoto.com/tutorials/ElectronicsGeneral/LM358.MOD (http://www.polyphoto.com/tutorials/ElectronicsGeneral/LM358.MOD)
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 09, 2013, 05:24 am
OK, thanks. Well before I change anything I decided to measure the performance of the existing setup (see original post).

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191774a.png)

Yellow is on pin 3 of the op-amp (+ input) and blue is on pin 1 (output).

Measuring with the cursor (from 0V) I get:



So I make that a gain of 68, not quite what the circuit should do. Have I hit some limit of the performance of the op-amp?

Also, is that about what you expect out of a electret mike? 24 mV isn't much, right?

This is with the mike draped over a speaker playing music quite loudly.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 09, 2013, 05:47 am
24mV is not out of line with an electret mic right on a speaker. Microphones generally don't put out much.

There are input offset voltage and offset current, if that goes in the wrong direction with an Op Amp referenced to ground with a single supply... the end result can act as if there were a reverse bias on the microphone input. I think you are measuring 24mV at the rightmost peak of the mic, but what I see is a lot of high frequency noise. The average of the noise looks more like 17 or 18mV, making 1.64V a lot closer to 100 times the input.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 09, 2013, 06:25 am
With your circuit I got this:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191774b.png)

Based on the readings on the screen, the gain is: 3.6 / 0.026 = 138

I had to ditch the 1 µF capacitor on the right (C2), that seemed to be sucking the output away.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 09, 2013, 06:29 am
It seemed to clip if the music was much louder, but I guess that since that isn't a rail-to-rail op-amp, you would expect that after about 3.6V.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 09, 2013, 06:30 am
Yeah, my example circuit is rather optimistic with an attempted gain of 1000, and a very artificial continuous 1kHz tone.

C2 is meant to be a smoothing capacitor, so you'd not see much except a little DC.

That should really be a two stage amplifier. Gain no more than 100 per stage.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 09, 2013, 06:37 am
Even in LTSpice, 10mV peak input only got us 2.8V peak.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: MarkT on Oct 09, 2013, 04:02 pm


Yellow is on pin 3 of the op-amp (+ input) and blue is on pin 1 (output).



But we are using an inverting circuit where the opamp inputs are virtual ground, right?
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 09, 2013, 09:38 pm
Not in the original circuit, I don't think (first post).
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 10, 2013, 09:33 pm
Nick, both your ckt and the one in reply #11, need a pullup R connected to the "+" input terminal (of the same value as the pulldown), in order to get the op Amps into the linear operating region. What you are seeing in your waveforms is clipping due to the opAmps being DC-biased at ground potential.

Also, the ckt of #11 is pretty much ALL wrong.

1. when adding the pullup on R3, use 10K to 100K for both.

2. a gain of 1000X is too high on an LM358. It's GBP [gain bandwidth product] is only 1 Mhz, so at gain=1000, the BW is only 1000 Hz. The gain probably shouldn't be set to over 100X or so, for audio work.

3. the LPF [low pass filter] on the output kills the signal, as you observed. It has a low-pass F3db = 1/(2*pi*R5*C2) = just 16 Hz.

Low-pass on the very output is an extremely poor way to remove the noise in the system - ie, after the noise has been "amplified" by the ckt. Your waveforms show how much noise there is on the electret signal.

4. both in your ckt and #11, and 99% of the time with non-inverting opAmp ckts, you want a low-pass filter cap across the "feedback" R. Especially at higher gain, this both filters noise and prevents the ckt from oscillating. Calculate the cap using the same formula as above,

F3db = 1/(2 * pi * R2 * C) --> C = 1/(2 * pi * R2 * F3db)

For audio, C = 1/(2 * pi * 100K * 5000Hz) = 318 pF, so something between 270 and 470 pF should work. Try items 1 and 4, and you should have a much nicer waveform output.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 10, 2013, 10:00 pm
Quote

4. both in your ckt and #11, and 99% of the time with non-inverting opAmp ckts, you want a low-pass filter cap across the "feedback" R.


R2 in my circuit, right?

BTW, in the screenshots I took the input (yellow) shows lots of noise, but it doesn't seem to be amplified. So am I correct in thinking this is a measuring artifact? The noise isn't really there? I was watching one of Dave Jones' videos where he showed that what looked like noise from a power supply wasn't really what it seemed.

http://www.youtube.com/watch?v=BFLZm4LbzQU
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 10, 2013, 10:39 pm
Yeah, your R2, the cap goes in parallel with it, not to gnd or anything else. You should always use a cap there whenever you have a gain of about 10X or more. There should also be one across R2 in the inverting ckt of reply #11 - along with all the other fixes.

You're blowing up a small signal, so you'll always see a lot of noise on it, unless you take significant scope grounding precautions as talked about in the past. Also, try just connecting your probe gnd lead to the test pin of the probe, and see what the noise looks like at the same o'scope gain setting - it'll probably look about the same as when on the ckt [maybe]. You need to know what your test equipment is actually doing FIRST, as a yardstick for comparison.

A lot of the noise is also high-frequency, so the limited BW of your amp due to the high gain setting will filter it. Remember, BW = GBP/Gain.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 10, 2013, 11:05 pm
With your suggested changes to my original circuit I now get:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191774c.png)
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 11, 2013, 06:50 am
It's looks like the noise on the output is slightly less, as might be expected from dropping F3db from 10Khz down to 5 Khz. However, it looks like you didn't add the pullup R at the "+" terminal to move the DC bias. I forgot, when you do that you'll need to put a 1 uF cap in "series" with R1, the R to gnd off pin 2, in order to make the "DC gain" = 1, when the AC-gain = 101. At that point, the output waveform should be more symmetrical.

BTW, did you measure the o'scope noise by tying the probe gnd to the probe tip?
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 11, 2013, 08:01 am
I did mention that point about not trying to get that much gain in one stage. And my circuit was not meant to amplify more than one half of the incoming signal. And I did also mention that the RC network on the output was meant to smooth it to something approaching an envelope detector.

The intention in wiring the Op Amp so it is biased at ground was to make it act as a precision rectifier, only passing one half of the waveform. It does what I meant it to do, it just needs a preamp before with less gain in it and the preamp.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 08:02 am
I added the resistor but not the cap you forgot to mention. :P
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 08:05 am
This is the reading with the probe tip grounded:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191774d.png)
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 11, 2013, 08:06 am

I added the resistor but not the cap you forgot to mention. :P


Ahem.

Quote
C2 is meant to be a smoothing capacitor, so you'd not see much except a little DC.


Not meant to be a final circuit, just to illustrate that the circuit acts as a precision rectifier. As mentioned, with that ridiculous gain the frequency response is horrible.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: polymorph on Oct 11, 2013, 08:06 am
With the probe tip grounded to what?
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 08:26 am
As instructed:

Quote

BTW, did you measure the o'scope noise by tying the probe gnd to the probe tip?


I looped the ground around to the tip.

Interestingly, if I connect the probe tip to the Ground on the scope, I get more noise, not less:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_191774e.png)
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 11, 2013, 08:33 am
Quote
This is the reading with the probe tip grounded:

You can see that that's basically the majority of noise you see superimposed on the electret signal. If you touch the probe gnd to the tip, you have a tiny pickup loop. If you touch the tip to the scope gnd, it's a bigger loop.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 11, 2013, 08:42 am
Quote
Not meant to be a final circuit, just to illustrate that the circuit acts as a precision rectifier. As mentioned, with that ridiculous gain the frequency response is horrible.

Yeah, that's basically how the ckt works, but I'm not sure it's such a good idea to DC-bias an opAmp right to gnd, there might be some nasty nonlinearities as the feedback loop goes in and out of operation. Plus you might end up with serious clipping of the tiny signal being amplified. I should think even a rectifier app should have the DC-bias set close to gnd, but slightly above, so the opAmp stays in operation.

I was trying to get Nick to understand a little better about how to get a single-ended [non-bipolar] amp ckt to work as a general amplifier.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 08:44 am
Yes, interesting. If I ground the tip and ground the ground wire, the noise drops slightly to around 5.6 mV.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 08:44 am

I was trying to get Nick to understand a little better about how to get a single-ended [non-bipolar] amp ckt to work as a general amplifier.


I'll add the extra cap tomorrow, I'm always keen to learn new things.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 08:47 am
Here's a slightly odd thing. I had the probe on 10x, and if I change it to 1x, the scope display doesn't change, but if I adjust the units, it now reads 600 µV as you expect as it is dividing the previous result by 10.

So whether you have 6 mV or 600 µV of noise depends on what setting you use. It's almost as if the noise is internal to the scope input circuitry.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: dc42 on Oct 11, 2013, 09:48 am

Nick, both your ckt and the one in reply #11, need a pullup R connected to the "+" input terminal (of the same value as the pulldown), in order to get the op Amps into the linear operating region.


The LM358 is not rail-to-rail output, the output range goes from close to 0V to around 3.5V when operating from a 5V supply. So I would not make the pullup resistor on the +input the same value as the pulldown, I would make it about twice as high, as I suggested in reply #5, so as to bias the input and output at about +1.8V. If there is noise on the power supply (e.g. because you are powering it from USB or a switched-mode power supply), then instead create a 2:1 voltage divider across the 5V supply to provide 1.8V, decouple it with a capacitor to ground, and take a 100K resistor from there to the +input.

Also, you must add the capacitor in series with R1, otherwise the amplifier will also be amplifying the DC bias and the output will be stuck at about 3.5V.
Title: Re: How to make a pre-amp for a electret? microphone
Post by: oric_dan on Oct 11, 2013, 10:09 am
Yeah, dc42 has a good point about how to bias the "+" input pin. Also, once you bias it into the linear [ie, symmetic] region of operation, and away from clipping the negative swings as at present, you may need to cut back on the AC-gain to keep it from clipping high input signals.

You can also play some more with the value of the cap across the feedback-R to see its effects - eg, check with larger values.

Quote
I'll add the extra cap tomorrow, I'm always keen to learn new things.

You can learn several things at once, of course. One, how to get it working for general audio amplification to produce nice output with symmetrical swings, and once that's in hand, then how to fiddle the ckt to do rectification, envelope detection, etc. [good night now].
Title: Re: How to make a pre-amp for a electret? microphone
Post by: nickgammon on Oct 11, 2013, 10:28 am

The LM358 is not rail-to-rail output, the output range goes from close to 0V to around 3.5V when operating from a 5V supply.


Well, I got that bit right:


It seemed to clip if the music was much louder, but I guess that since that isn't a rail-to-rail op-amp, you would expect that after about 3.6V.