Author Topic: How to set OpAmp gain using microcontroller?  (Read 11979 times)

0 Members and 1 Guest are viewing this topic.

Offline DoubleM

  • Contributor
  • Posts: 9
How to set OpAmp gain using microcontroller?
« on: June 11, 2013, 12:34:30 am »
Hi, everyone! I have a little problem that I can't solve currently. I have tried to find answer on google, but didn't have any luck... So basically here is the problem. I need to somehow change the gain of the operational amplifier (LM714 or similar), but instead of regular resistor i need to do it from software.

For example there are two buttons for adjusting volume (Volume+ and Volume-), and when button is pressed, my microcontroller should change the gain of OpAmp accordingly. I have made a little schematic diagram to better explain what i have, and what i need.

Only thing i could think of is digital potentiometer, but i would like to avoid additional IC-s, and keep it as simple as possible.

If anyone have an idea how to do it, please tell me... Thank you!
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 19680
  • Country: nl
    • NCT Developments
Re: How to set OpAmp gain using microcontroller?
« Reply #1 on: June 11, 2013, 01:20:08 am »
An amplifier with DC gain control like the TDA7052A from NXP and use PWM to control the gain. There are also programmable / variable gain amplifiers but these are usually more expensive. Maybe some other audio related chips can be used.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: How to set OpAmp gain using microcontroller?
« Reply #2 on: June 11, 2013, 01:24:29 am »
Yeah, this just isn't simple. I've switched taps on a voltage divider with an analog switch, but that's no good if you want that many steps. I'd go with a digipot (check the frequency response, though) or one of these audio chips as nctnico suggested. You're not going to get it without an IC, unless you spend a lot of time and board space on a discrete analog circuit.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: How to set OpAmp gain using microcontroller?
« Reply #3 on: June 11, 2013, 01:29:14 am »
For even better simplicity - are you sure you can't just use a pot?
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: How to set OpAmp gain using microcontroller?
« Reply #4 on: June 11, 2013, 01:38:41 am »
If you can leave the feedback resistor fixed and vary the one to ground, a VCA using a FET may be viable.  The FET would be controlled via smoothed PWM.  Just a thought.
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1419
Re: How to set OpAmp gain using microcontroller?
« Reply #5 on: June 11, 2013, 01:47:36 am »
Just use a green LED shining on a CdS phototresistor, enclose both in a piece of black shrink tubing, tightly optically coupled.
The LED would need to be driven by an emitter follower,  a RC integrator on the base from a PwM output of the MCU smooths out the PWM control signal. A small amount of forward bias setting the min  light output might be necessary with a resistor to VDD. The photoresistor should be placed from the output of  the opamp to the inverting input with a fixed resistor to ground. The resistor to ground sets the min gain.  A resistor in parallel with the phototransistor would set the max. gain, depending on the dark resistance of the photoresistive element. With the cheaper CdS or CdSe cells which have lower dark resistance, you may not need a max. gain setting paralled resistor. If you set the PWM limits, the boundaries of control, with MCU software clamps, perhaps none of the gain trimming resistors would be necessary.
« Last Edit: June 11, 2013, 01:58:19 am by Paul Price »
 

Offline DoubleM

  • Contributor
  • Posts: 9
Re: How to set OpAmp gain using microcontroller?
« Reply #6 on: June 11, 2013, 02:13:52 am »
For even better simplicity - are you sure you can't just use a pot?

That's the main issue here... If i could, i wouldn't be asking this silly question :)

If you can leave the feedback resistor fixed and vary the one to ground, a VCA using a FET may be viable.  The FET would be controlled via smoothed PWM.  Just a thought.

This is great idea, but problem is that signal is not always positive, but changes from -1V to +1V (for example), so FET would work correctly only when signal value is in the positive range... Only if i first shift the input to, say, 0V-2V peak-to-peak, and then... Well it's a mess...

So looks like for now digipot is the only viable solution.. Any recommendations on which one to buy? I would need 0-20kHz frequency bandwidth and at least 128 steps of value...
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: How to set OpAmp gain using microcontroller?
« Reply #7 on: June 11, 2013, 02:16:33 am »
Only if i first shift the input to, say, 0V-2V peak-to-peak, and then... Well it's a mess...

Shifting the signal isn't a mess, it's a perfectly valid solution.

Quote
So looks like for now digipot is the only viable solution..

What about the LED/photoresistor? I rather like that, actually...
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline DoubleM

  • Contributor
  • Posts: 9
Re: How to set OpAmp gain using microcontroller?
« Reply #8 on: June 11, 2013, 02:23:52 am »
Just use a green LED shining on a CdS phototresistor, enclose both in a piece of black shrink tubing, tightly optically coupled.
The LED would need to be driven by an emitter follower,  a RC integrator on the base from a PwM output of the MCU smooths out the PWM control signal. A small amount of forward bias setting the min  light output might be necessary with a resistor to VDD. The photoresistor should be placed from the output of  the opamp to the inverting input with a fixed resistor to ground. The resistor to ground sets the min gain.  A resistor in parallel with the phototransistor would set the max. gain, depending on the dark resistance of the photoresistive element. With the cheaper CdS or CdSe cells which have lower dark resistance, you may not need a max. gain setting paralled resistor. If you set the PWM limits, the boundaries of control, with MCU software clamps, perhaps none of the gain trimming resistors would be necessary.

Very creative thinking there :) Looks like that would work after a bit of tweaking of PWM values etc.. But $6 - $10 for a photoresistor is a bit too much for this project, and digipot costs about $1 - $2 for what i need.

In the meantime I've found this:
http://www.maximintegrated.com/datasheet/index.mvp/id/5218

For $1.32 it has everything I need. That is most likely what i will use, if somebody don't come up with a better idea...
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: How to set OpAmp gain using microcontroller?
« Reply #9 on: June 11, 2013, 02:25:01 am »
But $6 - $10 for a photoresistor is a bit too much for this project

:wtf: On what planet? $6-$10?
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: How to set OpAmp gain using microcontroller?
« Reply #10 on: June 11, 2013, 02:26:26 am »
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Paul Price

  • Super Contributor
  • ***
  • Posts: 1419
Re: How to set OpAmp gain using microcontroller?
« Reply #11 on: June 11, 2013, 02:27:47 am »
You can 5 Photoresistors for < $4 U.S.
« Last Edit: June 11, 2013, 02:34:51 am by Paul Price »
 

Offline DoubleM

  • Contributor
  • Posts: 9
Re: How to set OpAmp gain using microcontroller?
« Reply #12 on: June 11, 2013, 02:28:25 am »
But $6 - $10 for a photoresistor is a bit too much for this project

:wtf: On what planet? $6-$10?

Look at his original post, he attached the picture of a catalog where you can see prices... 6-11 bucks a peace.

But, i found this on ebay just now, 10pcs for $5, but would this work?
http://www.ebay.com/itm/10-Photoresistor-Cds-Light-Sensitive-Device-Dependent-Resistor-LDR-GL5537-2-/260918852577?pt=US_Single_Use_Batteries&hash=item3cbff9bbe1
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7805
  • Country: us
  • adieu
Re: How to set OpAmp gain using microcontroller?
« Reply #13 on: June 11, 2013, 02:32:31 am »
Yes.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline DoubleM

  • Contributor
  • Posts: 9
Re: How to set OpAmp gain using microcontroller?
« Reply #14 on: June 11, 2013, 02:37:56 am »
You can 5 Photoresistors for < $3 U.S.
You're welcome.

Thanks guys, but they are not shipping to Croatia where i live in. "Shipping: May not ship to Croatia, Republic of", but that link what I found, 10pcs for $5, are shipping for free to Croatia, my only question is would that type of photoresistor work tor this project?

It says: "10, Photoresistor Cds Light Sensitive Device Dependent Resistor LDR GL5537-2"
I guess it's ok? If yes, i'm ordering this immediately :)

Yes.

Oh, thank you! I'm ordering right now :)

Thanks for help everybody, i will try this using LED/photoresistor method, (when they arrive to me). I will post here what I did and if it worked or not :)
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: How to set OpAmp gain using microcontroller?
« Reply #15 on: June 11, 2013, 02:48:20 am »
They actually have a name for the LED/CDS sensor combination.  It's called a resistive opto-isolator, among other things.

They used to be popular with guitar effects designers.  I'm not sure how hard it would be to find someone that supplies them these days.
 

Offline DoubleM

  • Contributor
  • Posts: 9
Re: How to set OpAmp gain using microcontroller?
« Reply #16 on: June 11, 2013, 02:56:19 am »
They actually have a name for the LED/CDS sensor combination.  It's called a resistive opto-isolator, among other things.

They used to be popular with guitar effects designers.  I'm not sure how hard it would be to find someone that supplies them these days.

Interesting, i wasn't aware of that... I just ordered 10 pieces of CDS sensors, and I will make it myself using shrink wrap tubing like Paul Price said earlier. I will probably have to tweak the PWM timing until i find the perfect range to work properly. It's probably not a linear relationship of PWM voltage and CDS resistance, but i can compensate for it in software. I think it'll be a lot of fun :)
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1306
  • Country: 00
Re: How to set OpAmp gain using microcontroller?
« Reply #17 on: June 11, 2013, 02:57:51 am »
Yep, I think you can get the same affect by building your own.  Just knowing what it is called can help you find more information on the web regarding pitfalls and whatnot.

You might also look into photo FETs.  It seems like I remember them working great on small signals.  They should be bi-directional as well.

Here's a datasheet for one.  "Automatic gain control" is one of the listed applications.
« Last Edit: June 11, 2013, 03:03:50 am by TerminalJack505 »
 

Offline DoubleM

  • Contributor
  • Posts: 9
Re: How to set OpAmp gain using microcontroller?
« Reply #18 on: June 11, 2013, 03:10:29 am »
Yep, I think you can get the same affect by building your own.  Just knowing what it is called can help you find more information on the web regarding pitfalls and whatnot.

You might also look into photo FETs.  It seems like I remember them working great on small signals.  They should be bi-directional as well.

Here's a datasheet for one.  "Automatic gain control" is one of the listed applications.

Yep, that's exactly what i need   ;)
 

Offline mikes

  • Regular Contributor
  • *
  • Posts: 101
  • Country: us
Re: How to set OpAmp gain using microcontroller?
« Reply #19 on: June 11, 2013, 10:29:43 am »
I thought CdS sensors were basically gone in EU, due to RoHS.
 

Offline miceuz

  • Frequent Contributor
  • **
  • Posts: 374
  • Country: lt
    • chirp - a soil moisture meter / plant watering alarm
Re: How to set OpAmp gain using microcontroller?
« Reply #20 on: June 11, 2013, 05:53:01 pm »
yeah, most of the wah guitar pedals use led/photoresistor solution - it does not wear and just works, refitted one pedal to use for potting throw-wheel myself.

Online kripton2035

  • Super Contributor
  • ***
  • Posts: 1901
  • Country: fr
    • kripton2035 schematics repository
Re: How to set OpAmp gain using microcontroller?
« Reply #21 on: June 11, 2013, 06:32:55 pm »
you can also use a cypress psoc (1 is enought) and you have the controller AND the opamp (s) in the same package...

Offline knik

  • Contributor
  • Posts: 6
  • Country: pl
Re: How to set OpAmp gain using microcontroller?
« Reply #22 on: June 12, 2013, 11:05:03 am »
You can use 4051 multiplexer with 8 different feedback resistors and you will have 8 different gain settings.
Or you can use 4051 with R-2R attenuator.
 

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 243
  • Country: nl
Re: How to set OpAmp gain using microcontroller?
« Reply #23 on: June 12, 2013, 12:08:15 pm »
If you choose to go with a digital potentiometer there is one important thing to keep in mind. That is it's internal wiper resistance.
Due to it's internal construction a digital potmeter is basically a switched resistor network. The selector that chooses the resistor according to wiper position has an internal resistance that could be around 70 ohms. So 10 mA of current through the potmeter (wiper) results in an 700 mV drop across the resistor. (just read about this in 'Mastering the I2C bus', and this thread came to mind)

So if used in the feedback path of your opamp you really need to keep this in mind.
 

Offline poorchava

  • Super Contributor
  • ***
  • Posts: 1575
  • Country: pl
  • Troll Cave Electronics!
Re: How to set OpAmp gain using microcontroller?
« Reply #24 on: June 13, 2013, 06:05:46 am »
led+photoresistor approach is not that good, unless you can accept closed feedback loop and very slow settling time. Photoresistors are not linear, so you would have to build some sort of regulator measuring output signal from the amp and adjusting the LED current. This will be very slow, because photoresistors have rather high time constants.

You could use something like this: http://www.tme.eu/en/details/vtl5c10/tht-optocouplers-transistor-output/perkin-elmer/# but that kind of stuff tends to be rather expensive. For volume setting I would use digital potentiometer, as you can find many dedicated solutions. For anything of higher frequency range variable gain amplifiers are the only way to go.
I love the smell of FR4 in the morning!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf