DIYstompboxes.com

DIY Stompboxes => Digital & DSP => Topic started by: knutolai on March 26, 2013, 06:54:09 PM

Title: Netduino onboard ADC for audio
Post by: knutolai on March 26, 2013, 06:54:09 PM
Hi forum
As a part of a school project I am going to make a digital guitar effect pedal. I've currently decided to try the Netduino platform (resources listed below). Ruffly its a Arduino only faster and with more memory (RAM and for program). Its programmed in C# (.NET framework) and runs on 3.3 volt making that the maximum input voltage of the pins.

Sooo.. For this project as it is my first DSP pedal project I thought I'd use the onboard ADC and DAC (both 12-bit), only adding a simple circuit with buffers for volume and effect dry/wet. What I need to figure out is how I prepare a audio signal for the onboard ADC pin?

I do not exactly deem myself proficient at electronics, but this is what I have come up with so far:
The pin expects a signal between 0 and 3.3 volt. A voltage above or below that would result in clipping. If a signal is exceedingly high voltage the pin will be damaged. Is there any good way of scaling any signal so that I know it wont exceed the limits listed above? I know I can apply DC offset to offset the signal (silence at 3.3 volt/2 = 1.65 volt) and 3.3 volt zener diodes to safeguard the pin.

It there anything else I can do to protect the chip and prepare the incoming signal? If have this feeling I've missed some crucial OP Amp application or something  :icon_confused:

Any response is much appreciated :)

The Netduino 2 board specifications:
http://netduino.com/netduino2/specs.htm
Netduino 2 schemaitc:
http://netduino.com/netduino2/schematic.pdf
Title: Re: Netduino onboard ADC for audio
Post by: SISKO on March 26, 2013, 11:55:09 PM
Im no expert, but the firsts things that come to my mind is:
Antialiasing filter. Essential in all ADC.
Gain adjustable stage.
AGC? Kind off compressor
You *may* wish to have various inputs (guitar, mic, line level) if its gonna be reussable board.

Are you thinking about the output stage necesities too?
Title: Re: Netduino onboard ADC for audio
Post by: knutolai on March 27, 2013, 05:36:31 AM
So basically a low pass filter that cuts away everything above sample rate/2? Thanks. This is very helpful. Same goes for the Gain stage. I'm looking into automatic gain control compression.  seems useful!

This will be a project for guitar and/or feedback circuits using guitar pedals. A little of topic, but what would be the maximum voltage of a AC output from a amplifying circuit supplied with 9 volt DC? Im guessing 9 volt or so, but would that be a signal oscillating between 0 and 9 or -9 and 9?

I don't really know of any necessities for the output stage outside of adding a simple buffer and capacitors for removing any possible offset. Anything to add to that?
Title: Re: Netduino onboard ADC for audio
Post by: SISKO on March 27, 2013, 09:41:43 AM
The antialias filter needs to be a *very* sharp one. Or you can make your cut off  start way lower... like SR/4. You dont want any freq above SR/2 to enter your system if you are looking for a non distorted signal (its not the kind of distortion in a drive pedal, its non musical like a ring modulator)

You are right about output voltage. It would be oscillatin between 0v and 9v in an extreme case. Most of the time is much lower than that. Even if the circuit is running at full level, the maximum output voltage would be 8v or so.

Id add a headphone amplifier, a line level out (you may come up with an amp simulator!  :icon_biggrin: ) and a guitar amp out. But those are not really necesary.
Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 07, 2013, 03:21:59 PM
So I designed a first draft using ExpressSCH. The idea is that I'll be able to control the input and output gain for the Netduino. As well as the blend/mix between the dry and wet signal. The part in front of the ADC is meant to limit the signal between -0.6 and 3.3 volt. The inverting opamp has a low pass filter with a Fcof (cut-off freq) of approx. 21kHz. With a samplerate around 96kHz I would imagine that to be tolerable  ???

Im not really a proficient circuit designer and I would appreciate any feedback for improvements very much! The main thing which is bugging me is the pre-gain implementation. I know how to calculate the gain from a inverting amp, but varying the input resistor would also change the impedance of the buffer. Is that problematic? I dont wish to change the feedback resistor as that also changes the Fcof. Any thoughts on that?

(http://i.imgur.com/vOyBooh.png)
Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 08, 2013, 05:24:57 AM
These are my two cents:


Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 08, 2013, 07:18:37 AM
Thank you very much for this. Some great improvements here! However there is one thing I dont understand:
"TL072 works fine with loads down to 10k, so you can decrease the resistors to improve the signal/noise ratio."

Im not at all familiar with "loads" (coundnt find any good resources explaining the concept either, got any good research keywords?) I think I understand what you are suggesting (lowering the resistors, but keeping the ratio between the resistors in the buffer modules), but woundnt this hurt the impedance of the buffers? Can one have good SN-ratio and high impedance at the same time? By how great a magnitude do you suggest I lower my resistors?
Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 08, 2013, 08:13:09 AM
For instance the output load for the input buffer is P2, for the ADC inverter is R5||R6, and so on. The purpose of a buffer is to have a high impedance at the input and a low impedance at the output. So you want the input impedance to be as high as needed by the preceding circuit. In audio they say the input impedance should be around 10 times bigger than the output impedance of the preceding circuit. The input impedance of your buffer or inverters is not affected by the changes in their output circuits.

You can make C2 1u or 2.2u and connect it to the input buffer's output, then make R3 47k or 22k. This would isolate the preceding circuit from the inverter.
Basically you want to have the resultant load being seen at the buffer load (R3 in parallel with P2) more than 10k but not too far for TL072. There are op amps that can handle output loads much better, like NE5532, but you don't need it here.

DAC output impedance is 15k in the datasheet so you can make R8 150k or 220k to minimize noise.

Right now I have a cold (hence the spare time and some dizzyness :icon_biggrin:), so please take everything I wrote with a grain of salt.

Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 08, 2013, 09:30:28 AM
Hmmmmm! I think I get it. Anyways so I made a new version of the circuit with your suggestions.
Pre gain goes from 0,23 to 4,8
Post gain goes from 0,23 to 5,1
I might add a capacitor in parallel with the feedback resistor in the inverting buffer after the DAC.

One thing that I thought about:
Wount there be any crosstalk between the output of the DAC buffer and the input of the ADC buffer (read as feedback-problem)?

(http://i.imgur.com/T3G1iaX.png)
Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 08, 2013, 11:53:49 AM
It can be, although the output impedance of the input buffer should shunt it. Anyway, here's another cent:
(http://s17.postimg.org/j7jgxnznz/netduino_input_output.png)

Things added:

I hope it helps, I'm not that good at theory.

BTW, the ADC inverter has the inputs reversed in your schematic.

Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 08, 2013, 06:48:26 PM
Sorry. This is starting to go well over my electronics knowledge. I looks great and I really appreciate your help  :icon_smile: I think I understand the functionality of the circuit for the most part however I do have a few questions/things I'm unsure about, as well as some circuit modules I don't understand the significance of:
1. D1 and D2 is meant to give the circuit polarity protection if a power supply with the wrong polarity should be connected (?)
2. What is the purpose of R1 and R6? I don't recognize them as being part of any buffer modules I'm aware of.
3. What is the purpose of connecting the potmeters to the reference voltage? Does it yield the same effect as connecting to ground (this is what Im most familiar with? Does using the reference voltage have any advantages?
4. Why would R13 and R14 be different?
5. Why would I need a 2. order LP-filter after the DAC?
6. Would the cut-off freq of the LP-filter in front of the ADC depend only on C7 and R4?
7. Lastly, what is the point of having four capasitors in parallell between +9volt and ground?

Again thanks so much for the help! I really wish to understand this thoroughly  :icon_wink:
Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 08, 2013, 07:18:18 PM
:icon_biggrin:
1. The diodes protect the input from any signal being larger than the power supply (9V in this case). It's the same as at the input into the ADC of your microcontroller.
2. Current limiters.
3. The op amp pins that are connected to the pots are at the reference voltage. We don't want DC currents through the pots.
4. Because the signal was already amplified 5 times by the DAC output inverter.
5. Antialiasing filter. Not the best option, but it'll do.
6. AFAIK, yes.
7. Two of the 100n (ceramics, as they are good at shunting high frequencies) are to be soldered as near to the supply pins of the op amps as possible. The other 100n capacitor helps the 100u capacitor with the highs.

Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 09, 2013, 06:10:34 AM
About the anti-aliasing filter. Why would I want it after the digital part of the circuit? If aliasing has occurred adding a LP-filter after the DAC won't remove the unwanted frequencies as they have mirrored around the nyquist frequency of the ADC (samplerate/2).
Is the anti-aliasing filter meant to prepare the signal for the next module (read as soundcard/digital-pedal/amp) in the signal path?

My approach to this circuit is kind of minimal in terms of component count. Is the TLE2426 really necessary for good results? Could I use a 5 volt regulator like the LM7805 instead? Or just regular resistors like in the original circuit?

Also I found this on the Netduino forum:
http://forums.netduino.com/index.php?/topic/496-netduino-now-with-internal-aref/
The Netduino board has a analog reference pin! I could use that to bias the signal going into the ADC right?  :icon_biggrin:

Instead of the IC2 B inverting amplifier I'm thinking of adding something like this: (I mean of course the circuit architecture, not the specific values)
(http://www.electronics-tutorials.ws/filter/fil28.gif)
Wound that be unproblematic?

Oh and I absolutely love your gain potentiometer implementation! I thought about doing something similar to this, but really couldn't be sure if it would work!

Another observation:
Wont the buffer in front of the ADC always have a gain less than (-)1? I calculate (R4+pot)/R3 -> 20k/47k. I dont mean to be picky. Am I right on this or am I missing something vital?
Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 09, 2013, 09:02:43 AM
Here's a kinda unsure third draft:
(http://i.imgur.com/0yhFRJP.png)
I really want to keep the dry/wet controller-functionality. I think this will work. I'll definitely add the capacitors between the IC power pins, though I'm undecided on how to produce the Reference voltage as I'm limited to the parts currently in my possession.
Title: Re: Re: Netduino onboard ADC for audio
Post by: slacker on April 09, 2013, 10:48:15 AM
There's no need for a fancy voltage reference, the voltage divider and cap in your earlier schematic will do the job. If you want something more solid you can buffer that reference with an opamp.
Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 09, 2013, 02:41:46 PM
About the anti-aliasing filter. Why would I want it after the digital part of the circuit? If aliasing has occurred adding a LP-filter after the DAC won't remove the unwanted frequencies as they have mirrored around the nyquist frequency of the ADC (samplerate/2).
Is the anti-aliasing filter meant to prepare the signal for the next module (read as soundcard/digital-pedal/amp) in the signal path?

Ha, you got me! God knows what was I thinking. Of course you're right.


My approach to this circuit is kind of minimal in terms of component count. Is the TLE2426 really necessary for good results? Could I use a 5 volt regulator like the LM7805 instead? Or just regular resistors like in the original circuit?

The original resistor divider alows only for 0.45mA. Adding everything that is referenced to the +4.5V (the ADC inverter has the 10k + 100 resistors on the output) made me think I want more current capability from the reference. Of course you can use the original resistor divider with a buffer (op amp or transistor). 78XX regulators are fairly noisy and they would not give you a real half supply reference.


Also I found this on the Netduino forum:
http://forums.netduino.com/index.php?/topic/496-netduino-now-with-internal-aref/
The Netduino board has a analog reference pin! I could use that to bias the signal going into the ADC right?  :icon_biggrin:

Yeap.


Instead of the IC2 B inverting amplifier I'm thinking of adding something like this: (I mean of course the circuit architecture, not the specific values)
(http://www.electronics-tutorials.ws/filter/fil28.gif)
Wound that be unproblematic?

I used an inverter because it's more fit for the mixing job, as it makes a virtual ground on its inverting input.


Wont the buffer in front of the ADC always have a gain less than (-)1? I calculate (R4+pot)/R3 -> 20k/47k. I dont mean to be picky. Am I right on this or am I missing something vital?

Let's see: minimum gain is 10k / 47k ~ 0.21, maximum gain is 10k / 47k * (10k (the pot) + 100) / 100 ~ 21.48. So, minimum gain will be less than 1, but this is what you wanted to be able to atenuate a high level signal. Isn't it?


I really want to keep the dry/wet controller-functionality. I think this will work.

Hey, it's your circuit. IMHO, a separate level control would be much more flexible, but if it works for you, it works.


There's no need for a fancy voltage reference, the voltage divider and cap in your earlier schematic will do the job. If you want something more solid you can buffer that reference with an opamp.

Actually it is fancy only if it's not already in your drawer.


LATER EDIT: looking behind, I found that the most usefull sugestion has not been given. Use a breadboard, there's nothing faster in clearing up almost all issues.

Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 09, 2013, 03:06:26 PM
Uh, now that you added resistors before the blend pot, it will be able to atenuate the clean signal only 15 times (-23dB) and the processed signal only 2.3 times (-7dB). You don't need R13 and R14.

Also, R15, R9 and C12 look funny. Maybe you wanted R9 to be 10k or something like it? Or you can disband them and use the final op amp as an voltage follower.

Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 09, 2013, 07:13:45 PM
My brain kind of feels like scrambled eggs! OK, soooo.. I thought maybe change the architecture around a bit (in my head this makes a lot more sense now, though I might just have missed the mark completely)

Fourth draft:
(http://i.imgur.com/ju6Fh16.png)

The idea with the gain pots is that both the dry and wet signal would be amplified/dampened equally (to keep the mix even when the blend is set at 50/50). If my, and your, math (thanks for that calculation! :icon_razz: I didnt have a clue one could amplify like that) is correct the input buffer gives a gain ranging from approx 0,2 - 20 and the output buffer gives a gain ranging from approx 0,05 - 5.
5 * 0,2 = 1
20 * 0,05 = 1 , meaning any dampening or amplification can be leveled

Now there probably are a few flaws here, as well as some guesswork from my part. As you pointed out breadboarding the circuit is probably a good idea at this point. I have to stop spewing schematic sketches everywhere!  :icon_biggrin:
First of Im not sure if R1 is needed anymore. Im guessing it can be omitted as R2 makes it redundant (?)
Im guessing my output buffer is all wrong in relation to the impedance on the output of the other two buffers. I cant seem to wrap my head around how I would calculate the gain using P2.

Also Ive added a buffer to amplify the current for the Vref and changed the buffer in front of the ADC to a 2. order LPF.
Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 10, 2013, 08:57:57 AM
OK so I read through once more. If I understand correctly the load from the input- and DAC-buffers pushed onto the output buffer equals P2 (100k). When I then want a min. gain of (-)0.05 I would use a 4,7k feedback resistor in the output buffer.
Like this: (correct??)
(http://i.imgur.com/dpO5gkS.png)
Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 11, 2013, 10:00:26 AM
Quote
Let's see: minimum gain is 10k / 47k ~ 0.21, maximum gain is 10k / 47k * (10k (the pot) + 100) / 100 ~ 21.48. So, minimum gain will be less than 1, but this is what you wanted to be able to atenuate a high level signal. Isn't it?

Where can I find this formula?
Title: Re: Netduino onboard ADC for audio
Post by: ggedamed on April 12, 2013, 06:55:38 AM
Sorry, man, my cold is gone and my child is on holiday :icon_lol:. So not much spare time from now on.

Take a look here (http://www.electronics-tutorials.ws/opamp/opamp_2.html).

First, you should keep a resistor between the cursor of P2 and the inverting input of the op amp (BTW, it would much easier to discuss if the op amps would have names), to limit the op amp gain at the ends of the pot travel.
Then replace P3 and R4 with 2 resistors, like this (figure 2):

(http://s18.postimg.org/k9m90lsw9/op_amp_inverting.jpg)

Let's say Vo is the output voltage of the op amp. Vout from the page linked above would be Vo * R4 / (R3 + R4). Use it in the eqations in the page linked above and there you have it.

I leave it to you as an exercise the alternative blend control from figure 3.





Title: Re: Netduino onboard ADC for audio
Post by: knutolai on April 12, 2013, 12:45:09 PM
Quote
Vout from the page linked above would be Vo * R4 / (R3 + R4).

you mean Vin * R4 / (R3 + R4) right?

Quote
maximum gain is 10k / 47k * (10k (the pot) + 100) / 100 ~ 21.48.

This is where you lost me. I cant see how that calculation relates to that simple formula. 100 is the the 100R resistor R4 right (in my schematic)?