Please help solve ramp for op amps! - Page 1
Forum section: electronics / beginners

author: ilbs
author_rank: Contributor
timestamp: October 02, 2013, 11:25:20 pm
content: Hello,I have been trying to get an op amp to do the following ramp:(V1) Input: must be 5Vdc!(V2) Input: 9 to 12Vdc(Vout) Output: 3.5 to 6.3Vdcra = 10K ohmsWith all desperation, I have been trying to calculate resistors r1, r2 and rf for a few days now and it seems that I am not able to do it.To the point that I think this is not doable!If someone knows the maths on how to calculate this, please get back. I am not looking for a quick answer (or circuit) calculated by some op amp calculator!I am looking for the mathematical breakdown to this solution please.And since typical op amp equations such as the "differential equation" or super position equations don't solve for this... I have adventured myself with in experimental in house maths without success.I have attempted taking the vout/vin ratio which is:A=(6.3-3.5)/(12-9) = 0.933Using this ratio, I tried the math around op amps to get the correct ramp without success! I have given up!Can someone please provide some insight on this thanks!

author: c4757p
author_rank: Super Contributor
timestamp: October 02, 2013, 11:27:52 pm
content: Ohm's Law!!!!!!!!!!!!!!!!!!!The whole thing can be solved with Ohm's Law and a relatively simple system of equations... write out an Ohm's Law equation for each resistor, then solve them together as a system.

author: ilbs
author_rank: Contributor
timestamp: October 02, 2013, 11:29:01 pm
content: Hi, Can you show me how please!

author: c4757p
author_rank: Super Contributor
timestamp: October 02, 2013, 11:30:28 pm
content: I'm not going to do it for you, but I can steer you in the right direction. What do you know? Do you know enough algebra to work out a system of equations? Do you know what Ohm's Law is?The other hint, if you haven't gotten this: an op amp, when not saturated, will "attempt" to keep its inputs equal. So write an equation for each input, then set them equal to each other, then solve for values.You're not going to get individual values for all three resistors. You'll want to pick two of them and solve for the other two. Alternately, if you find theratioof the resistors, there are a few calculators online which can select a pair of standard values which meet that ratio.

author: ilbs
author_rank: Contributor
timestamp: October 02, 2013, 11:39:37 pm
content: Hi,I am not that much mathematically inclined. Sorry! But if I see an example I will then know how to do the rest of my ramps!Yes I know ohms law... but its coming up with the equations that I have trouble!QuoteyesQuoteI always have trouble doing that....thank you for replying!

author: c4757p
author_rank: Super Contributor
timestamp: October 02, 2013, 11:44:24 pm
content: OK, see if this gets you started.Ohm's Law, as you know, states thatV, the voltage across a resistor, is equal toI, the current through it, multiplied byR, its resistance. So for each resistor, figure out the voltage you want to appear across it at a hypothetical point of operation. Then rearrange, and you have an equation for the current through the resistor.Assuming the op amp's inputs don't take any current themselves, the current through two resistors in series will be equal, so you can set those two currents equal to each other and thus combine two equations.You'll need two hypothetical operating points to get a solvable set of equations.If nobody beats me to it, I'll work through asimilarproblem (but not the same!!) so you can follow along. But I want to eat dinner firstAlso, to beat the peanut gallery to the point, yep, there are other ways to do this. Some require fewer equations. But I'd rather have a simple set of equations that you can be handy with than memorize one for every imaginable situation.

author: ilbs
author_rank: Contributor
timestamp: October 02, 2013, 11:53:25 pm
content: c4757p,Are you sure its that simple, because don't forget, there's a ramp that needs to be taken into considerationAnyways, I will wait for your solution as I am very curiousthanks

author: c4757p
author_rank: Super Contributor
timestamp: October 02, 2013, 11:54:52 pm
content: Positive. (Punmaybeintended.)

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 12:39:22 am
content: OK. I actually did it differently. I figure this way is more intuitive, and works for pretty much any op amp scaling application.Note that no matter what funny business you have going on with voltage shifts and such, the op amp can't see "ground". So you pick a point to call "ground" that makes the problem look conveniently like a simple amplifier with gain, and there is always one.Here, I'm inversely scaling voltages, 1 to 5V scaled onto 10 to 7V, using the inverting topology. First, I compute the gain of the amplifier, then I pick the ground point, then I pick resistors to give those.WARNING!!!I got R1 and R2 backwards, at the very end. It should be R1 = 100k, R2 = 75k, R2 = 3/4 R1. Everything else is correct and has been verified as such.

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 12:45:46 am
content: And LTspice likes it! (Can't be bothered to dig out the breadboard...)

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 03:20:16 am
content: Hi c4757p,You are talking to a veeeeeery slow guy here.... more than you can imagine!!!Okay, so, I fully understand your calculations when we have the input signal ramp at the inverting input. Your calculations make sense and there is other ways to get the same result.... such as shown at "rampAlt" attachment below.But that's not my problem.... The problem I have is when we put the ramping signal at the non-inverting input and provide the constant voltage at the inverting input...See second attachment below "oddRamp2" where I tried to do your example by following your directives but this time 1 to 5 volts is at the non-inverting input and the constant voltage of 15Vdc is at the inverting input. Somehow, I get lost just about here!This is why I asked about that *specific* example !!!!Anyways, I don't have LTSpice... perhaps I should get it..... wonder if its expensiveIf you can do me a favor... and see if your calculations actually work with my specific example... it would clarify my confusion!Thank you very much for your help!

author: Andy Watson
author_rank: Super Contributor
timestamp: October 03, 2013, 09:31:48 am
content: I think c4757p's intuitive approach is the right one, attempting to solve one huge equation can hide the action of the circuit. Try this: Calculate what V2 should be to give 5V at the output. 5V was not an arbitrary choice, it will enable you to specify (assuming an ideal op-amp) the voltages at all the nodes in the circuit. Now you can find the ratio of R1:R2.

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 01:29:10 pm
content: Dammit, I forgot about this thread... I'll be back in about two hours and I'll look over that.Quick glance: you are using the wrong equation for gain. It is different for a noninverting amplifier.

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 02:29:18 pm
content: This one is a bit harder. I'll get you started - if you're "not that much mathematically inclined" you might not see where to begin with this one. Here's what I did.Vin is being multiplied by Gain1 (this is the "gain" - less than one - from the R1/R2 voltage divider), then by Gain2 (the op amp gain) around a virtual ground.You already know Vgnd (it's 5V), so we can work backwards:(Vin Gain1 - Vgnd) Gain2 = (Vout - Vgnd)(9 Gain1 - 5) Gain2 = (3.5 - 5)9 Gain1 Gain2 - 5 Gain2 = -1.5There are multiple solutions to this problem! We know: Gain1 is between one and zero noninclusive (because it's a voltage divider!) and Gain2 is greater than one (because it's a noninverting op amp!). So pick one of them to be a number you like and solve for the other. (Hint: Not all combinations work! Remember those constraints - if you get an answer outside them, try again.)Best to find all the gains and shifts, then write an equation for them, then start banging on it!LTspice yet again approves of my solution! But I'm not showing you my values

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 02:34:53 pm
content: Quote from: ilbs on October 03, 2013, 03:20:16 amLess than a cup of bad coffee, food poisoning from Taco Bell, or a free puppy. And better than at least two of them.

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 03:33:51 pm
content: Don't understand!Thanks anyways

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 03:40:45 pm
content: Quote from: c4757p on October 03, 2013, 02:29:18 pmThe first thing I said to do after this point was to choose a number for one of the gains, within the specified limits. Pick a few! What are your choices?As far as the equation I started with, I just wrote a description of the relationship between input and output:First Vin is multiplied by the gain of the voltage divider:Vin Gain1Then, the op amp sees it as being relative to the virtual ground:Vin Gain1 - VgndThis is then multiplied by the gain of the op amp:(Vin Gain1 - Vgnd) Gain2To give the output voltage, again relative to the virtual ground:(Vin Gain1 - Vgnd) Gain2 = Vout - Vgnd

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 04:09:19 pm
content: QuoteGood explanation.... I at least now I know where you are coming from.... Thanks you for thisQuoteIn reference to attachment.... so I picked 0.5 as Gain1, this solves for Gain2 as the gain of the amplifier which is -0.375... I assigned it to the rf/ra resistor gain and this didn't work!!!So, now what... I have to pick another value other than 0.5 and re-try again ?

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 04:11:40 pm
content: This was exactly my first step. Instead of different numbers, try changing your method a bit - pick a Gain2.Be careful with your math there - somehow you picked a value for RF even though Gain2 was negative! That should not be possible. This is a non-inverting amplifier, the gain is positive by definition.

author: Sigmoid
author_rank: Frequent Contributor
timestamp: October 03, 2013, 04:18:51 pm
content: If you have trouble with algebra, you'll suffer a lot with electronics.Really, try to bring yourself up to speed. It's not avoidable.As for op-amps, the model that finally really made me understand them is the following:G is the open loop gain, expect it to be something gigantic.As you see, Vout of the amp is(Vin+ - Vin-) * G.Now, if you feed that back into Vin-, you have a control loop! And everything you learned about control theory comes to life.Of course if you haven't learned control theory, it's prime time - after you've mastered basic algebra.

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 04:38:36 pm
content: Boff !!!Picked a Gain2 as 2.... still doesn't work for me!see attachment!

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 04:44:29 pm
content: You calculated RF wrong! Remember -noninverting amplifier. Different equations.Your gains are right, though.

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 06:00:31 pm
content: gain for non inverting is:(r2/(r1+r2))(1+rf/ra)(0.472222)(1+2)1.41666if I make rf 1.4166 of ra, this still doesn't work ...and if I take the difference of the gains:(2-0.4722) = 1.527777 and use this in the gain for non-inverting input like this:(4722/10K)(1+1.52777)1.1936an rf/ra gain of 1.1936 is close but not precise at all... which means it still doesn't work!Not sure if this is the way to do it !confused

author: Galaxyrise
author_rank: Frequent Contributor
timestamp: October 03, 2013, 06:13:58 pm
content: Try not to think of opamps in terms of set equations for gain and what-not. opamps raise their output voltage when the voltage at the inverting input is lower than the voltage at the non-inverting input, and they lower their output voltage when the voltage at the inverting input is higher than the voltage at the non-inverting input. That's it, really, and everything else follows from that.

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 06:35:08 pm
content: It's only that simple if you find algebra intuitive. Sometimes it can be approximated as a fixed-gain system just fine.I'll look more later.

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 07:17:35 pm
content: I think it has more to do with:vout=V2(gainNon-inv) + V1(gainInv)I will also look more .... but tomorrow

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 08:21:30 pm
content: Quote from: ilbs on October 03, 2013, 06:00:31 pm...the hell'd you get that from? Fix that equation and your problem is solved...

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 09:28:41 pm
content: don't know how... that's why I'm here....

author: c4757p
author_rank: Super Contributor
timestamp: October 03, 2013, 09:31:11 pm
content: Just Google "noninverting amplifier"! Then click through to the almighty Wikipedia, where you see this:Try your math again with that. Your R1 and R2 have nothing to do with Gain2, the amplifier gain - they only affect Gain1, the attenuator gain.

author: ilbs
author_rank: Contributor
timestamp: October 03, 2013, 09:56:24 pm
content: try my math again with what???you said my gains are right!and you said rf is badly calculated!so if it has nothing to do with gain 2, so thenit has to do with gain1 which is0.4722222 so is it:V2(1+0.472222)9(1.47222)13.24so what does 13.24 have to do with this....look.... I'm am obviously trying here...I am not being lazy!!! I just don't getthis stuff the way you are trying toexplain this.Does anyone have any detailedhelp on this please....thank you

author: c4757p
author_rank: Super Contributor
timestamp: October 04, 2013, 03:03:53 am
content: Gain2 = 1 + RF/RaYour R1/R2 are correct. Though you might want to try picking values closer to standard ones.

author: ilbs
author_rank: Contributor
timestamp: October 04, 2013, 03:49:16 am
content: if gain2 = 2and if you are saying that gain2 is:(1+rf/ra)thenra should = 10kandrf should also = 10Ktherefore:if r2 = 4722, then va should = 4.24999998and therefore vb should also = 4.24999998which works out to:Vra and vrf = 0.75000V and therefore:5-0.75000-0.75000 = 3.5vdcIs this correct.... I am not at the labso I can only test this tomorrow

author: c4757p
author_rank: Super Contributor
timestamp: October 04, 2013, 03:52:13 am
content: If I remember correctly, yes. I didn't save my data, but it looks good.

author: ilbs
author_rank: Contributor
timestamp: October 04, 2013, 03:54:40 pm
content: One last question,concerning:QuoteWhy are we presuming that Vgnd is 5Vdc, is it because we know the inverting input is 5V??Because I tried setting Vgnd to 6 Vdc and that didn't work anymore

author: c4757p
author_rank: Super Contributor
timestamp: October 04, 2013, 04:03:30 pm
content: The inverting input is the virtual ground. Note that in the usual noninverting arrangement, that point would go torealground, not a voltage input.

author: ilbs
author_rank: Contributor
timestamp: October 04, 2013, 04:37:56 pm
content: c4757p,While we are in a lengthy thread, I may as well ask. I have no trouble with algebra, I have done up to college math including calculus. But my usual problemis defining the equations. Like many (I'm sure) coming up with the equations can be real tough.How do you guys come up with these equations.... I mean there must be some sort of a rationalization for one to come up with:(Vin x G1 - Vgnd)(G1) = Vo-VgndIn the grand scheme of things (and correct me if I am wrong) the above formula is an intention to make a point in the circuit equal to another point inthe circuit while knowing that these two points MUST be equal, right?In other words, I am sure there are other solutions ... but I don't see any other... I think this one would be wrong:(Vin x G1 - Vgnd)(G1) = V1-Vgndare there any other equations we could of written for this?

author: c4757p
author_rank: Super Contributor
timestamp: October 04, 2013, 05:00:11 pm
content: Quote from: ilbs on October 04, 2013, 04:37:56 pmThat's a common position to end up in. It often takes some experience and intuition to know.QuoteYep, you got it!It's just a description, in "algebra language", of what I expect to see at a bunch of points in the circuit. The piece-by-piece explanation that I gave a couple posts ago was pretty much exactly my thought process when I wrote it.QuotePlenty! You could have gone the pure Ohm's Law route which I originally (foolishly) suggested - I forgot, with that many resistors it often ends up a bit complicated. You'd end up with a system of multiple equations, which I'd probably just toss into MATLAB for a solution

author: ilbs
author_rank: Contributor
timestamp: October 04, 2013, 05:04:04 pm
content: c4757p,I learned a lot in this threadThanks for your help