LM258AD Differential amplifier not happy

Discussion in 'The Projects Forum' started by maxthestork, Oct 13, 2011.

  1. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    Hi All,

    This is my 1st post! I am implementing what I was hoping was going to be a simple battery voltage monitor to interface to my microcontroller.

    The battery voltage I am monitoring is 36.4V when fully charged and around 31.2V when about empty.

    To get better resolution since the range I am interested in is so small, I decided to put in a cheap 24V linear regulator and use a differential amplifier so that I get the difference of the battery voltage from 24V.

    The schematic is attached which shows what I am trying to do.

    The problem is that the amplifier does not do any differencing. Regardless of the voltage of the battery, the output of the circuit is stuck at about 0.8V

    It only starts to decrease below 25V (when the 24V output is no longer 24V).

    The input voltage I tested with is 32.5V and the voltage in to the opamp is as expected around 0.656V.

    The input from the 24V regulator to the opamp is higher than I expect at 1.28V.

    Is there something glaringly dumb that I have done. Analog is not my strength.

    Any help would be much appreciated and I will post the final working schematic in an altium schematic for anyone else to use downstream.

    Thanks
    Peter
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Hello Peter,
    I'm trying to figure out why you have 10k for R4/R5, and 205 Ohms for R3/R6?

    R6/(R5+R6) will result in both input voltages being multiplied by ~0.02009.
    So, if the actual battery voltage is 36, you'll get ~723.2mV at the noninverting input.
    Your 24v reference will be 0.48216 at the inverting input.
     
    Last edited: Oct 13, 2011
  3. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    If you want the output to be Vout=(Vbatt-24), then make all 4 resistors equal in value. 10k resistors will put a 20k load on your battery, which will cause it to discharge at 1.8mA, initially. If this is too high, you could make the resistors as high as 100k each.
     
  4. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Keeping in mind that the circuit will multiply the difference in the input voltages by .0205 with the values shown, which doesn't sound useful -
    If the output is able to sink the current that flows through the feedback resistor, the inverting input will follow the noninverting input, i.e., the inverting input voltage will also be 723.2mV. The output would need a 100Ω resistor to ground in order to sink the 2.33mA flowing in the feedback resistor. I don't recommend this, but if it were done, the output would be about 246mV (12V difference X .0205).
     
  5. BJT_user

    Member

    Oct 9, 2011
    35
    8
    Hello Max. I have some experience with differential circuits and the first thing I notice is that the op amp is powered with a single-ended supply. This means the negative supply to the op amp is also ground. For op amps, this makes things a little touchy for signals right around ground potential. Op amps don't like their inputs and outputs to run so close to their voltage limits. For best performance, you need to bias the inputs around the mid range of -V(gnd) and +V(24v).
     
  6. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    If you read the description of what he wants, you'll find that the output never gets near ground, so the single supply will work just fine, unless he redefines the problem.
     
  7. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    Hi All,

    Thanks for the replies. BJT_user, the LM258AD is a nice little device and will hapilly work with a single power supply as long as the inputs and outputs are all positive. I have attached the datasheet.

    SgtWookie, the analysis of the circuit leading to the 0.0205 gain for this differential circuit is described quite nicely here though there are probably other good ones out there
    http://www.electronics-tutorials.ws/opamp/opamp_5.html

    Ron H, thanks for the suggestions.

    I will probably get some 100k resistors to replace the 10k resistors to reduce the loading on the battery.

    I tested the idea of the 100ohm resistor from the output to ground. I had the feeling that the reason the inverting input value was so high was that there was not enough current being pushed back to lower the voltage at the inverting input but it did not occur to me that the load was not sinking very much current and so the value was stuck.

    I put in a 100 ohm resistor to ground and tested 3 battery voltages and the values changed to the following ( yes I know the lower value of 28 is lower than my battery spec but I am using a bench supply which only goes to 33V on a good day:D)

    Input (battery) voltage = 32.4V
    Non inverting input = 652.6mV (reasonable)
    Inverting input = 711.8mV
    Output of opamp = 227.3mV

    Input (battery) voltage = 30V
    Non inverting input = 603.8mV (reasonable)
    Inverting input = 711.6mV
    Output of opamp = 227.2mV

    Input battery voltage = 28V
    Non inverting input = 563.9mV (reasonable)
    Inverting input = 711.7mV
    Output of opamp = 227.3mV

    So the output and inverting input values are lower and more in line with expectations but still too high and they don't change with the input battery voltage which is the important part.

    My understanding (wobbly though it may be) is that the opamp is working to bring the voltage at the 2 inputs to the same value. When the non inverting input is at 563.9mV(for a 28V battery input), the opamp works to put the same voltage at the inverting input. The 24V reference has to be brought to 563.9mV which means it drops 23.4361V across the 10K resistor which means 2.34mA is flowing through the 10K resistor to the inverting input.

    To apply 563.9mV at the inverting input the opamp has to push (563.9mV/205 ohms) 2.75mA through the 205ohm resistor.

    Because no current (ideally) is flowing into the opamp inverting input, 2.34mA of the 2.75mA from the opamp output goes to offsetting the current from the 24V reference. This leaves 410 micro amp flowing across the 205 ohm feedback resistor which gives the opamp output voltage 84.05mV which sort of corresponds to the gain of 0.0205 for a 4V difference in input voltages.

    The logic of the stuff I wrote above would seem to work but why can't I see this happening?

    The 100 ohm resistor from the output to ground, reduced the size of the input at the inverting input but this is probably just because of a connection to ground from the 24V reference via the feedback resistor. So basically the behaviour looks the same except the output voltage of the opamp is shifted downwards. Was worth exploring the effect though...

    Looking forward to more ideas. Thanks again.


    Oh and I thought I would explain the strange 0.0205 gain.

    The voltage output from this circuit gets fed to another isolation device (HCPL-7520) but I did not want to confuse the discussion with a lot of other parts in the schematic. I will have to vary the gain as the 0.0205 gain is actually too high for the HCPL-7520 and causes it to saturate but I should be able to vary the gain through a change in resistors once I get a handle on why it is not giving me the voltage I want on the output.
     
  8. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    I didn't read the HCPL-7520 datasheet thoroughly, but my first thought is to insert a sense resistor in the feedback loop of the LM258, and monitor the voltage across it with the HCPL-7520. Trying to get a very low voltage out of the LM258 is problematic, and I think the input offset voltage becomes a fairly significant contributor to error.
     
  9. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    Hi Ron,

    thanks for your response. I removed the HCPL-7520 so that the output of the opamp is basically floating. The behaviour was not different both when as in the schematic and also with the 100 ohm resistor to ground.

    I was fairly sure the HCPL-7520 was not affecting the circuit but I took it out to be sure.

    I need to translate the voltage difference to a range of 0 - 220mV. I know my gain is not appropriate for this right now but the schematic I put up should have given me a good starting point and I would then just change resistors to get the gain sorted.

    I am confused as to why the behaviour is not what I would expect. I have tested this on 2 boards with the same results.

    The consistency of the behaviour on the 2 boards suggests that I am missing something and it is not (or less likely) a component issue.
     
  10. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Can you summarize what you expected? Sorry, but I got bogged down in post #7.
     
  11. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    No worries, Ron,

    From the schematic which I am reattaching, I was expecting to see the output of the opamp vary according to the difference between the voltages applied to the inverting and non inverting input.

    The circuit is a basic differential amplifier and the gain from the components selected should be 0.0205.

    My problem is that I don't see the output voltage varying with the battery voltage applied to the non inverting input.

    Really hoping someone can help me understand what's gone wrong with this.

    Thanks and regards,
    Peter
     
  12. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    I suspect that the device spec which indicates the amp output can swing to 0V may be indicative rather than absolutely true. The linearity may also be suffering as the output approaches 0V.

    Also the input offset will have some bearing on the accuracy.


    I ran a multi-step simulation using LM258 spice model

    Results attached show simulated output for given V_battery, the theoretical value and the % error. There is a distinct loss of linearity near the low end. The problem seems to be improved by using a bipolar supply +/-12V. Also if I then use a "better" op-amp such as an LT1006 the results are excellent.
     
    Last edited: Oct 14, 2011
    maxthestork likes this.
  13. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Also what resistor tolerances are you using?
     
  14. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    Hi t_n_k

    Thanks for looking at that in spice. I wish I knew how to use SPICE. Will have to get familiar with it at some stage and probably would not have (as many) of these problems...

    Does seem like Ron suspected as well that the small bracket at the bottom of the working window is not going to do what I want. I might have to ditch my opamp differential amplifier as I can't squeeze a negative supply on to the board.

    Thanks guys, I will have a think and post back.
     
  15. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    Hi t_n_k

    the resistor tolerances are 0.1%.
     
  16. maxthestork

    Thread Starter New Member

    Oct 13, 2011
    13
    1
    :DHi All,

    ok the good news. The circuit works as expected if the resistor values are all 10K and the output is pretty much equal to the difference between the opamp inputs.

    This bottoms out at ~1.4V and maxes at 7.9V.

    I now plan to feed this difference to the next part of the circuit using a resistive divider to scale it.

    Wish I didn't have to modify 10 boards but it is better than modifying 100:rolleyes:

    Thanks again for all the inputs.
     
  17. BJT_user

    Member

    Oct 9, 2011
    35
    8
    That is a basic problem with Op Amps. When the VCC- is at ground potential, the output becomes nonlinear when it gets to around < 1.5 volts. TNK is right about the output being able to swing to 0 volts, but that is only if VCC- is in the range of -1.5 volts or more. Also, the same is true for outputs that are close to VCC+. The output can never reach the same potential of VCC- or VCC+ due to the biasing potential required for transistors. There must be at least .7 (1.4 for darlingtons) above VCC- or below VCC+ for transistors to function linearly.
     
  18. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Set the op amp gain at 1, and use an attenuator on the output to get to .0205.

    EDIT: Oops. I see that you have already decided to do this.
     
    Last edited: Oct 14, 2011
Loading...