Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

operational amplifier circuits etc.

Status
Not open for further replies.
What exactly are you talking about here? If you see a problem you must state what it is.

I didn't mean much. I was trying to say that to keep track of the details such as 10-bit ADC is being is used, the voltage output of current sensor IC, etc.

Yes, in general some gain can help because the circuit then takes better advantage of the ADC input range. Of course it also amplifies any error present in the sensor. If the gain is too high, it could also push the op amp output out of range.

4.7k might be ok, but you do have to check the op amp output at the plus and minus input extremes to make sure that it can actually get to those values.

So, gain can help. I need to design this circuit so that's why I wanted to confirm it.

I believe 4.7k would do better than 5.1k because this way the output won't go near the rail voltage. Note that we are dealing maximum current of 2.3A and in this circuit the value R3 was chosen to be 5k.

Moreover, don't you think that using a capacitor like this next to non-inverting input of the op-amp a good idea? A small value capacitor such as 22-33 pF would be okay.

If possible, please also have a look on this part from previous post which you didn't address in your last post.

This is a general query. If a single supply op-amp is power by +5V supply then the its lower rail voltage is ground. I mean to say that its output voltage cannot go negative.

NorthGuy: I hope you are following this discussing about the current sensor. I'm not able to find any other current sensor other than the given one. Using a shunt might be a better idea but in my view for someone like me who don't have any experience with designing real circuits this might pose a problem by making the circuit more messy and error prone. If you or anyone else have any better current sensor IC in mind then please let me know because it's possible that I might need to order some stuff from online dealer such as Digikey. Thanks.

Regards
PG
 

Attachments

  • sensor_cap.jpg
    sensor_cap.jpg
    38.5 KB · Views: 830
  • missed_part.jpg
    missed_part.jpg
    99.6 KB · Views: 621
I didn't mean much. I was trying to say that to keep track of the details such as 10-bit ADC is being is used, the voltage output of current sensor IC, etc.



So, gain can help. I need to design this circuit so that's why I wanted to confirm it.

I believe 4.7k would do better than 5.1k because this way the output won't go near the rail voltage. Note that we are dealing maximum current of 2.3A and in this circuit the value R3 was chosen to be 5k.

Moreover, don't you think that using a capacitor like this next to non-inverting input of the op-amp a good idea? A small value capacitor such as 22-33 pF would be okay.

If possible, please also have a look on this part from previous post which you didn't address in your last post.

This is a general query. If a single supply op-amp is power by +5V supply then the its lower rail voltage is ground. I mean to say that its output voltage cannot go negative.

NorthGuy: I hope you are following this discussing about the current sensor. I'm not able to find any other current sensor other than the given one. Using a shunt might be a better idea but in my view for someone like me who don't have any experience with designing real circuits this might pose a problem by making the circuit more messy and error prone. If you or anyone else have any better current sensor IC in mind then please let me know because it's possible that I might need to order some stuff from online dealer such as Digikey. Thanks.

Regards
PG

Hi PG,

I know you said 10 bit ADC. With my post i was pointing out that a 10 bit ADC looks like a 9 bit ADC if we only use half the range, no matter where that range is within the full input range of the ADC. Using only 1/4 of the range means it looks like an 8 bit ADC, etc. So we loose resolution if we dont use the whole range.
Amplification can get us back to a range that is closer to the full range, but we also must think about the error getting amplified too then. This may or may not be significant to the application.

It's questionable if a 33pf cap will do anything there, or if it is even needed at any value. The op amp has a filter cap so that might be enough. The idea with a cap in that position would be to get the two resistor network to have a time response similar to the sensor.

I did not 'miss' your question about the data set. I was trying to keep the questions down to a more manageable number per reply. It makes reading the questions easier and faster.

With your data set, i assume you are using the circuit with the amplifier, so what value of R3 are you using?
 
Thank you, MrAl.

Amplification can get us back to a range that is closer to the full range, but we also must think about the error getting amplified too then. This may or may not be significant to the application.

But what do you recommend? Using the current sensor without any amplification circuit gives small output and hence limited range of ADC is used. But with amplification, you say that error also get amplified.

It's questionable if a 33pf cap will do anything there, or if it is even needed at any value. The op amp has a filter cap so that might be enough. The idea with a cap in that position would be to get the two resistor network to have a time response similar to the sensor.

So, you don't recommend it?

I did not 'miss' your question about the data set. I was trying to keep the questions down to a more manageable number per reply. It makes reading the questions easier and faster.

With your data set, i assume you are using the circuit with the amplifier, so what value of R3 are you using?

And I didn't say that you missed it! :) I used this circuit where value of R3 was taken to be 5k.



Yes, you did miss the following query. This is a general query. If a single supply op-amp is power by +5V supply then the its lower rail voltage is ground. I mean to say that its output voltage cannot go negative. Thank you.

Regards
PG
 
Last edited:
Hi,

Using the amp is still better.

The decision to use a 33pf cap would have to be made after a few real world tests.

Lets concentrate on the calculations for now and come back to the others a little later.

In your data set, there appears to be a few errors. The -2.3 amp entry looks like it may be off by a few counts.
Also, some of the other entries look like they are rounded UP when they should be simply truncated. For example, if the analog output result is 417.8 the digital result should be 417, not 418.
This means you should go over your formulas for the sensor and op amp to determine what might be wrong, and also check your rounding method. The required rounding method is sometimes called "floor()", which is like just finding the integer value of a floating point number.

Just for reference, the two main formulas are:
1. Vout=0.185*I+2.5 (the sensor)
2. Vout=2.5*(R3/R1+1)-(Vin*R3)/R1 (the op amp) which with R3=5k and R1=1k becomes: Vout=15.0-5*Vin

To get the last output, Vout from the sensor becomes Vin of the amplifier.
To get the digital result, divide the last Vout by (5/1024) and then truncate to an integer.
Note there is a need for only one formula not two (the op amp formula with the sensor output formula substituted for Vin).

Im not sure how much of the work you wanted to do yourself so im not showing all the work yet :)
 
2. Vout=2.5*(R3/R1+1)-(Vin*R3)/R1 (the op amp) which with R3=5k and R1=1k becomes: Vout=15.0-5*Vin

It is easier to look at this formula that way:

(Vout - 2.5) = (Vin - 2.5)*R3/R1

Or, for both formulae combined:

(Vout - 2.5) = I*0.185*R3/R1
 
It is easier to look at this formula that way:

(Vout - 2.5) = (Vin - 2.5)*R3/R1

Or, for both formulae combined:

(Vout - 2.5) = I*0.185*R3/R1

Hello,

I left it in the form i had shown so that PG can see what is being done and work with it himself if it wanted to.

I am not sure why you are presenting your form as being somehow "easier", perhaps you can explain.

The simplest form is:
Vout=512-(4736*I*R3)/(125*R1)

and the digital output form (what we are after) is:
VoutDigital=floor(512-(4736*I*R3)/(125*R1))

With resistors R3=5k and R1=1k this then simplifies to:
Vout=512.0-189.44*I

and:
VoutDigital=floor(512.0-189.44*I)

Note it's a linear output so we end up with the slope intercept form of a line which is the simplest form.
 
I am not sure why you are presenting your form as being somehow "easier", perhaps you can explain.

Because in such form, it describes what is happening. The deviation from 2.5V gets magnified by the factor of R3/R1. If we want more magnification, we can increase R3 or decrease R1.
 
Thank you, MrAl, NG.

Using the amp is still better.

Thanks for confirming it.

The decision to use a 33pf cap would have to be made after a few real world tests.

Or, perhaps we can simply do away with it.

Lets concentrate on the calculations for now and come back to the others a little later.

In your data set, there appears to be a few errors. The -2.3 amp entry looks like it may be off by a few counts.

In my calculations or data set in this post the errors lie in decimal part of the numbers. I believe the reason for this is that I calculated the values for sensor output separately and then used those rounded sensor output results to find Vout of amplifier circuit. Hence, a kind of accumulated error occured. Besides this, I wasn't able to any other error with that data set.

This is from my data set: -2.3A in:--------Vout = 4.675V--------ADC result = 958
This is using your formulas: -2.3A in:--------Vout = 4.6275V--------ADC result = 948

There is an error of "10" between ADC results.

I believe overall my method of calculation was correct. If I'm wrong, please let me know. Thanks.

Also, some of the other entries look like they are rounded UP when they should be simply truncated. For example, if the analog output result is 417.8 the digital result should be 417, not 418.

Simply speaking, we are always interested in integer part of the number.

Note to self: floor() is a Matlab function like round() and ceiling(). The floor() is used to find integer part of a float.

Just for reference, the two main formulas are:
1. Vout1 = 0.185*I+2.5 (the sensor output)
2. Vout = 2.5*(R3/R1+1)-(Vout1)(R3/R1) (the op amp output)
3: ADC reading = floor{Vout (5/1024)}

Thanks for the formulas. I have edited them a bit. Hope you won't mind.

Im not sure how much of the work you wanted to do yourself so im not showing all the work yet :)

I had already done my work while constructing that data set but that's a different thing that I left some errors there for you to correct! :) Thank you.

NorthGuy: It looks like you missed a minus sign in (Vout - 2.5) = I*0.185*(-R3/R1). Thanks.

Best regards
PG

PS: I believe that it should be ADC reading = floor{Vout (1024/5)}.
 
Last edited:
Because in such form, it describes what is happening. The deviation from 2.5V gets magnified by the factor of R3/R1. If we want more magnification, we can increase R3 or decrease R1.

Hi,

I feel i owe it to you to tell you i disagree on this point, and the reason.

If this were an app where a human operator was going to be looking at a volt meter to see what the current level was, i would tend to agree with you, and i would want that kind of simplification too. But it's not a human operator, it's to be fed into an ADC of a micro controller. That means the ADC will have to interpret the result, and the ADC can only interpret positive results (at least this one anyway). That means we actually dont want to distinguish between plus readings and minus readings, at least not until the ADC+uC gets a chance to interpret them, and then they can be converted to whatever form is necessary for the application.

I'll still stay open to suggestion however if you still feel you have a reasonable explanation for wanting to render the formula into that form, but i'd like to hear this explanation so maybe i could understand you better.
 
Thank you, MrAl, NG.



Thanks for confirming it.



Or, perhaps we can simply do away with it.



In my calculations or data set in this post the errors lie in decimal part of the numbers. I believe the reason for this is that I calculated the values for sensor output separately and then used those rounded sensor output results to find Vout of amplifier circuit. Hence, a kind of accumulated error occured. Besides this, I wasn't able to any other error with that data set.

This is from my data set: -2.3A in:--------Vout = 4.675V--------ADC result = 958
This is using your formulas: -2.3A in:--------Vout = 4.6275V--------ADC result = 948

There is an error of "10" between ADC results.

I believe overall my method of calculation was correct. If I'm wrong, please let me know. Thanks.



Simply speaking, we are always interested in integer part of the number.

Note to self: floor() is a Matlab function like round() and ceiling(). The floor() is used to find integer part of a float.



Thanks for the formulas. I have edited them a bit. Hope you won't mind.



I had already done my work while constructing that data set but that's a different thing that I left some errors there for you to correct! :) Thank you.

NorthGuy: It looks like you missed a minus sign in (Vout - 2.5) = I*0.185*(-R3/R1). Thanks.

Best regards
PG


Hi again,

You noted that there is a count difference of 10 count in one of the readings, so you verified that there is something wrong with one of the calculations.

When you are studying this kind of problem and something like this happens like this, it's not enough to simply state that "there is an error". You must hunt and track down that error so that you can continue your work comfortably. Who made the error, was it you or was it the person giving you the other conflicting answer? To find out you should at the very least go over your own work to verify the procedure for calculating the gain and whatever else was done correctly, and additionally if the solution method of the conflicting data was also given to you, then you have the unique opportunity to go over THAT work as well in order to fish out any possible bugs.

I provided you with the method i used by providing the formulas. The formulas are nothing more than the gains of the two circuits and any offsets combined. I suggest at the very least that you provide your formulas step by step so we can all go over them.

For my solution, i simply start with the transfer function of the sensor as one formula, then find the transfer function of the op amp circuit, then combine the two. I then convert to digital form as i mentioned by dividing by the bit value 5/1024 and then taking the 'floor()' of the result.

So if you can state your solution step by step we'll see what happened that gave you a count that was different.
 
But it's not a human operator, it's to be fed into an ADC of a micro controller.

I don't understand the point of this discussion, but formulae are for humans. Humans may use them to design circuits (e.g. select resistor values) and/or write programs for MCU. The program for MCU is supposed to perform the opposite task - calculate current using ADC readings. The calculated current may be negative or positive.
 
Thank you, MrAl.

To find out you should at the very least go over your own work to verify the procedure for calculating the gain and whatever else was done correctly, and additionally if the solution method of the conflicting data was also given to you, then you have the unique opportunity to go over THAT work as well in order to fish out any possible bugs.

I provided you with the method i used by providing the formulas. The formulas are nothing more than the gains of the two circuits and any offsets combined. I suggest at the very least that you provide your formulas step by step so we can all go over them.

The following is from my previous post above.

In my calculations or data set in this post the errors lie in decimal part of the numbers. I believe the reason for this is that I calculated the values for sensor output separately and then used those rounded sensor output results to find Vout of amplifier circuit. Hence, a kind of accumulated error occured.

I did check some values but didn't update that data set. The reason for not updating is first I need to finalize value R3 between 4.7k or 5.1k. I will update it soon. Thanks.

Regards
PG
 
I don't understand the point of this discussion, but formulae are for humans. Humans may use them to design circuits (e.g. select resistor values) and/or write programs for MCU. The program for MCU is supposed to perform the opposite task - calculate current using ADC readings. The calculated current may be negative or positive.

Hi again,

First, note the application we are working with here. It's a current sensor to be used with a uC chip ADC unit. The uC may then display the current, or it may use it to adjust some process or even just store readings for later review by a human being.

What this means is that making a plus and minus sense out of the intermediate output of the amplifier makes no sense because we need to convert everything into a digital number that is positive, and that gets fed to the ADC.
To check for errors, we use a well chosen set of current levels and calculate the digital form, then compare these results to another members calculations to see if we are in agreement. If we are not in agreement then somebody made a mistake :)
There is no reason to convert to a plus and minus reading because we'll be comparing all positive numbers because that is what the ADC will convert it into. We need to know the ADC count is correct so we dont need to interpret it into any polarity.

I suppose what you wanted to do is make it 'easy' to read the output of the amplifier in terms of plus or minus, but that just does not help for this application nor for finding out if there are any errors in the digital count.

It would make a ton of sense if we had to monitor the output of the amplifier with a volt meter, but we are not doing that. Even then we would probably want to use a digital meter biased to 1/2 Vcc in order to get a plus and minus reading.

Sorry if you dont understand this concept but you did reply to my post stating that the formula you came up with somehow made something easier, so i thought i owed it to you to let you know about this.
 
First, note the application we are working with here. It's a current sensor to be used with a uC chip ADC unit. The uC may then display the current, or it may use it to adjust some process or even just store readings for later review by a human being.

On a construction of a cathedral you can see a long chain of people carrying stones. One of them was asked what he was doing and he said: "I'm carrying a stone". When another man was asked the same questions, he said: "I'm earning my living". A third man replied: "I'm building the cathedral".

I don't think the goal here to build a current management circuit. The goal here is to use this example to help PG to learn how to design circuits. There are many steps, and none of them should be skipped.

Here's how I would see the process:

The first thing is to set a goal. Say +-3A needs to be measured. We're given a sensor which does 185mV/A with assumed accuracy of 1%.

How much do we need to magnify that? Look at the op-amp output range - 0.25 to 4.75 (datasheet), perhaps little tighter. Gives us 4.5V. We need to map 6A into 4.5V. It gives us 0.75V/A. The device produces 0.185V/A. Need to magnify 4 times.

How do we do that? (Vout - 2.5) = -I*0.185*R3/R1. Looking at this, the amount of amplifications is directly proportional to R3/R1 ratio. We have only standard resistors. What level? Do we try to save power with bigger resistors or increase speed and precision? Sensor is at best 1% accurate, don't need to worry about precision, speed is not important - go power save - 10K for R1, (33K + 6.8K) for R3. Can short 6.8K later if need be.

Check the op-amp. We don't need much but it's good to check anyway. Input offset must be within 1mV. Noise? Other criteria? Are they met?

How do we measure that? ADC. Sensor is 1% accurate, we need 7bit, add one bit for rounding 8bit. We have 10bit ADC - fine 10 times more resolution. Checking ADC linearity, gain, offset errors (datasheet). Combined error is 3 counts. Good.

Now to the program. Get ADC count A. V = A*5/1024 (or perhaps V = A*5/1023? Doesn't matter. The last digit is well below sensor accuracy, it's bogus anway).
I = (2.5 - V)/(0.185*R3/R1).

o.185*R3/R1 is a constant = 0.185*(33+6.8)/10 = 0.763.

Other part: 2.5 - V = 2.5 - A*5/1024 = (512 - A)*5/1024 = (512 - A)* 0.00488

Combine: I = (512 - A)*0.00488/0.763 = (512-A)*0.00640. Go to mA: I = (512 - A)*6.4

Coding (in C). Processor is slow, do integer arithmetics in mA. Average some number of ADC samples. OP wants 30. Calculate the sum

C:
int16_t sum = 0;
sum += adc_count_received_from_adc; // repeat 30 times

30 samples will go up to 30*1024 = 30720. Will fit into int16.

Now, need to do averaging and scaling.

I = (512*30 - Sum)*6.4/30 = 15360 - Sum*0.2133.

Rewrite this in a form suitable for the computer: I = 15360 - Sum*13979/65536.

Go back, check all the numbers, make sure they're right. People do make mistake (at least me - I never get correct numbers in the first pass).

Convert to C:

C:
int16_t current;
 
sum = 15360 - sum;
current = (sum*13979L)>>16;

Write more to get it out to LCD or UART.

Testing. Produce different currents, measure with DMM and compare. Are they within 1% of ours. Good, we're done.

Not within 1%. Collect more data, do least squares. Check linearity. No linearity - big problem. Get a scope, go through the circuit, see where linearity is lost.

Linearity is good. Recalculate coefficents. Adjust 15360 and 13979 constants. Does it put us within 1%. Not within 1%? Can we leave with the error? No? Too bad, back to the drawing board, so what are we going to measure?
 
Hi,

Wow that was so much easier :)

Seriously though i guess we should take our own little side discussion into PM's or as they now call them "A conversation". I just started one.
 
Last edited:
On a construction of a cathedral you can see a long chain of people carrying stones. One of them was asked what he was doing and he said: "I'm carrying a stone". When another man was asked the same questions, he said: "I'm earning my living". A third man replied: "I'm building the cathedral".

This was really good!

I have constructed a new table of the values. This time R3=5.1k and R1=1k in the circuit.

Code:
-2.3A in:------------------Vout = 4.67005V---------------------------------------------------------------------------- = 956
-2A in:--------------------Vout = 4.387V----------------------------------------------------------------------------- = 898
-1.5A in:------------------Vout = 3.91525V--------------------------------------------------------------------------- = 801
-1A in:--------------------Vout = 3.4435V---------------------------------------------------------------------------- = 705
-0.5A in:------------------Vout = 2.97175V--------------------------------------------------------------------------- = 608
0A in:---------------------Vout = 2.5V---------------------------------------- 10-bit ADC integer reading in integer = 512 //range is 0 t0 5V
0.5A in:-------------------Vout = 2.02825V--------------------------------------------------------------------------  = 415
1A in:---------------------Vout = 1.5565V---------------------------------------------------------------------------- = 318
1.5A in:-------------------Vout = 1.08475V--------------------------------------------------------------------------- = 222
2A in:---------------------Vout = 0.613V----------------------------------------------------------------------------- = 125
2.3A in:-------------------Vout = 0.32995V--------------------------------------------------------------------------- = 67


Formulas used:

i:
Vout = {I*0.185*(-R3/R1)} + 2.5

ii: ADC reading = floor{Vout (1024/5)}

iii: For positive current:
2.3A is represented by = (512-67)
=> 1A is represented by = (512-67)/2.3 = 193.47826
193.47826 ADC reading respresents = 1A
=> 1 ADC reading = (1/193.47826)

Hence corresponding positive current any ADC reading = {512-(ADC reading)}(1/193.47826) //formula applies if(ADC <= 512)

iv: For negative current:
-2.3A is represented by = 956-512
=> -1A = (956-512)/2.3 = 444/2.3
444/2.3 ADC reading represents = -1A
1 ADC reading represents = -1/{(444)/2.3} A

Hence corresponding negative current for any ADC reading = {(ADC reading) - 512}(-2.3/444) //formula applies if(ADC > 512)

Regards
PG

PS:
An edit was made after MrAl's post below. The value for "1.5A in" was incorrect.
Check post #59 below. It gives a single formula to calculate current from any ADC reading.
 
Last edited:
This was really good!

I have constructed a new table of the values. This time R3=5.1k and R1=1k in the circuit.

Code:
-2.3A in:------------------Vout = 4.67005V---------------------------------------------------------------------------- = 956
-2A in:--------------------Vout = 4.387V----------------------------------------------------------------------------- = 898
-1.5A in:------------------Vout = 3.91525V--------------------------------------------------------------------------- = 801
-1A in:--------------------Vout = 3.4435V---------------------------------------------------------------------------- = 705
-0.5A in:------------------Vout = 2.97175V--------------------------------------------------------------------------- = 608
0A in:---------------------Vout = 2.5V---------------------------------------- 10-bit ADC integer reading in integer = 512 //range is 0 t0 5V
0.5A in:-------------------Vout = 2.02825V--------------------------------------------------------------------------  = 415
1A in:---------------------Vout = 1.5565V---------------------------------------------------------------------------- = 318
1.5A in:-------------------Vout = 1.1125V--------------------------------------------------------------------------- = 227
2A in:---------------------Vout = 0.613V----------------------------------------------------------------------------- = 125
2.3A in:-------------------Vout = 0.32995V--------------------------------------------------------------------------- = 67


Formulas used:

i:
Vout = {I*0.185*(-R3/R1)} + 2.5

ii: ADC reading = floor{Vout (1024/5)}

iii: For positive current:
2.3A is represented by = (512-67)
=> 1A is represented by = (512-67)/2.3 = 193.47826
193.47826 ADC reading respresents = 1A
=> 1 ADC reading = (1/193.47826)

Hence corresponding positive current any ADC reading = {512-(ADC reading)}(1/193.47826) //formula applies if(ADC <= 512)

iv: For negative current:
-2.3A is represented by = 956-512
=> -1A = (956-512)/2.3 = 444/2.3
444/2.3 ADC reading represents = -1A
1 ADC reading represents = -1/{(444)/2.3} A

Hence corresponding negative current for any ADC reading = {(ADC reading) - 512}(-2.3/444) //formula applies if(ADC > 512)

Regards
PG


Hello again,

I am not sure why you want to insist on using two formulas when only one is needed. That is, one formula that covers plus and minus signals. There are two parts to the formula (current sensor and op amp) but it's just one formula and it can handle anything you throw at it. It makes life a lot easier.

There is one value in your set that does not fit. I suspect it was just a simple miscalculation for that one data point. I am posting my set here so you can review. When i do my set i use a program so that all the values are calculated the same way. I'll include that too so you can see how easy it can be.

a

Code:
Iin    VSout     Vout   ADC
-2.3  2.07450  4.67005  956
-2.0  2.13000  4.38700  898
-1.5  2.22250  3.91525  801
-1.0  2.31500  3.44350  705
-0.5  2.40750  2.97175  608
+0.0  2.50000  2.50000  512
+0.5  2.59250  2.02825  415
+1.0  2.68500  1.55650  318
+1.5  2.77750  1.08475  222
+2.0  2.87000  0.61300  125
+2.3  2.92550  0.32995   67

Program:

atom R1,R2,R3,Rf,Iin,Vsout,Vin,Vout,Vref,Vcc,ADC
sequence IinValues

IinValues={-2.3,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.3}

Vcc=5
R1=100000
R2=100000
R3=5100
Rf=1000


Vref=Vcc*R2/(R1+R2)

for k=1 to length(IinValues) do
  Iin=IinValues[k]
  Vsout=Iin*0.185+2.5
  Vin=Vsout
  Vout=Vref*(R3/Rf+1)+Vin*(-R3/Rf)
  ADC=floor(Vout/(Vcc/1024))
  printf(1,"%+3.1f  %3.5f  %3.5f  %4d\n",{Iin,Vin,Vout,ADC})
end for


sleep(3600*24)

Note that in the program the formula is left in two parts for your easy inspection. If we combined them we would have one simple formula:
ADC=floor((500*R1-37*Iin*R3)/(200*R1)/(5/1024))
and that is good for any polarity signal.
Simplifying more, we get:
ADC=floor(512-(4736*Iin*R3)/(125*R1))
and this also allows you to get a sense of the effect of the polarity of Iin that i think NorthGuy was looking for, because 512 is the half way point for the ADC.
 
Last edited:
Part 1:
Say +-2.3A needs to be measured. We're given a sensor which does 185mV/A.

How much do we need to magnify that? The op-amp output range is 0.32995 to 4.67005. Gives us 4.3401V. We need to map 4.6A into 4.3401V. It gives us 0.9435V/A. The device produces 0.185V/A. Need to magnify 5.1 times.

How do we do that? (Vout - 2.5) = -I*0.185*R3/R1. Looking at this, the amount of amplifications is directly proportional to R3/R1 ratio. Let's assume that R1 is 1k and R3 is 5.1k.

Now to the program. Get ADC count A. V = A*5/1024 where "A" is ADC reading or count and it is an integer from 0-1023.

I = (2.5 - V)/(0.185*R3/R1).

0.185*R3/R1 is a constant = 0.185*(5.1)/1 = 0.9435

Other part: 2.5 - V = 2.5 - A*5/1024 = (512 - A)*5/1024 = (512 - A)* 0.00488

Combine: I = (512 - A)*0.00488/0.9435 = (512-A)*0.0051722. Go to mA: I = (512 - A)*5.1722

Coding (in C). Processor is slow, do integer arithmetic in mA. Average 30 ADC samples. Calculate the sum

C:
signed int16 sum = 0;
sum += adc_count_received_from_adc; // repeat 30 times

30 samples can at most go up to 30*1024 = 30720. So, the result will fit into int16.

Now, need to do averaging and scaling.

I = (512*30 - sum)*5.1722/30 = (15360 - sum)*0.17241.

Rewrite this in a form suitable for the computer: I = (15360 - sum)*11299/65536.

Convert to C:

C:
signed int16 current;       // I believe int16_t is also used to declare a signed int16

sum = 15360 - sum;
current = (sum*11299LL)>>16;     //  because in my compiler it takes LL to declare 32-bit int
//or we can use a single step: current = ((15360-sum)*11299LL)>>16



Part 2:
Let's talk about input offset a bit. MrAl was also mentioning it in previous messages but at that time I didn't focus on it.

Check the op-amp. We don't need much but it's good to check anyway. Input offset must be within 1mV. Noise? Other criteria? Are they met?

This text explains input offset voltage and input offset voltage drift parameters.

Let's focus on LM358 and the datasheet says that it has low input offset voltage of 2mV. So, what is this "2mV"? According the text it means that differential dc voltage of 2mV is needed to be applied to the inputs of LM358 to make the output 0V. In other words, you need to do this to make output voltage to be zero.

Thank you for the help.

Best wishes
PG

PS: This attachment was added later.
 

Attachments

  • diff_offset.jpg
    diff_offset.jpg
    22 KB · Views: 865
  • input_offset1.jpg
    input_offset1.jpg
    271.9 KB · Views: 593
  • offset2121.jpg
    offset2121.jpg
    192.5 KB · Views: 579
Last edited:
Hi,

That's very good, and almost correct. The only difference is that the 2mv can either be plus or minus for an op amp even the same type. So one might have +2mv offset and the next you pick up out of the parts bin might have -2mv offset.

The way this affects an application usually depends on the gain setting and it mostly affects DC coupled circuits not AC unless the gain is very high. For a gain of 5 for example, the output voltage could be off by 10mv (input offset 2mv again). If that 10mv represents 2 ADC counts (10bit ADC with 5v ref) and 2 ADC counts equate to (say) 20ma, then the ADC count could be off by plus or minus 20ma due to input offset. There is also some drift associated with the input offset, so it may increase with temperature. The data sheet should contain this info.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top