How to set OpAmp gain using microcontroller? - Page 1
Forum section: electronics / general

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 12:34:30 am
content: 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!

author: nctnico
author_rank: Super Contributor
timestamp: June 11, 2013, 01:20:08 am
content: 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.

author: c4757p
author_rank: Super Contributor
timestamp: June 11, 2013, 01:24:29 am
content: 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 alotof time and board space on a discrete analog circuit.

author: c4757p
author_rank: Super Contributor
timestamp: June 11, 2013, 01:29:14 am
content: For even better simplicity - are you sure you can't just use a pot?

author: David_AVD
author_rank: Super Contributor
timestamp: June 11, 2013, 01:38:41 am
content: 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.

author: Paul Price
author_rank: Super Contributor
timestamp: June 11, 2013, 01:47:36 am
content: 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.

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 02:13:52 am
content: Quote from: c4757p on June 11, 2013, 01:29:14 amThat's the main issue here... If i could, i wouldn't be asking this silly questionQuote from: David_AVD on June 11, 2013, 01:38:41 amThis 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...

author: c4757p
author_rank: Super Contributor
timestamp: June 11, 2013, 02:16:33 am
content: Quote from: DoubleM on June 11, 2013, 02:13:52 amShifting the signal isn't a mess, it's a perfectly valid solution.QuoteWhat about the LED/photoresistor? I rather like that, actually...

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 02:23:52 am
content: Quote from: Paul Price on June 11, 2013, 01:47:36 amVery creative thinking thereLooks 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/5218For $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...

author: c4757p
author_rank: Super Contributor
timestamp: June 11, 2013, 02:25:01 am
content: Quote from: DoubleM on June 11, 2013, 02:23:52 amOn what planet? $6-$10?

author: c4757p
author_rank: Super Contributor
timestamp: June 11, 2013, 02:26:26 am
content: You're welcome.

author: Paul Price
author_rank: Super Contributor
timestamp: June 11, 2013, 02:27:47 am
content: You can 5 Photoresistors for < $4 U.S.

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 02:28:25 am
content: Quote from: c4757p on June 11, 2013, 02:25:01 amLook 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

author: c4757p
author_rank: Super Contributor
timestamp: June 11, 2013, 02:32:31 am
content: Yes.

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 02:37:56 am
content: Quote from: Paul Price on June 11, 2013, 02:27:47 amQuote from: c4757p on June 11, 2013, 02:26:26 amThanks 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 immediatelyQuote from: c4757p on June 11, 2013, 02:32:31 amOh, thank you! I'm ordering right nowThanks 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

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 11, 2013, 02:48:20 am
content: They actually have a name for the LED/CDS sensor combination. It's called aresistive 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.

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 02:56:19 am
content: Quote from: TerminalJack505 on June 11, 2013, 02:48:20 amInteresting, 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

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 11, 2013, 02:57:51 am
content: 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 datasheetfor one. "Automatic gain control" is one of the listed applications.

author: DoubleM
author_rank: Newbie
timestamp: June 11, 2013, 03:10:29 am
content: Quote from: TerminalJack505 on June 11, 2013, 02:57:51 amYep, that's exactly what i need

author: mikes
author_rank: Regular Contributor
timestamp: June 11, 2013, 10:29:43 am
content: I thought CdS sensors were basically gone in EU, due to RoHS.

author: miceuz
author_rank: Frequent Contributor
timestamp: June 11, 2013, 05:53:01 pm
content: 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.

author: kripton2035
author_rank: Super Contributor
timestamp: June 11, 2013, 06:32:55 pm
content: you can also use a cypress psoc (1 is enought) and you have the controller AND the opamp (s) in the same package...

author: knik
author_rank: Newbie
timestamp: June 12, 2013, 11:05:03 am
content: 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.

author: Christe4nM
author_rank: Unknown
timestamp: June 12, 2013, 12:08:15 pm
content: 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.

author: poorchava
author_rank: Super Contributor
timestamp: June 13, 2013, 06:05:46 am
content: 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.

author: envisionelec
author_rank: Frequent Contributor
timestamp: June 13, 2013, 11:54:19 am
content: A motorized pot?

author: David_AVD
author_rank: Super Contributor
timestamp: June 13, 2013, 10:52:57 pm
content: Quote from: envisionelec on June 13, 2013, 11:54:19 amLOL - that's so much smaller and easier than an e-pot!

author: mikes
author_rank: Regular Contributor
timestamp: June 14, 2013, 01:12:39 am
content: You can use a jfet as a voltage controlled resistor. Google "voltage controlled resistor jfet."

author: DoubleM
author_rank: Newbie
timestamp: June 14, 2013, 01:15:57 am
content: Thanks to all of you guys! I will try to use LED/CDS method, but will also order few different types of digipots, and experiment with them if my first attempt fail.Quote from: Christe4nM on June 12, 2013, 12:08:15 pmI'll keep that in mind... thanks.Quote from: poorchava on June 13, 2013, 06:05:46 amI know it's not linear, but I'm planning to measure that function (LED current / CDS resistance) and try to approximate it in software, in worst case i will capture 50 points, enter them in table and then do a linear interpolation on the output of the PIC. Also, it doesn't need to be very precise or consistent, it's just for audio volume control and if the volume drift +/-10% over the period of few hours due to temperature change, etc., nobody could notice that probably.I'm not really an expert, but I have a lot of confidence that this might work. If not, digipot is my second solution.

author: DoubleM
author_rank: Newbie
timestamp: June 14, 2013, 01:22:45 am
content: Quote from: mikes on June 14, 2013, 01:12:39 amWe already had this idea here on this thread, but the problem is that FET's are not bi-directional, like real resistors, and in the feedback loop of this OpAmp we have AC currents. Solution would be to shift the voltage up so that the whole signal is on the positive range (DC). This might not be a bad idea after all, I could try to experiment with it, while I'm waiting for my CDS sensors, so i have nothing to lose