Author Topic: mic -> op-amp -> ADC connection: How to do it properly?  (Read 22811 times)

0 Members and 1 Guest are viewing this topic.

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
mic -> op-amp -> ADC connection: How to do it properly?
« on: October 19, 2015, 08:23:04 pm »
Good time of the day,

Brief intro:
I am exploring the STM32F303VC peripherals on the STM32F3-Discovery board and now I would like to utilize the ADC and DAC modules.
The idea is to capture sound (voice) with the microphone, digitize it via ADC, store result inside the MCU and play it back via DAC.

As a mic I've chose Electret Condenser Microphone (BCM-9754P pdf) as it is easy accessible in my area.
As a op-amplifier I've chose TI NE5532P (pdf). Because of its affordability and low-noise.
I plan to use 5V supply from a board for op-amp and 3.3V (in fact ~2.95V) supply for all other stuff.

And the question is - how to connect/wire this things together?

I've found alot schematics on the internet but I lack expirience and knowledge to understand them well. This is where I ask you for help.

First variant looks like this (taken from here):


While the purpose of all components is desribed in the suorce I don't understand why or for what purpose those voltage dividers (R1R2 and R6R7) are used /needed. How they infuence o nthe result and can I remove them?

Secend variant that I consider looks this way: (taken from AVR335: Digital Sound Recorder datasheet)



Here the voltage divider R2R3 is used  on non inverting input (why, what if not?)
Plus the inverting amplifier connection is used - why this is acceptable? Shouldn't this influence the ADC results?

Will be very greatfull for any help!
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #1 on: October 19, 2015, 08:36:47 pm »
Look at the power supply of the op amps, it is "single" rail, ie there is only a positive supply, but your audio is both positive and negative around ground. So that the op amp can have both positive and negative swings an artificial ground point is created by the potential dividers usually at 1/2 Vcc so that there is a virtual ground to reference to or rather a vitual negative rail.
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #2 on: October 19, 2015, 11:43:12 pm »
As a op-amplifier I've chose TI NE5532P (pdf). Because of its affordability and low-noise.
I plan to use 5V supply from a board for op-amp and 3.3V (in fact ~2.95V) supply for all other stuff.
Good choice for low-noise, but, the datasheet suggests that it won't get out of bed for anything less than 10V supply voltage (top of page three). If you do manage to wake it up, it probably will not perform well. Also, the input common-mode range and the output will "typically" only swing to within 2 volts of the power supplies - with a 5V supply that will leave you an operating window of 1V.

« Last Edit: October 19, 2015, 11:51:21 pm by Andy Watson »
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #3 on: October 20, 2015, 01:09:02 am »
Look at the power supply of the op amps, it is "single" rail, ie there is only a positive supply, but your audio is both positive and negative around ground. So that the op amp can have both positive and negative swings an artificial ground point is created by the potential dividers usually at 1/2 Vcc so that there is a virtual ground to reference to or rather a vitual negative rail.

This is how I see it with case#2 (inverting configuration) from AVR example where virtual ground and mic output are on different op-amp inputs:
Relatively to the virtual GND op-amp is able to provide both positive and negative swings, wich are at the same time positive relatively to the 'real' GND.
And as ADC, in this example, operates on the same voltage and use the same Vcc and GND as op-amp. From ADCs point of view those swings lie within his operation range and are also positive. Is this correct?

Then I have another question - as this is 'inverting configuration' the silence (0V output from the mic) will be inverted by op-amp to Vcc (or to a top value avaliable for cpecific op-amp ). ADC will also deal with this as with a Vcc (or close) value. How this should become again 'silence' after playback? What I am missing...?

 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #4 on: October 20, 2015, 01:13:30 am »
Andy Watson, you are right. In this case I'll consider what is preferable in my case, to increase power supply of op-amp or choose another model. Thank you.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #5 on: October 20, 2015, 01:16:35 am »
Then I have another question - as this is 'inverting configuration' the silence (0V output from the mic) will be inverted by op-amp to Vcc...

Wrong. Assuming the supply voltage is 5V, the voltage at pin 3 of U1A will be 2.5V because of the divider. According to virtual earth principle, the voltage at pin 2 will be 2.5V as well. In the case where there is silence, there will be no current flowing through C1, since the input signal is a flat 0V. This means there's no current flowing through R9 either, and no current flowing through R1. So the output from the op-amp is 2.5V (not Vcc as you've asserted), which is exactly perfect because the value should be dead in the middle of the 0 to Vcc range so that it's free to increase and decrease as AC sound waves arrive.
 

Offline Simon

  • Global Moderator
  • *****
  • Posts: 17816
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #6 on: October 20, 2015, 06:01:20 am »
think of it as -gain x input
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #7 on: October 21, 2015, 08:20:38 pm »
Would like to thank you for the help! It allows me to locate my knowladge gaps precisly.
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #8 on: October 22, 2015, 02:31:52 pm »
.
« Last Edit: October 22, 2015, 02:34:45 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #9 on: November 01, 2015, 12:52:59 am »
Good evening guys,

I've ended up with this circuit :



And have difficulties with ADC readings. The 8bit ADC results in "silent" situation gives value of ~110.
And when I rub the microphone/ talk it swings from ~96 to ~124.
I've tryed different vaulues for R5 from 15k? <-> 330k? to adjust gain but the result is almost the same.
I was expecting swings from 0 to 256 (in 8 bit ADC mode), what I could do wrong here?
C3 is electrolytic capacitor, all other are ceramic, op-amp is LM324(pdf)

Will be grateful for your advices!
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #10 on: November 01, 2015, 01:22:05 am »
The gain of the amplifier will be (approx) R5 / (R2 + Xc2). The value of C2 gives high value of impedance (Xc2) at audio frequencies. What is the lowest frequency of interest? Use this value to calculate the value of C2 to realise an impedance equal to R2.

Edit: As it stands, C2=4700pF, will give the amplifier a low-frequency roll-off starting at 34kHz. Assuming you want to cover the audio frequency range, C2 needs to be approximately 1000 times larger.
« Last Edit: November 01, 2015, 01:26:09 am by Andy Watson »
 

Offline Habropoda

  • Regular Contributor
  • *
  • Posts: 67
  • Country: us
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #11 on: November 01, 2015, 03:10:32 am »
Not an expert, but it looks like your op amp will also start rolling of frequencies higher than about 1-2khz at that gain.  You would need to cascade a couple of those with lower gain on each to get decent bandwidth.

David's EEVBLOG #572 addresses this issue.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #12 on: November 01, 2015, 11:20:06 am »
Why on earth did you decide to use the LM324? It's possibly the worst choice for audio. It suffers from horrible crossover distortion and is far too slow to produce treble accurately.

The NE5532 and TL072  are much better! I notice you've gone for an 8V supply so why not use the NE5532 or TL072 which should work off 8V (I know it's not specified to but I know it will). If in doubt use the NE5534 which similar and is specified down to 6V.

 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
The easiest person to fool is yourself. -- Richard Feynman
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #14 on: November 01, 2015, 05:39:58 pm »
Take a look at how SparkFun does it.
https://www.sparkfun.com/datasheets/BreakoutBoards/Amplified-Mic-Electret-v14.pdf
I wonder why they went for the OPA344. The gain will drop below 100 at just 10kHz and it's more noisy than other amplifiers around. The OPA345 variant would've been a better choice. The gain doesn't drop below 100 until 30kHz so will perform well at the high end of the audio band.

Personally I would've chosen the TLV2460 which is lower noise.

As far as the original poster is concerned. He hasn't said what gain he requires. The schematics he's posted have a gains ranging from 10 to 330.

Here's a circuit which should be reasonably low noise and have a gain of  331.



Notes:
The non-polarised capacitors should be anything but ceramic which is microphonic and can cause problems in audio circuits.

The polarised capacitors can be aluminium.

U1 = NE5534 or if that's not good enough, the OP37.

As mentioned above R3 & R4 bias the op-amp at half the supply voltage.

C3 is added to improve the supply rejection.

R5 sets the input impedance to 27k at audio frequencies and roughly balance the DC resistance seen at both of the op-amp's inputs.

If this is being run of a battery. C3 and R5 may be unnecessary. If you want to remove them, by all means do but increase R3 and R4 to 68k to keep the DC resistance seen at the op-amp's inputs matched.

R6 and C5 will filter out RF noise and terminate the cable with 100R, at RF which should be close to the characteristic impedance of the cable.
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #15 on: November 01, 2015, 08:52:43 pm »
I appreciate all recommendations and suggestions.

Andy Watson, haven't realised that I need to take capacitive reactance into account.
My goal is, at least, pick up the speech and ideally full audio frequency range. Assume that, in this case, lowest frequency of interest should be 300Hz.
I swithed C2 for a 22µF. This means capacitive reactance to be close to 24Ohms at 300Hz. So impedance of my C2(22µF) is much less then the 1kOhms R2 resistor. Is it important to keep their impedance the same and why? Thank you.

Habropoda, got it. I reduced the gain to x16 by replacing R5 to 15.7kOhms resistor and will step upward.

Hero999, I trusted to "Microphone and Speaker Circuit Diagram" from AVR and they used LM324 in their circuit. The main idea was to start with a working setup as I was unfamiliar with ADC,op-amps, mics and audio processing in general when was starting this project. I was assuming that I am going to start sampling rate from 8kHz, will have 9V swing and was thinking that I'll be fine with 9V/125us=0.072V/us slew rate. Also had plans to try different op-amps and play with audio quality after get the basic variant working.
Concerning the requird gain and voltage supply - I don't know wich gain I need. Don't know how to calculate it. Was planning to choose it based on the ADC readings. I used 8V supply only beacause it was more stable then outup from ac/dc adpter I have. So it's not a limit. I am going to obtain linear voltage regulators for +12(+9/+3) and -12(-9/-3) respectivly to power op-amp rails and mic.

alsetalokin4017, thank you for the link.

I will try use different values for resistors and capacitors based on circuits you have offered. But for now, from my point of veiw, the mane difference seems that I am using different voltage suply for mic/op-amp and ADC when all offered circuits use one power supply. Maybe I'll simplify my case and will obtain rail-to-rail op-amp and make this hole thing to work from a single 3V supply (stm32F3-discovery board) to get rid of secend  voltage divider right before ADC input.
« Last Edit: November 01, 2015, 08:54:54 pm by AlStorm Prime »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19522
  • Country: gb
  • 0999
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #16 on: November 02, 2015, 09:38:15 pm »
It depends on what you're doing.

It isn't just the poor slew rate and bandwidth which makes the LM324 unsuitable for audio but also the crossover distortion, which creates glitches in the waveform when the output changes from sinking to sourcing current and vice versa.

See the video linked below which discusses the LM358 which is the same as the LM324 but contains two, rather than four op-amps.


As mentioned in the video, adding a resistor between the output and 0V will ensure it operates in class A so will remove the crossover distortion.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #17 on: November 02, 2015, 09:55:31 pm »
As mentioned in the video, adding a resistor between the output and 0V will ensure it operates in class A so will remove the crossover distortion.

In the OP's use case, that'd be a (physically) very large and very very hot resistor...

Edit: Whoops, I should not visit forums first thing in the morning. My brain thought I was reading the Linear motor drive thread. Sorry!
« Last Edit: November 02, 2015, 11:04:08 pm by rs20 »
 

Offline Delta

  • Super Contributor
  • ***
  • Posts: 1221
  • Country: gb
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #18 on: November 02, 2015, 10:41:07 pm »
As mentioned in the video, adding a resistor between the output and 0V will ensure it operates in class A so will remove the crossover distortion.

In the OP's use case, that'd be a (physically) very large and very very hot resistor...

Eh? I thought the use case was just to drive an MCU's ADC?
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #19 on: November 04, 2015, 04:47:11 pm »
Good evening,
Would like to thank you for the support.  :-+
I moved a few steps toward the goal of this project.
The current circuit is able to REC / PLAY for a 3 seconds duration as well as continuously broadcast from MIC to speaker.
Now I'll focus on software - SD card, FAT file system and differential pulse-code modulation encoding.
Perfecting the hardware part for a sound quality is going to be final part.
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #20 on: November 08, 2015, 10:52:22 pm »
Good evening!
Today I faced with the following problem - usage SD card, that is powered from the same source as the op-amp, cause strong distortion of recorded sound. My guess is - increased current drain, while in write cycle, results in voltage surges. Adding 1000uF capacitor (C4 on the schematic) close to op-amp +rail softens the distortion, but doesn't remove it entirly.

Will be grateful for any ideas on how to wire this properly or improve the project!

I'll attache the actual schematic, general photo and the view of soundwave.
Also, if anyone wants to listen this, the link on soundcloud
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #21 on: November 08, 2015, 11:02:58 pm »
R1 provides direct coupling between the +ve supply and the input to your amplifier. I would split R1 and add some (may be a lot of) decoupling capacitance at the split.

Also, make sure that the ground path for the audio input is solid from mic to amplifier to input of the ADC and that it does not serve anything else.
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #22 on: November 09, 2015, 11:12:06 pm »
R1 provides direct coupling between the +ve supply and the input to your amplifier. I would split R1 and add some (may be a lot of) decoupling capacitance at the split.

Also, make sure that the ground path for the audio input is solid from mic to amplifier to input of the ADC and that it does not serve anything else.

You mean that I should not connect SD card to the same ground as mic/amp/adc?
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #23 on: November 10, 2015, 02:09:52 am »
R1 provides direct coupling between the +ve supply and the input to your amplifier. I would split R1 and add some (may be a lot of) decoupling capacitance at the split.

Also, make sure that the ground path for the audio input is solid from mic to amplifier to input of the ADC and that it does not serve anything else.

You mean that I should not connect SD card to the same ground as mic/amp/adc?

Not quite. I think he means they should be connected, but at precisely one point. I.e., there should be a dedicated ground trace for the opamp, adc and mic (and associated resistors and decoupling) that is connected at only one single point to the rest of the grounds of the circuit.

Fwiw, I'm not sure that's really necessary until you see interference-related issues (haven't been following the thread).
 

Offline AlStorm PrimeTopic starter

  • Contributor
  • Posts: 19
  • Country: ua
Re: mic -> op-amp -> ADC connection: How to do it properly?
« Reply #24 on: November 11, 2015, 01:57:36 pm »
I had interference-related issues. Turned out that they where caused by SPIs SCL/MISO/MOSI lines. As they where to close to the analog part of the schematic.

Also, I found out that more then 90% of ADC(8bit mode) results lie between 120 <> 148 and audicity shows that recorded sound wave swings from 0v to 0.2V. Does this means that op-amp gain is to small in my case? I was expecting swings from top to bottom...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf