Author Topic: Design Critique - input / output for microcontroller  (Read 2229 times)


Design Critique - input / output for microcontroller
« on: February 21, 2012, 10:28:35 PM »
I'm looking to use a microcontroller (attiny) to do some really basic signal processing.  I know all about the limits of that particular hardware so I'm certainly not shooting for super high quality, but as a software guy seeing what I can make it do sounds fun.  Also as a software guy, the circuit needed to get things into and out of the microcontroller seems a bit daunting to me.  I'd really appreciate any critique/suggestions on this design.  Here is what I'm attempting to accomplish:
1. low pass filter the input with a cutoff near 4k - my sample rate will probably be higher than 8k and as I understand it the nyquist freq is sample rate / 2 and that needs to be filtered out to reduce aliasing.
2. amplify the input - the attiny only has 8-10 bits of precision in ADC so I want to use as much of the 0-5v range as I can.  I picked 11 as the gain factor to try and balance this goal against making the op amps clip on hotter signals.
3. low pass filter the output to remove any PWM frequency bleed. I can make the PWM run at near clock speed (in the MHz) range, but this should clean things up regardless
4. support mixing back in the clean signal and adjusting the output volume.  I'm sourcing the clean input after steps 1 and 2 (so the same thing that's going into the attiny).

I'm running just about everything off of 5v that I plan to get from a regulator.  I'll have to make sure that whatever I pick can supply enough current for the uc and the opamps.  Is this a realistic thing to do?

Here are pics of the input and output.  The input schematic's output is the in to the attiny as well as the source of the clean signal for later.  The output schematic includes dc biasing that doesn't need to be in the real circuit since my output will be 0-5v.

Are there any big problems with this?  I've only used 3 op amps so realistically I have a spare one that I could use to do the blend or volume differently if there's a better way.


Re: Design Critique - input / output for microcontroller
« Reply #1 on: February 22, 2012, 10:10:05 PM »
The way you set the input to half of 5V also puts half of 5V's hash into the input. Which is silly, because you HAVE a clean half-5V nearby.

And you don't actually want to do it that way. The 200Ks won't match, the 100Ks won't match, and OA2 takes the difference of the unmatches and amplifies by 10. In a worst-case (10% resistors at the tolerance limit opposite ways) you have 0.5V times 11 is 5.5V output error, the output could (try to) be 8V or -3V. Which aint good on a 5V opamp.

Take all your refs the same place.

Filter that Vref good. Perhaps 0.1uFd off 100K is fine in a regulated world. My history is wall-power with both 60Hz and sags/spikes, I'd use a fat cap.

The gain-stages only need gain for AC/Audio. A cap in the bottom of the NFB network drops the gain to unity at DC. The output follows the DC level from Vref.

Now a tricky-bit. That SK filter "can" be gimmicked onto a Gain stage. The gain-set network has a point at unity gain. It has non-zero impedance, but if the NFB network impedance is much lower than filter impedance, the error is mild. This eliminates the second opamp (sorry!).

I suspect the happy gain won't be 11. I've shown a clean place to trim it on test.

« Last Edit: February 22, 2012, 10:11:58 PM by PRR »


Re: Design Critique - input / output for microcontroller
« Reply #2 on: February 22, 2012, 11:35:55 PM »
That is incredibly helpful, thank you.  Best of all, I think I understood most of it.

It's probably clear that most of my first attempt was directly from the single supply op amp collection thing.  I was playing around with using a single op amp for both the filtering and amplification but I couldn't get it work out with a single supply without amplifying the bias voltage and making a mess.  The cap in the feedback before ground was the missing piece...and makes sense now that it has been pointed out.

After posting I thought about making the input gain variable (either via trimmer or even a knob) since (depending on the effect and its order in the chain) the signal level could be drastically different.  I've got it modeled now as a fixed 220 into a 1k pot.

Is 4kHz a reasonable frequency for the filter roll off?  The best answer is probably 'build it and see'.  I can probably get the sample rate high enough to add some room for more treble if it will sound better (and if I end up sampling at 8k it probably won't sound very good to start with so the aliasing won't really matter).

Thanks for saving me an op amp :)


Re: Design Critique - input / output for microcontroller
« Reply #3 on: February 23, 2012, 12:28:04 AM »
> I think I understood most of it.

Glad you did. I didn't, and there is an error in my DC error analysis. Not as bad as -3V to 8V; still bad enough that worst-case won't work.


Forgotten thought:

Not all opamps work well at 5V total supply. Used to be hardly-any; now there's good choices. Choose well.

The universal TL072 has an internal 7V reference, works great at 9V or a bit below, but is probably not a good choice at 5V. Aim for 5V suggested supply and 1MHz-10MHz gain-bandwidth. (99MHz chips are mighty fussy about layout and gross over-kill for audio systems.) Other specs will probably be sufficient.
« Last Edit: February 23, 2012, 12:29:40 AM by PRR »


Re: Design Critique - input / output for microcontroller
« Reply #4 on: February 23, 2012, 05:32:55 AM »
Using a CMOS opamp that can do rail to rail output would also be beneficial


Re: Design Critique - input / output for microcontroller
« Reply #5 on: February 23, 2012, 06:46:18 AM »
Use an MCP6004 instead of a TL072 ...they work well & are cheap as erhm...chips!  :icon_mrgreen:


Re: Design Critique - input / output for microcontroller
« Reply #6 on: February 23, 2012, 10:57:24 AM »
Thanks for the chip recommendations. I also found the AD8606 which seems to fit the bill.