Need help with an op-amp circuit

You would think there’s plenty of material for this on the web, but surprisingly I can’t find what I need. And AI has been uniformly awful.

I have what I think is a simple problem: a 0v to 3.3v input that I want to scale/bias to -5v to +5v. Supply is +/- 9v. The op-amp I have handy is the OPA134. I know I just need to set up some resistor network and figure out the values.

The one seemingly useful calculator I found was this one:

And this page in particular:

But… the case 2 calculator doesn’t work! All the others do. And the math is pretty hairy with that R1||R2 in there. Ugh. Do I really have to come up with my own solver?

Ok. I know how op-amps work, mostly. I can have a circuit that ties the inverting input to each of Vin, Vref (+/- 9v), and Vout with a resistor each, and the non-inverting input to ground. Set one of them to 10k or something and solve for the others. They have to satisfy:
Vin/R1 + Vref/R2 + Vout/Rf = 0

…since the currents must sum to zero and the voltage is also zero. I’ll just solve for Vin=0/Vout=-5 and Vin=3.3/Vout=5.

Except… it’s unsolvable. One of the other resistances has to be negative. And I don’t want to complicate the circuit with a negative resistance.

I guess I need four resistors. Probably in the topology in the case 2 diagram above? Or am I missing something and three resistors would work? And is there a solver out there that will handle gain and bias?

That calculator page does not work for me. Have you tried, e.g. on a breadboard, a basic difference amplifier circuit like

The gain here is supposed to be R_\mathrm{f}/R_\mathrm{i}, and you want a gain of 3, e.g. maybe R_i could be 10k and R_f 30k? (Or vice versa…)

If noise is a problem, you can always create a better circuit.

There are indeed four resistors there. Is that a problem?

A lot of useful ideas in The Art of Electronics, Section 5.14.

It’s been a long time since I touched an op-amp, but I’m good at math.

Looking at the equations on that broken calculator page, I notice that they’re equivalent to

b = V_\text{ref} \left( \frac{R_2}{R_1 + R_2} \right) (m - 1).

For the parameters you want, you have m = 3.0303.. and b = 5\text{ V}. This implies that R_2/(R_1 + R_2) \approx 0.2736 for V_\text{ref} = 9 \text{ V}, or R_1/R_2 \approx 2.655.

So if I wanted to find a solution, I would first find a pair of resistors out of the resistor series I’m using that approximated this ratio; then figure out what R_1 \parallel R_2 is (I assume this is the parallel combination of R_1 and R_2); and then determine R_f and R_g from that. It will also help to note you must have

R_1 \parallel R_2 = R_1 \left( \frac{R_2}{R_1 + R_2} \right) = 0.2736 R_1

given the above constraint.

If you’re using E24 resistors, R_1 = 4.3 and R_2 = 1.6 (in whatever decade of resistance is appropriate) hits that ratio within 2%, which is well within the tolerance of E24 resistors. You then have R_1 \parallel R_2 = 1.17, which simplifies your life when you go to calculate R_f and R_g from the equation for m.

Another schematic of a classic 4-resistor amplifier (perhaps this link will actually appear?)
https://www.analog.com/en/resources/analog-dialogue/articles/deeper-look-into-difference-amplifiers.html

Assuming you want to use the positive supply to provide the offset:

Input to non-inverting input of opamp.
Pick feedback resistor Rf from output to inverting input.
Resistor R1=1.8Rf from positive supply to inverting input.
Resistor R2=0.68Rf from inverting input to ground.

This gives non-inverting gain (1 + Rf/(R1||R2)) = 3.03 so 0 to 3.3V maps to 0 to 10V
This gives offset of -Vsupply(Rf/R1) = -5V to set ouput range from -5V to +5V

No, I just thought that three resistors supports two ratios, and I have two unknowns to solve for, so it might work. And it would, except that for some reason Digikey doesn’t stock negative resistors.

Oh! That’s a very good observation. Makes the solution trivial in fact. That entire term is constant.

Either side is suitable. But wait: that’s a three-resistor solution. Different topology than I first tried, though. And just E12 series resistors, to boot. I’ll give this a try.

Thanks, all!

I also took a stab at it. Final circuit is on Page 4. Let me know if it works.

Imgur

Imgur

Imgur

Imgur

As can be seen, I am getting 2.463 V from 3.3 V using a voltage divider. But you can use a voltage other than 3.3 V. You’ll have to change the resistor values, of course. Whatever you use, just make sure it is very stable. For the best stability, use a voltage reference chip.

Thanks! I’ll read that in more detail later.

I did try @Marvin_the_Martian’s circuit, which mostly worked. The only problem is that it’s pretty sensitive to resistor values–with the 5% ones I had on hand, the final range ended up being something like -3.6v to 4.0v, which is pretty far from -5v to 5v. Some of this is inevitable (and I’ll probably just check my stock for ones closer to the center) but I wonder if a different topology would make it less sensitive. I could also stick a trim pot or two in there somewhere…

1% MF resistors are very cheap nowadays. Heck, even 0.1% ones are fairly cheap. For less than $8, you can use 0.1% MF resistors in the circuit I provided:

R1
Mouser Part Number: 279-YR1B768RCC
Resistance = 768 Ω
Power rating = 0.25 W
Tolerance = ±0.1%
Price: $1.04

R2
Mouser Part Number: 279-YR1B2K26CC
Resistance = 2260 Ω
Power rating = 0.25 W
Tolerance = ±0.1%
Price: $0.82

RG1
Mouser Part Number: 71-RN60C8200BRE6
Resistance = 820 Ω
Power rating = 0.25 W
Tolerance = ±0.1%
Price: $1.74

RG2
Mouser Part Number: 756-RC55D-510RBI
Resistance = 510 Ω
Power rating = 0.25 W
Tolerance = ±0.1%
Price: $2.68

RF
Mouser Part Number: 71-RN60C2701B
Resistance = 2700 Ω
Power rating = 0.25 W
Tolerance = ±0.1%
Price: $1.47

As I’m sure you’re aware, trim pots suck. :slight_smile: Only to be used as a last resort.

They might be cheap, but they aren’t in my parts bin :slight_smile: . But yeah, I’ll probably throw those into the order when I actually make the thing. Currently I’m just experimenting. I can find a “lucky” resistor in my stock or trim it with a high-value one for now.

That’s way too much gain error (24%) to be accounted for by 5% resistor tolerances. I’d expect a 10% error if you are unlucky. What are the actual values you are using?

Gonna check that later tonight. Agreed that the error seems like a bit much. I only checked them enough to ensure I had the 1.8k, 1k, and 0.68k resistors in the right spots.

I did repeat the math to verify that it works as you’d expect. I’ll repeat that with the actual values to see if there’s a discrepancy. The supply isn’t exactly 9v either, it’s maybe 9.3v, though I wouldn’t expect that to end up as a huge difference either.

9.3V vs 9V on the positive supply will make the output about 167mV more negative. The problem with using the supply as an input to the amplifier is that the power supply rejection is very poor - any variation or noise on the supply will show up directly in the output. For any critical application a more stable reference voltage would be used.

What are you driving the input with?

Haven’t fully decided on the input yet, but probably a PWM from an ESP32 sent through a filter of some kind. For testing, I’m just tying the input to ground or ~3.3v with another resistor network (dividing 5v via 100 ohm and 51 ohm resistors). Seems like there should be negligible error in either case.

Eh, scratch that. Gonna need a proper DAC. MCP4922 or the like.

Ok, after quadruple-checking everything and hoooking up my o-scope to compare against my multimeter, finding nothing… I discovered the problem. I thought a 100 ohm load would be fine. But the short-circuit current for the OPA134 is only 36 mA, and 5v/100ohm = 50 mA :person_facepalming: .

Time to order some parts, at any rate. And I’m thinking it might be time to hit up OSHPark again, now that I’ll probably be tariffed at JLCPCB. Ah, well. They’re higher quality boards and made in the US. Can’t complain too much.

That would do it. I assume you removed the load and all was fine?

Yep. And it seems to drive the final load just fine as well (it has its own servo amplifier). Thanks again for the simple design!

Glad I remembered something about op-amps, in any case. The inverting and non-inverting inputs should be the same voltage, not 500 mV from each other. Yeah, that’s bad.

Any suggestions about maximizing performance? Noise is of fairly little concern. I’ll be changing the output at about 30 kHz but I want the transitions to be as sharp as possible. So I think I want >1 MHz of actual bandwidth. Gain is pretty low at 3x, which implies a GBW of 3 MHz… not particularly high in op-amp terms. Need to check on slew rate as well but I’m not going to be doing full -5v..5v swings at 30 kHz.

I’m sorry I can’t help you with your problem, but this thread title brought back memories. Opamp was the name of a technical bookstore that used to be in Hollywood, California. I don’t know when they closed but they’d been in business for decades and carried books on anything and everything to do with electronics, computers, programming and so on.

Since I come from a software background I didn’t know that the name was supposed to be read as Op-Amp, so I could help imagining the name as “O-Pamp”.