SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By 8Volts
#164115
Hello,

I am so discouraged with these op amps...
In spite of all the equations I know, I have been trying for days to get an op amp to do the following ramp:

(V1) Input: must be a constant 5Vdc!
(V2) Input: 9 to 12Vdc
(Vout) Output: 3.5 to 6.3Vdc
ra = 10K ohms

With all desperation, I have been trying to calculate resistors r1, r2 and rf and it seems that I am not able to do it.

Internet articles only show equations on how to calculate Vout, but in reality, many times, we know Vin and Vout and need to solve for the *resistors*. And often we need the op amp to do ramps too. I don't get why there is no such simplified examples around the Internet or tutorials.

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 or LTSpice or other! I am looking for the mathematical breakdown to this solution! :neutral:

Thanks!
You do not have the required permissions to view the files attached to this post.
By waltr
#164116
Not sure if this really can be done but lets talk it through.

Ignoring V2 input (assume its at 0V for now).
If ra and rf are equal then the +5 on V1 becomes -5V on the output since this is the inverting input.

Now ignore V1 input (assume its at 0V).
The Voltage range input to output ratio is: (12-9)/(6.3 - 3.5) = 1.07. This is the Gain required on the non-invert leg which is: 1 + rf/ra.
BUT, you need an offset. Calculate the center Voltage of the input range and the center Voltage of the output range. These are: 10.5V in, 4.9V out. This means you need to offset the output by -5.6V.

Now we can go back to the V1 input and calculate the gain needed for a -5.6V output which is: -5.6/5.0 = -1.12 (minus means inverting). So this is the ratio of rf/ra.

Lets see if this helps and where you can take this for now.
By 8Volts
#164119
it works only for the 9Vdc, but when we ramp V2 to 12.Vdc, we get approximately 6.5Vdc instead of 6.3Vdc 8)
Now we can go back to the V1 input and calculate the gain needed for a -5.6V output which is: -5.6/5.0 = -1.12 (minus means inverting). So this is the ratio of rf/ra.
I can't thank you enough waltr

PS... wondering ... does this work with any non-inverting ramp input/output signal ??? I guess I will try a few different examples... and I will let you know.

Sincere thanks
You do not have the required permissions to view the files attached to this post.
Last edited by 8Volts on Tue Oct 22, 2013 10:09 am, edited 2 times in total.
By Mee_n_Mac
#164122
8Volts wrote:I always thought the voltage range input to output was the gain and is typically calculated as:
(6.3 - 3.5)/(12-9) = 2/3 or 0.66666666

Can you imagine ... I was off with this from the start.... oooffff :shock:
The gain is the change in output / the change in input, that's 2.8/3.
Your values are a bit off.

You've already seen this expression for the gains, Vo/V1 and Vo/V2. The rest is basic algebra.

VOUT = [R2/(R1+R2)] [(Rf + Ra)/Ra] V2 - [Rf/Ra] V1 ; Ra = 10k

Rewrite that as ;

VOUT = k2V2 - k1V1 to make it easy.

VOUT ranges from 3.5 - 6.3, a difference of 2.8 and only the V2 input changes. It goes from 9 - 12, a difference of 3. Recall the definition of gain is the change in output / the change in input. By definition the gain in the V2 path (k2) must be 2.8/3 = 0.93333333333333333333333333333333.

So let's find k1 now.

VOUT = k2V2 - k1V1
3.5 = 9*k2 - k1V1 or re-arranging ...
k1 = (9*k2 - 3.5)/V1 with V1 = 5

So k1 = 0.98

Now find the resistor values.

k1 = Rf/Ra and Ra = 10k so ...
Rf = 9.8k or the closest value to it.

Now find R1 and R2;
[R2/(R1+R2)] [(Rf + Ra)/Ra] = k2 = [R2/(R1+R2)] [k1 + 1]
[R2/(R1+R2)] = k2/[k1 + 1] = 0.47138047138047138047138047138047

So we have choices we can make for R1 and R2 and have the gain be the same number. Let's choose R2 = 20k
That makes R1 = 22.43k or as close as you can get.

As a final check stick all the values into the top equation and see if VOUT is correct when V1 = 5v and V2 = 12v.
By waltr
#164132
The Voltage range input to output ratio is: (12-9)/(6.3 - 3.5) = 1.07.
Yep, I got this part backwards as Mee_n_Mac pointed out. It should state:
The Voltage range output to input ratio is: (6.3 - 3.5) / (12-9) = 0.9333. Close but not correct.

I tried just thinking through the problem and presenting a way to look at this. Great you picked it up from there.
By Mee_n_Mac
#164135
What's interesting is that there's no practical difference btw the two solutions. One path gain being a tad high is made up by the other path being a bit low.
By UhClem
#164140
Once upon a time long ago and not too far away, I had an EE course on Analog filters. The text was Analog Filter Design by M.E. Van Valkenburg.

It starts with a discussion of opamps and simple models. The simplest is a dependent voltage source: v = A(v+ - v-) where A goes to infinity.

But that isn't really required here. All you need are two features of an opamp with negative feedback:

1) Virtual open: the input currents at the opamp are zero. (close, anyway)
2) Virtual short: the voltage at the inverting and non-inverting inputs is equal.

(v+ and v- are the voltages at the noninverting and inverting inputs of
the opamp)

(v1 - v-)/Ra = (v- - Vout)/Rf

v+ = v2 * r2/(R1 +R2)

But v+ = v- (virtual short) so

Vout = (V2-V1)*(Rf/Ra)*(Ra/Rf + 1)/(R1/R2 +1)

You have fixed:

V1 = 5V
Ra = 10K

In addition you seem to require:

V2 = 9V -- Vout = 3.5V
V2 = 12V -- Vout = 6.3V

That gives you two equations but you still have three unknown resistor values so also set

R2 = 10K

Plug all those numbers into the equation and solve for Rf and R1.
By 8Volts
#164178
Hello Mee_n_Mac, I apologize for the delay for this reply!

I am slowly getting around to the multitude
of ways these problems can be solved!

Okay!, I fully understand your solution as you first solved for the gain at v2 branch, and then with:

Vout=K2V2-K1V1

you solved for K1 which allowed us to pick resistors to satisfy that ratio (gain of rf/ra) for the inverting leg. Then with this you figured out r1 and r2 with:

K2/[K1+1]

which gave us the ratio of what r1 is to r2. Okay, I get this :mrgreen: I am not an expert... but I definitely get it :D

*BUT*

I can't understand why we can't use the same problem
solving scheme for a configuration without ramps!
Consider the following:

Suppose, we have the same configuration, but this time, there is no ramps. Is there a way of starting off our calculations by solving for K2 and then solving for the K1 branch as you did for the initial sample with the ramps. Please see attachment as my attempt failed. As you can see, in the attachment, the attempt failed since K1 would be 0... and that can't be right!!!

I was able to do it starting from the k1 branch instead (not shown in attachment), which worked out by simply doing:
k1=3.5/5 = 0.7, and assigning the proper resistors to satisfy this ratio which gave, 10K for ra and 7K for rf. I was then able to solve for Vra and with this, I was able to transpose the voltage at the other input and solving for Vr2 and figure out the r1 and r2 resistors by Vr2/9 and satisfying this ratio. This way is fine and I get it... but as I mentioned above, is there a way to solve this by figuring out the K2 branch *FIRST* and then solving for the K1 branch just as you did for the original circuit at the top
of this thread?

Thanks all for your help!
You do not have the required permissions to view the files attached to this post.
By Mee_n_Mac
#164189
8Volts wrote:Suppose, we have the same configuration, but this time, there Vout =3.5is no ramps. Is there a way of starting off our calculations by solving for K2 and then solving for the K1 branch as you did for the initial sample with the ramps. Please see attachment as my attempt failed. As you can see, in the attachment, the attempt failed since K1 would be 0... and that can't be right!!!
By 'no ramps' do you mean that V2 doesn't vary from 9 - 12 v ? If so then there's no single unique solution. You can choose the resistor values to make the gains for the V1 and V2 paths be almost whatever you want so long as they compliment each other. For example if V1 = 5, V2 = 9 and Vout = 3.5 ;
VOUT = k2V2 - k1V1 ;
then k1 could 1 so long as k2 = 0.944. Choose the resistors accordingly.

Or make k1 = 3.3 and set k2 = 2.2222. Choose the resistors accordingly.

See what I mean.
By 8Volts
#164374
Hello,

I have one last question for wltr...

Please view Attachment... In the hopes that my calculations are not a fluke, I seem to be able to calculate the correct ratio for r1 and r2 by using the same method you proposed for the non inverting circuit at the top of this thread! Can you confirm that your method can also be used when the ramp is at the inverting side instead of the non-inverting side. Just curious!

Thanks
You do not have the required permissions to view the files attached to this post.
By 8Volts
#164649
Hello again gentlemen,

I have understood all the methods of calculating op amp ramps as discussed in this thread. However, I would like to ask one last question to Waltr. Waltr I sincerely apologize for bringing back this post, I really feel awful for this, but there is a particular case where your method doesn't work. I would like to be clear about this, where I know its most probably my fault again for being so slow and inexperienced with electronics, so please bear with me this last time :mrgreen: :mrgreen:

In the attachments below I have a peculiar case were the voltage of input ramp starts, is the same as the output ramping start voltage :doh: :doh:

I tested other methods of calculating all the resistors and they confirm successfully using the differential equation! However, when we follow along the method you have proposed, I only seem to be able to confirm successfully that the resistor values are correct only when V1 is 6Vdc and the output is 1.0Vdc. When I try to use the differential equation when V1 is 3.0Vdc and Vout is 3.0Vdc, the equation fails to the expected result of 3.0Vdc :doh: :doh:

I am currently making a personal tutorial about op amps so I can personally reference this theory. I have now come down to finaly documenting the last method (Your method) which I do find as interesting as the other ones. If you can please take a quick look at my work in the 3 attachments below and see why the first differential equation doesn't work :?: :?:

I have tried all day to documented this anomaly, but I really don't know how. :doh: :doh:
I think that this method works only if we have a ramp on the non-inverting input (as the initial example in this post). But
if the ramp is on the Inverting input, vo/vin is already known and so is the gain (rf/ra)! :think:

What do you think? Your help is sincerely appreciated.
Again thank you for your time!
You do not have the required permissions to view the files attached to this post.
Last edited by 8Volts on Sun Oct 20, 2013 3:05 pm, edited 3 times in total.