Feasible to use an AVR ATtiny13 for audio AGC?

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just wondering if you guys think this is possible.

I plan on using an AVR ATtiny13 and two amplifiers that have selectable gains of +1, +10, and +50. Using two amplifiers in series, I can get away with +1, +10, +50, and +100 gain. I am going to send a microphone input which can range from 2 mV rms (dynamic mic) to 140 mV rms (electret mic), into the amplifier and default the gain to +100. I'll have the output of the amplifier connected to an ADC channel on the AVR and if the signal starts to clip, I'll lower the gain. I'll also have voice band filters at the input/output of the amplifiers. Does this method sound good or would there be a simpler/easier way to do it?

I've never really programmed any feedback type loops in an AVR, does anyone have any example projects that are similar? Any tips?

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a suggestion: The gain steps sound much too large to me to make a smooth AGC. Personally, I'd do it with just one op-amp and a digital potentiometer.

Here's a bunch from Digikey's catalog: http://search.digikey.com/scripts/DkSearch/dksus.dll?Cat=2556350

Either that or a voltage controlled variable-gain amplifier fed by a DAC. I've never used one but a quick google shows they exist: http://www.national.com/pf/LM/LMH6505.html

odokemono. I try to entice electrons to do my bidding.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in principle, you certainly can do it: use the avr to detect rms and use that to control a digital pot to produce variable gains.

a simpler solution is to rectify the audio signal and adc that as a way to detect clipping.

I think a VGA like AD603 would be far easier to implement.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have a Voltage Controlled Amplifier, which is an analog multiplier, as the gain element, you could use the computer to calculate the avg or rms signal level you are interested in (probably the output level?) and use a pwm out to create a dc control voltage to the VCA. I guess the win using the computer is you could have up and down buttons to select threshold level and output/input gain (compression ratio). Maybe a text lcd would be good for displaying the user selectable parameters.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Small PICs have been used for audio-derived AGC in receivers for the amateur radio bands using the ADC to sample the audio, so it should be feasible. IF amplifiers generally have voltage-controlled gain, which makes things simple.

Leon Heller G1HSM

Last Edited: Sat. Oct 9, 2010 - 08:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your question brings back memories.
I did a project years ago building a VHF radio repeater. The micro was a basic stamp, and I used a digital pot to control the audio gain. (I used two HT's, I did not build the RF section!). Google precision rectifier for circiuts using a diode and an op amp to convert low level audio to DC without worrying about the forward voltage drop of the diode with low level audio signals.

I'v also used Analog Devices VGA's, Variable Gain Amplifiers. They have chips that use an analog control voltage, as well as some with a digital interface. Their bandwidth is much greater than you need, but they are also easy to use. AD's VGA's .

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theoretically speaking, you could do gain control with the AVR by:

1) Reading in the signal from an 8-bit ADC.

2) Twos-compliment the number so that your absolute number (0-255) is now a signed value (-127 to 128).

3) Invert the sign on any negative number (take the absolute value of the number). This gives what you might see on an O-scope when a signal goes through a full wave rectifier.

4) Check to see if this value is less than a current running tally of "peaks". If so, decrease the maximum peak count by a certain value (maybe 10) to simulate an RC-discharge. If the value is greater, update the maximum peak tally with this new number. This simulates a smoothing capacitor on a peak detector circuit.

5) Take the difference between the tallied peak value (simulated peak detector) and the threshold gain value, and calculate the percentage that the signal needs to be adjusted.

6) Apply that adjustment to the original twos-complimented value taken in from the ADC.

7) Reverse the twos-compliment of the modified sample to give you an unsigned 8-bit value.

8) Push the modified value out to your DAC (a PWM signal from one of the output ports at around 200KHz and pushed through a low-pass filter to eliminate the carrier).

The tricky parts to this is having one or more interrupt handler routines to get the value from the ADC and putting the modified value out on the DAC in a time-consistant manner. With the inventive use of ring buffers for storing the values coming in and going out, you can have your main process - the one that figures out the peak value and adjusts the gain for the sampled value - running all-out pulling stuff from one ring-buffer, and putting an adjusted value into another. If one buffer becomes empty or full, the main process "waits" until the one or both conditions resolve themselves.

A similar inpur / output process is used with most sound cards, even those using real-time audio. You'll have a slight delay in the signal, but it won't be noticable.

(Or, you can just use a digital pot...)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can probably still find "multiplying" DACs, where you squirt your signal in as the DAC reference voltage, and take your multiplied signal straight from the DAC output. Gain varies from zero to fullscale according to the DAC setting.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a typical differential pair is a reasonably good hardware multiplier.

Quote:
The tricky parts

the real tricky part here is to design a system that is overall stable. in essence, you have a negative feedback system that is highly non-linear and analytically difficult to figure out before hand. the mcu is essentially a PID here.

if you want to have optimal performance, you have to chose the pid algorithm carefully. a self-tuned pid or a pid with Kalman filtering would be quite desirable but that demands a lot out of the device + programmers.

again, I would stay full analog here. a VGA like ad603 would actually be your best bet.

or you try different combinations.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now Mr Millwood.... can you quantify 'reasonably good hardware multiplier' in terms of signal to noise ratio and distortion? My observation after studying several decades of audio compressor and limiter circuits as published in the Journal of the Audio Engineering Society is that exactly none of them use an emitter base junction as a gain reduction element unless it is encapsulated in a circuit that compensates for the nonlinearness of the junction. And I also doubt if any commercial compressors and limiters use classical PID algorithms, which assume the system and equations are linear. The attack and release and threshold and 'hard knee' and 'soft knee' and compression ratio knobs are are real nonlinear, in that they have clever tricks to make the gain adjustments unnoticeable... diodes and pseudo rms detection done by charging a cap with a current proportional to error above threshold (Allison Gain Brain, circa '70 for example). I think this guy could make a digitally controlled gain gizmo with a simple algorithm like 'if the input is 1 db above threshold, reduce gain 1db' and make release time const variable, but faster than the attack time const. I think we would need a panel of Golden Ears to detect whether avg or rms of waveform was less audible. And of course, I would use an AVR in my version, so you won't gripe about me being off topic.

Imagecraft compiler user