mic -> op-amp -> ADC connection: How to do it properly? - Page 1
Forum section: electronics / beginners

author: AlStorm Prime
author_rank: Contributor
timestamp: October 19, 2015, 08:23:04 pm
content: Good time of the day,Brief intro:I am exploring theSTM32F303VCperipherals on theSTM32F3-Discoveryboard 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-9754Ppdf) 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 fromhere):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 Recorderdatasheet)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!

author: Simon
author_rank: Unknown
timestamp: October 19, 2015, 08:36:47 pm
content: 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.

author: Andy Watson
author_rank: Super Contributor
timestamp: October 19, 2015, 11:43:12 pm
content: Quote from: AlStorm Prime on October 19, 2015, 08:23:04 pmGood 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.

author: AlStorm Prime
author_rank: Contributor
timestamp: October 20, 2015, 01:09:02 am
content: Quote from: Simon on October 19, 2015, 08:36:47 pmThis 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...?

author: AlStorm Prime
author_rank: Contributor
timestamp: October 20, 2015, 01:13:30 am
content: 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.

author: rs20
author_rank: Super Contributor
timestamp: October 20, 2015, 01:16:35 am
content: Quote from: AlStorm Prime on October 20, 2015, 01:09:02 amWrong. 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 increaseanddecrease as AC sound waves arrive.

author: Simon
author_rank: Unknown
timestamp: October 20, 2015, 06:01:20 am
content: think of it as-gain x input

author: AlStorm Prime
author_rank: Contributor
timestamp: October 21, 2015, 08:20:38 pm
content: Would like to thank you for the help! It allows me to locate my knowladge gaps precisly.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: October 22, 2015, 02:31:52 pm
content: .

author: AlStorm Prime
author_rank: Contributor
timestamp: November 01, 2015, 12:52:59 am
content: 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!

author: Andy Watson
author_rank: Super Contributor
timestamp: November 01, 2015, 01:22:05 am
content: 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.

author: Habropoda
author_rank: Regular Contributor
timestamp: November 01, 2015, 03:10:32 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: November 01, 2015, 11:20:06 am
content: 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.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: November 01, 2015, 04:42:13 pm
content: Take a look at how SparkFun does it.https://www.sparkfun.com/datasheets/BreakoutBoards/Amplified-Mic-Electret-v14.pdf

author: Zero999
author_rank: Super Contributor
timestamp: November 01, 2015, 05:39:58 pm
content: Quote from: alsetalokin4017 on November 01, 2015, 04:42:13 pmI 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.

author: AlStorm Prime
author_rank: Contributor
timestamp: November 01, 2015, 08:52:43 pm
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: November 02, 2015, 09:38:15 pm
content: 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.

author: rs20
author_rank: Super Contributor
timestamp: November 02, 2015, 09:55:31 pm
content: Quote from: Hero999 on November 02, 2015, 09:38:15 pmIn 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 theLinear motor drive thread. Sorry!

author: Delta
author_rank: Super Contributor
timestamp: November 02, 2015, 10:41:07 pm
content: Quote from: rs20 on November 02, 2015, 09:55:31 pmEh? I thought the use case was just to drive an MCU's ADC?

author: AlStorm Prime
author_rank: Contributor
timestamp: November 04, 2015, 04:47:11 pm
content: 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.

author: AlStorm Prime
author_rank: Contributor
timestamp: November 08, 2015, 10:52:22 pm
content: 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 onsoundcloud

author: Andy Watson
author_rank: Super Contributor
timestamp: November 08, 2015, 11:02:58 pm
content: 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.

author: AlStorm Prime
author_rank: Contributor
timestamp: November 09, 2015, 11:12:06 pm
content: Quote from: Andy Watson on November 08, 2015, 11:02:58 pmYou mean that I should not connect SD card to the same ground as mic/amp/adc?

author: rs20
author_rank: Super Contributor
timestamp: November 10, 2015, 02:09:52 am
content: Quote from: AlStorm Prime on November 09, 2015, 11:12:06 pmNot 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).

author: AlStorm Prime
author_rank: Contributor
timestamp: November 11, 2015, 01:57:36 pm
content: 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...

author: AlStorm Prime
author_rank: Contributor
timestamp: November 12, 2015, 12:19:28 am
content: Was searching the source of noise and found out that op-amp circuit doesn't give any of it.Connected speaker to the op-amp output, before ADC, and was surprised as it was clean and quiet.I can also exclude output part of the schematic (afetr DAC) because the same noise present when I play recorded audio from the PC.All noise I have appears after A/D conversion.So I have two things that doesn't looks right for me - noise after A/D conversion and range of the ADC results.As I mentioned earlier 90% of ADC results are from 120 to 148, instead of 0 to 255 for a 8 bit ADC resolution mode.For now I assume that Quantization Error can be a reason of noise in my case as only 10% of ADC resolution is used for audio quantization.My guess is that one stage amplification is not enough.Maybe I shoud add more stages or switch for the "compandor"/"mic conditioner" and force ADC results to swing in full range?

author: Dave
author_rank: Super Contributor
timestamp: November 12, 2015, 06:53:58 am
content: Why exactly is there a capacitor across the electret microphone?C3 also has no place there, it's just loading the output of the opamp, destabilizing it.R6 is redundant.

author: AlStorm Prime
author_rank: Contributor
timestamp: November 12, 2015, 08:13:32 am
content: Quote from: Dave on November 12, 2015, 06:53:58 amThe plan was like this:C1was taken from hereand was supposed to be "C3 is a power supply stabilization condenser"C3 was taken fromAVR335: Digital Sound Recorder datasheetpage 7, and was supposed to be a part of "R5 and C8 form a simple first order low-pass filter.."R6 is the way how I undestoodHero999s link on#215: Basics of crossover distortion | LM358 op amp exampleI am not sure if all of this can be combined and supposed to be in this way, but when i connect speaker to the outup of op-amp I don't hear the noise like I do after the uC.

author: Dave
author_rank: Super Contributor
timestamp: November 12, 2015, 07:47:56 pm
content: Just so we are clear, we are still talking about this schematic, right?C1 isn't a power supply stabilization capacitor, it's loading the microphone and severely degrading your signal. Remove it.The author from your link is using it as a low-pass filter, but it's almost two orders of magnitude smaller than yours.C3 isn't forming a low-pass filter, it's just loading the output of the opamp, forcing it into oscillation. You'd need a resistor in series to form a LPF. Remove it or add a resistor between the opamp's output and C3 (at least a couple of hundred ohms).MCP602 doesn't suffer from crossover distortion like the awful LM358. R6 is not needed.You might want to reduce the gain of your amplifier, because I have a feeling that after you remove C1, your signal is going to peak severely.

author: Kalvin
author_rank: Super Contributor
timestamp: November 12, 2015, 09:21:17 pm
content: Something simple might work too.Edit: Adding a capacitor in parallel with the resistor connected to the op amp's output will limit the high frequencies as needed (low-pass filtering).

author: AlStorm Prime
author_rank: Contributor
timestamp: November 13, 2015, 02:51:52 pm
content: Dave, I completely agree with your arguments and removed redundunt parts from the schematic.Kalvin, I am pretty sure this will work.I see two reasons why things went to complicated in my case.- it was done for a first time- and I chased the noise source in a "wrong direction', was thinking that something is wrong with the mic-op.amp part and started to add filters (in a wrong way btw)The last thing that I made is I've disconnected the mic-op.amp and second power supply completly.The only things thet are left are STM32F3-discovery power by USB from a host PC and SD card with SPI interface.Then I made the voltage divedire from discoverys 3V and GND supply, as I did for the virtual ground for the op.amp.And measured this with ADC. The result was next:And this sounds exactly as the noise I was chasing.I have plans to do more research on this and run few more tests (try external power supply instead of USB, and to to separate in time proces of reading ADC results and proces of dumping it on SD card).All I have to add for now is the part of internal schematic of STM32F3 discovery board where Vref is shownHave strong intention to find the reason of such behavour of my ADC and will be greatfull for any ideas about this.Have a nice friday guys!

author: Dave
author_rank: Super Contributor
timestamp: November 13, 2015, 11:03:07 pm
content: The noise might be caused by the ADC itself. The resistive divider is providing a high-impedance input to the ADC, but the ADC requires a low-impedance input, because it needs the current spikes to charge the sampling capacitor.Try doing an FFT on that noisy signal, let's if the noise somehow corresponds to the sampling frequency of the ADC.Second thing you should try: Add an opamp as a buffer and put a RC LPF on the output composed of 100R resistor and 1nF cap. Try measuring the same thing again.

author: AlStorm Prime
author_rank: Contributor
timestamp: November 14, 2015, 02:30:48 am
content: original postI had a 'bug' in the testing software wich has distorted the results of the few last testings. So I've deleted this post to not mislead.

author: Kalvin
author_rank: Super Contributor
timestamp: November 14, 2015, 01:29:13 pm
content: Quote from: AlStorm Prime on November 13, 2015, 02:51:52 pmDid you connect the voltage divider to the filtered supply voltage or to the unfiltered and noisy supply voltage coming directly from the USB.

author: AlStorm Prime
author_rank: Contributor
timestamp: November 18, 2015, 01:18:09 am
content: Kalvin, I was using 3.3V supply from the Discovery board, wich has a 'low-dropout regulator' on board, to drive all parts of schematic (plus a bunch of thing onboard of the Discovery), including the voltage divider for the op-amp. So it was defenetly not a 'filtered' voltage supply.Actually, this was a reason of my troubles. Noise from the power supply line. It did take a long way for me to realise and fix this.I want to thank everyone for the help, ideas and explanations. It was informative, useful and interesting.And I still have a lot stuff to work on, play and test. have found a lot of 'supportive' audio ICs from different manufacturers. Like microphone conditioners, MEMS mics, codecs, filters, reference grounds and so on. Not counting the world of power supply part of the schematics.For now I am looking on the SSM2167(pdf), but what confuses me is it's maximum gain, wich is 40dB (online converter says it's x100 for the Voltage).I guess this will be not enough for me, as now I use two stage amplification ~ x34 each.