Noisy ADC + DC bias introduced when I pluck a string

Started by gabrielgcma, March 15, 2025, 08:10:27 PM

Previous topic - Next topic

gabrielgcma

I'm trying to design my own loop pedal, something like a Ditto Looper clone. Here's what I'm using:

- MCU: STM32F411 on a BlackPill v3.1 dev board
- ADC: PCM1808 24bits 96kHz (I'm going for 24bits 44.1kHz though) wrapped in a module
- DAC: PCM5102
- TL072CP to pre-amplify the signal

ADC specs:








Currently, I'm just trying to make sure the signal is read correctly. This is the acquisition stage:








I have the ADC setup as the I2S master and STM32 as the slave. The STM32 is outputting a PLL clock of 25MHz to the ADC, which in turn outputs the I2S clock and the WS clock. The I2S and clock are set up as follows:











This is the I2S output of an E note on the 12th fret, with a moderate force as I would do if I was playing naturally. In the 2s of recording, I went from idle, picking the note and letting ring:







As you can see, I think I have too much noise on my ADC, and I don't know what are those "ghost" values - those ones that seem to be a duplicate of the original one but with an offset. Besides, there seems to be some DC bias happening right when I pluck the string, making the signal more negative and climbing up with time, causing clipping of the ADC:



Is my gain of 6.1 too high for this ADC? Am I doing something else wrong?




PRR

Welcome!

Quote from: gabrielgcma on March 15, 2025, 08:10:27 PMI don't know what are those "ghost" values - ....
Is my gain of 6.1 too high for this ADC?

Could be. Rather than think(*) real hard, why not just try lower gain and see what happens? Lift one end of C7 or R20 to get gain of 1. Also the VOL knob on the guitar turned at least halfway down.
(*) We have headcolds. We have several drugs and also the Peach Brandy open. I can barely compute "gain of 1". But I think if it is overloading, I might hear a difference 6 or 1.

  • SUPPORTER

ElectricDruid

Welcome! Nice project!

+1 what PRR said.

Electric guitars vary *a lot*, but 1Vpp signal output is a reasonable ballpark figure for a quick guesstimate. IF you've got x6 gain on that, you'll get a signal that's going to be too loud for your 5V full scale reading.
Definitely try less gain, and the simplest way is to just turn the guitar down and see if that fixes it.

I think there might be something funny going on with the input stage too. The ADC_VREF works out at 2.22V (please check...) so there's some offset there from the ADC's midpoint.
Also that 2.2V bias voltage is used for the input op-amp stage. How close can that op-amp drive to ground? If it clips (say) two diode drops from ground, at 1.2V, there's only 1V of headroom below the bias point. I think you might be better with a 5V single supply rail-to-rail op-amp. They were designed for jobs like this.

The offset can be minimised in the hardware, but you will also need to add a highpass filter in the code to remove the remaining offset. It's just standard practice for DSP, basically. You *won't* get a perfect zero reading from the ADC with no signal, whatever you do, and you don't really need to.
Quote from: gabrielgcma on March 15, 2025, 08:10:27 PM

gabrielgcma

#3
Quote from: PRR on March 16, 2025, 01:04:44 AMWelcome!

Quote from: gabrielgcma on March 15, 2025, 08:10:27 PMI don't know what are those "ghost" values - ....
Is my gain of 6.1 too high for this ADC?

Could be. Rather than think(*) real hard, why not just try lower gain and see what happens? Lift one end of C7 or R20 to get gain of 1. Also the VOL knob on the guitar turned at least halfway down.
(*) We have headcolds. We have several drugs and also the Peach Brandy open. I can barely compute "gain of 1". But I think if it is overloading, I might hear a difference 6 or 1.



Thanks!

I'll lower the gain and see what happens. I thought I needed to amplify the guitar in order to get a better ADC reading, because it has a window of 3Vpp. So I don't need to worry about it? I was afraid I was going to lose tone and brightness.

gabrielgcma

#4
Quote from: ElectricDruid on March 16, 2025, 06:39:54 AMWelcome! Nice project!

+1 what PRR said.

Electric guitars vary *a lot*, but 1Vpp signal output is a reasonable ballpark figure for a quick guesstimate. IF you've got x6 gain on that, you'll get a signal that's going to be too loud for your 5V full scale reading.
Definitely try less gain, and the simplest way is to just turn the guitar down and see if that fixes it.

I think there might be something funny going on with the input stage too. The ADC_VREF works out at 2.22V (please check...) so there's some offset there from the ADC's midpoint.
Also that 2.2V bias voltage is used for the input op-amp stage. How close can that op-amp drive to ground? If it clips (say) two diode drops from ground, at 1.2V, there's only 1V of headroom below the bias point. I think you might be better with a 5V single supply rail-to-rail op-amp. They were designed for jobs like this.

The offset can be minimised in the hardware, but you will also need to add a highpass filter in the code to remove the remaining offset. It's just standard practice for DSP, basically. You *won't* get a perfect zero reading from the ADC with no signal, whatever you do, and you don't really need to.
Quote from: gabrielgcma on March 15, 2025, 08:10:27 PM


Thanks!

QuoteAlso that 2.2V bias voltage is used for the input op-amp stage. How close can that op-amp drive to ground? If it clips (say) two diode drops from ground, at 1.2V, there's only 1V of headroom below the bias point. I think you might be better with a 5V single supply rail-to-rail op-amp. They were designed for jobs like this.

I don't think the TL072 is affecting the signal, but here's a sample of the opamp output at ADC_R_IN (sorry the sloppy quality) with gain of 6:



It seems to be amplifying the whole signal just fine, even when I strum the guitar really hard, no clipping.

Anyways, I lowered the gain to 2 (25k/25k + 1 because of the noninverting opamp), and I got better results!

Idle:



E on 12th fret with full volume, transient:



E on 12th fret with full volume, ringing:



E on 12th fret with half volume, transient:



E on 12th fret with half volume, ringing:



I think I got more dense and better quality results with half volume, and no clipping at the transient. So... unity gain is the way? I'd still liket o get rid of that ghost signal at the top, that would be done with the high pass filter you mentioned, right?

And I'm really curious as to why even though the signal is within the ADC range, when I pluck the guitar with full volume, it somehow gets clipped. As I said, my scope shows the opamp output signal is never clipped like the ADC output says.

gabrielgcma

I don't know if this is important, but here's more detail about my power supplies:

- 12V from a power supply connected to a line filter that's connected to an outlet.
- 5V and 3.3V from the BlackPill dev board that's connected to the USB on my computer.

I'm not connecting the ground from the BlackPill breadboard to the ground of the signal breadboard.

FiveseveN

Quote from: gabrielgcma on March 16, 2025, 02:01:04 PMI'd still liket o get rid of that ghost signal at the top, that would be done with the high pass filter you mentioned, right?
By the looks of it I'd suspect a numerical problem, with either the reading or display, maybe an overflow?


Have you actually listened to this through the DAC? Might be the quickest way to see if the ghost values are actually there or just an artifact.
Quote from: R.G. on July 31, 2018, 10:34:30 PMDoes the circuit sound better when oriented to magnetic north under a pyramid?

ElectricDruid

Quote from: gabrielgcma on March 16, 2025, 02:01:04 PMI don't think the TL072 is affecting the signal, but here's a sample of the opamp output at ADC_R_IN (sorry the sloppy quality) with gain of 6:



It seems to be amplifying the whole signal just fine, even when I strum the guitar really hard, no clipping.
I don't agree. The bottom of the waveform looks distorted to me. You could try feeding it a test signal to see for sure. Download a free signal generator for your phone and feed in a sine wave or a triangle and see how that looks.

The TL072 *cannot* drive the signal close to ground, so with x6 gain it *will* clip when biased at 2.2V unless the signal is a very low level.

QuoteAnyways, I lowered the gain to 2 (25k/25k + 1 because of the noninverting opamp), and I got better results!
...which is what you'd expect if the op-amp was clipping.

I think your op-amp choice is limiting your headroom significantly.

gabrielgcma

#8
Quote from: FiveseveN on March 16, 2025, 03:06:48 PM
Quote from: gabrielgcma on March 16, 2025, 02:01:04 PMI'd still liket o get rid of that ghost signal at the top, that would be done with the high pass filter you mentioned, right?
By the looks of it I'd suspect a numerical problem, with either the reading or display, maybe an overflow?


Have you actually listened to this through the DAC? Might be the quickest way to see if the ghost values are actually there or just an artifact.

Quote from: ElectricDruid on March 16, 2025, 08:36:02 PM
Quote from: gabrielgcma on March 16, 2025, 02:01:04 PMI don't think the TL072 is affecting the signal, but here's a sample of the opamp output at ADC_R_IN (sorry the sloppy quality) with gain of 6:



It seems to be amplifying the whole signal just fine, even when I strum the guitar really hard, no clipping.
I don't agree. The bottom of the waveform looks distorted to me. You could try feeding it a test signal to see for sure. Download a free signal generator for your phone and feed in a sine wave or a triangle and see how that looks.

The TL072 *cannot* drive the signal close to ground, so with x6 gain it *will* clip when biased at 2.2V unless the signal is a very low level.

QuoteAnyways, I lowered the gain to 2 (25k/25k + 1 because of the noninverting opamp), and I got better results!
...which is what you'd expect if the op-amp was clipping.

I think your op-amp choice is limiting your headroom significantly.

Sorry @ElectricDruid, you're absolutely right, it looks distorted, I didn't even think enough. The DAC output confirms the clipping, I can hear it with volume 10 and a harder picking.

I recorded the output of the DAC and man... it sounds awful, even with x2 gain and half volume. A lot of noise (the logic analyzer was right) that randomly changes its volume every ~5s, and some popping that I think it's because of the clipping. If I slightly touch the jumpers on the breadboard, the thing goes mute (it's a clusterf* of jumpers intertwined).

This is a piece of it but lower your volume so you don't go deaf because of the pops:

https://drive.google.com/file/d/1H0NjlhEOKhNllTdv5tc3Q_EPL_AQLjTc/view?usp=sharing

@ElectricDruid do you have any part number recomendations of a good rail to rail single supply opamp? The thing is, even if I fix the clipping and headroom I would have no idea where to start debugging this loud background noise.

This is the most difficult project I've ever done for my Computer Engineering major :icon_cry: .

free electron

The VREF pin on the PCM1808 is not an input, but a passive pin to connect a decoupling capacitors filtering the internal bias supply.
https://www.ti.com/lit/ds/symlink/pcm1808.pdf
Page 3. last position in the pin table.
If the ADC_VREF nets are the same on both schematics, you have the input buffer bias fed into that pin.

I'd bias the input buffer normally at half the supply to get the max headroom and run it into the ADC via a DC blocking cap (they are installed on the module board), maybe add an RC lowpass and BAT54S clipping diodes to clamp the input voltage between 0 and 5V.
PCM1808 as most of the I2S audio ADCs, DAC and codecs has it's own internal input bias and reference voltage source.

Here is the PCM1808 eval board schematic directly from the TI showing basic operation:
https://www.ti.com/lit/ug/sbau349/sbau349.pdf?ts=1742282119942

gabrielgcma

#10
Quote from: free electron on March 18, 2025, 04:03:47 AMThe VREF pin on the PCM1808 is not an input, but a passive pin to connect a decoupling capacitors filtering the internal bias supply.
https://www.ti.com/lit/ds/symlink/pcm1808.pdf
Page 3. last position in the pin table.
If the ADC_VREF nets are the same on both schematics, you have the input buffer bias fed into that pin.

I'd bias the input buffer normally at half the supply to get the max headroom and run it into the ADC via a DC blocking cap (they are installed on the module board), maybe add an RC lowpass and BAT54S clipping diodes to clamp the input voltage between 0 and 5V.
PCM1808 as most of the I2S audio ADCs, DAC and codecs has it's own internal input bias and reference voltage source.

Here is the PCM1808 eval board schematic directly from the TI showing basic operation:
https://www.ti.com/lit/ug/sbau349/sbau349.pdf?ts=1742282119942


Oooh I feel stupid now, about that VREF pin. I just hope I didn't damage the ADC. Thanks!

I have a question regarding the bias you mentioned: so you'd be feeding a signal centered around 6V (half my supply). But why does the ADC module decouples the DC bias before feeding the signal, if the ADC datasheet states that it cannot read negative voltages? How would it translate the 6V-centered input into the 0 - 5V range?

free electron

The input pins are internally biased using a built in divider inside the PCM1808, which presumably uses the VREF pin for external decoupling capacitance.
It's a simplified guess, but i think the analog inputs look similar to this:



To test, disconnect the inputs from the ADC module, power it up and measure the DC voltage on the analog input pins (after the 10uF DC blocking caps), will probably be in range of half the Vcca = 5/2 = 2.5V.
With that ADC receives the AC signal centered at 2.5V - no negative voltages involved.

Not the best naming, though. VREF in the converter nomenclature usually means the voltage that corresponds to the full scale of the numeric value, ie. with Vref=3.3V, 3.3V on the input results in 1023 read with a 10bit ADC. Here, they've used it for the mid bias point of the input signal. Can be confusing.

The biasing would most likely work in your original circuit if not the ADC_VREF -> VREF connection. ADC module has the input 10uF capacitors blocking the buffer DC bias.

Pretty much all audio converters i've encountered have all this built in, usually including a low noise reference voltage source, sometimes optionally an external one.
Similarly, DSPs with build in ADC/DAC like the popular FV-1 use the same approach, input AC signal is DC blocked and the bias happens internally.
This is different from a generic ADC chip or and ADC inputs built into an MCU, where the reference voltage and the input bias often have to be supplied externally.

For lower noise i'd also use a separate 5V regulator for the ADC+DAC.

gabrielgcma

#12
Quote from: free electron on March 18, 2025, 08:06:55 AMThe input pins are internally biased using a built in divider inside the PCM1808, which presumably uses the VREF pin for external decoupling capacitance.
It's a simplified guess, but i think the analog inputs look similar to this:



To test, disconnect the inputs from the ADC module, power it up and measure the DC voltage on the analog input pins (after the 10uF DC blocking caps), will probably be in range of half the Vcca = 5/2 = 2.5V.
With that ADC receives the AC signal centered at 2.5V - no negative voltages involved.

Not the best naming, though. VREF in the converter nomenclature usually means the voltage that corresponds to the full scale of the numeric value, ie. with Vref=3.3V, 3.3V on the input results in 1023 read with a 10bit ADC. Here, they've used it for the mid bias point of the input signal. Can be confusing.

The biasing would most likely work in your original circuit if not the ADC_VREF -> VREF connection. ADC module has the input 10uF capacitors blocking the buffer DC bias.

Pretty much all audio converters i've encountered have all this built in, usually including a low noise reference voltage source, sometimes optionally an external one.
Similarly, DSPs with build in ADC/DAC like the popular FV-1 use the same approach, input AC signal is DC blocked and the bias happens internally.
This is different from a generic ADC chip or and ADC inputs built into an MCU, where the reference voltage and the input bias often have to be supplied externally.

For lower noise i'd also use a separate 5V regulator for the ADC+DAC.

Thanks for the detailed explanation.

Quote from: free electron on March 18, 2025, 04:03:47 AMI'd bias the input buffer normally at half the supply to get the max headroom and run it into the ADC via a DC blocking cap (they are installed on the module board), maybe add an RC lowpass and BAT54S clipping diodes to clamp the input voltage between 0 and 5V.

I tried biasing the TL072CP at half the supply, but didn't do much to the headroom. Still got mostly noise and the guitar still sounded distorted, even with half volume. I also tried 512Fs at 48kHz. I also tried using a separate 5V regulator. An important detail that I left out is that I was connecting the raw output of the DAC module straight into my audio interface, I don't know if that's correct.

If I understand correctly, the problem is that the TL072 can't interface well with the ADC when it's supplied with single voltage, because it can't drive close to ground. So if I power it with symmetrical voltage, could it perform well? I initially planned using a ICL7660S voltage inverter but I managed to fry the thing when testing (I think because of the rise rate of my power supply, which required a Schottky diode), so I resorted to single-supply.

Either way, I'll be getting some rail-to-rail opamps. These are the ones that I researched:

- OPA1678
- OPA1652
- OPA2376
- MCP6022
- TS912

Do you guys think any of these would do?

 

ElectricDruid

Quote from: gabrielgcma on March 19, 2025, 10:47:23 PMIf I understand correctly, the problem is that the TL072 can't interface well with the ADC when it's supplied with single voltage, because it can't drive close to ground. So if I power it with symmetrical voltage, could it perform well? I initially planned using a ICL7660S voltage inverter but I managed to fry the thing when testing (I think because of the rise rate of my power supply, which required a Schottky diode), so I resorted to single-supply.

As FreeElectron has pointed out, the ADC input has it's own internal bias, so you don't have to worry about providing the bias from outside. That frees you up. The TL072 can be run off 9V and can (should!) be biased to half of its supply voltage (so 4.5V). That gives plenty of headroom in the input buffer. The TL072 output is then coupled to the ADC input with a capacitor. If you're still getting distortion like that, the signal is probably too loud for the ADC (since it doesn't have quite as much headroom as the buffer, 5V versus roughly 7Vpp).

I initially said you should go with a single-supply rail-to-rail op-amp, but after FreeElectron correcting things, there's really no need.

You *do* need to read the DAC datasheet and find out what the "typical application" circuit looks like and what you're supposed to do with the output. The basic test for stuff like this is to read the ADC input and pass it straight to the DAC output and check that you get a clean signal straight through. That proves that the analog hardware is working correctly and the ADC/DAC are sampling correctly. Without the DAC output set up properly, you won't get what you expect.

free electron

Side note: these cheap modules from Aliexpress most likely do not have the genuine chips installed. Specs in the datasheet might have "suggestion how it should be, sort of" value when applied.

I'd approach it step by step to know where exactly the clipping+noise is occuring:
- use a sin generator instead of guitar for more consistent signal, any distortion will be much easier to spot
- disconnect the buffer from the ADC and run it through a 10uF DC blocking capacitor into an amp, even better a scope. Is everything fine? In my last project using separate ADC+DAC (5V power) i ended up using a gain of ~1.4, but it might vary depending on the guitar/pickups etc.
- If the buffer is fine, time to check the ADC. First make sure the chip inputs are biased by measuring the DC voltage with no input signal. Should be about 2.5V, measured directly on the chip pins. Moving to the I2S side. While writing drivers i usually do a larger buffer in ram, enough to collect a few 1kHz sin cycles, record the input signal into the buffer and send it back to the PC for analysis. Good idea is also to hook up a logic analyzer to the I2S bus and observe the data. If the data is corrupted, there might be something wrong with the ADC config or the module is faulty. If the logic analyzer does not show any suspect corruption (again, sin is good to eyeball it), there might be issues with I2S configuration, DMA, memory align and all sorts of surprises hidden in the chip's Errata.
- Having the correct data sampled, it's time to move to the DAC. Simple loopback should play the incoming data, if not - double check the configuration, try different module.

If the prototype is built on a breadboard with wires, the 512xFs mode with 25MHz master clock might suffer from the signal integrity issues. Try 256Fs with half the MCO frequency.

Hope it helps!

gabrielgcma

#15
Thanks guys, y'all have been really helpful and patient. Stuff that even my professors weren't able to help with.

Unfortunately, my blackpill dev board & DAC are fried. I was experimenting with powering the dev board with AMS1117 3.3V and 5V regulators, everything was going fine for the first couple tries. When I tried setting it up again after a day, I don't know what I did wrong, but the regs started to blink their LEDs. I guess I didn't act quick enough to unplug the dev board, because now there's a short between 3.3V and GND at the devboard, and the DAC module heats a lot and won't turn its LED on - no short between 5V and GND, but 276k ohms between 3.3V and GND, I guess it's a short. Could be faulty regs, could be just my stupid a**.

The project will be idle for the next couple weeks, while I wait for a new blackpill dev board and DAC from China - I tried searching for DIP CODECs for quick prototyping, but nothing so far. While it would help a lot with the hardware, unfortunately I'm not able to buy a Teensy or a Daisy Seed (at least not original ones) because of exorbitant import taxes, shipping fees & dollar cost here in my country - for example, a 65MB SDRAM Daisy Seed at $25 with $110 of shipping (only option at their website) is equivalent to 51% of a minimum wage check here.

Thanks for the help, I will post updates. 


ElectricDruid

Quote from: gabrielgcma on March 22, 2025, 12:45:41 PMUnfortunately, my blackpill dev board & DAC are fried.

Sorry to hear that. I think we've all been there, but it's not a great place to be. :'(
It's just annoying that doing something stupid is so much easier than doing something clever, otherwise I'd do clever stuff all the time!

You'll get it sorted.


PRR

Quote from: gabrielgcma on March 22, 2025, 12:45:41 PMnow there's a short between 3.3V and GND at the devboard, and the DAC module heats a lot and won't turn its LED on - no short between 5V and GND, but 276k ohms between 3.3V and GND, I guess it's a short.

276k is NOT a "short". Get bright light and good magnifier, look for stray scraps of wire. I have "fixed" sick PCs by turning them over and beating flakes of metal out of the bus slots (it was in a workshop). Measure carefully, take full notes, work out what is really going on.
  • SUPPORTER

gabrielgcma

Quote from: PRR on March 22, 2025, 02:32:40 PM
Quote from: gabrielgcma on March 22, 2025, 12:45:41 PMnow there's a short between 3.3V and GND at the devboard, and the DAC module heats a lot and won't turn its LED on - no short between 5V and GND, but 276k ohms between 3.3V and GND, I guess it's a short.

276k is NOT a "short". Get bright light and good magnifier, look for stray scraps of wire. I have "fixed" sick PCs by turning them over and beating flakes of metal out of the bus slots (it was in a workshop). Measure carefully, take full notes, work out what is really going on.


Thanks, that's a good tip. I did take it on the magnifier and even though there really is 276k ohms on the 3v3 module rail with respect to GND, both voltage regulators are gone, with two of their pins shorted.  :'(   

gabrielgcma

#19
Hi guys. I got the new gear but still the DAC output sounds awful, distorted and clipped (the audio interface CLIP led blinks all the time).

I'm now using an OPA2376, 5V single-supply rail-to-rail input and output. The signal after the amplifier looks a bit better, here's an E on the 12th fret (don't mind the readings, I switched from DC coupled to AC coupled, and the gain is 6x):



This time, I'm running the DAC module output into a buffer that's also rail-to-rail input and output, and from that I'm plugging into the audio interface:





This is the I2S output of the ADC with 6x gain:





This is a picture of the mess:



From your guys' experience, what do you think it could be? Could it be the long wires? Am I wasting time by not etching a board or using a perf board?

So far I've tried:

- inserting an 1k resistor inbetween the DAC_OUTPUT and the output buffer.
- decreasing the input gain and using unity gain