1. 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.
    Dismiss Notice

Measure Mains AC current

Discussion in 'Electronic Projects Design/Ideas/Reviews' started by abicash, Jan 22, 2009.

  1. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    Hello MrAl

    Thanks for replying.
    But i have moved very far from that approach and due to accuracy and some other problems i am using the ACS712 sensor.

    I would like your help on that if you can.

    Thanks anyway
     
  2. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi,

    Actually i am happy to hear that you moved away from that simple solution
    because i dont think it is a very good one, unless you are working with
    low current.

    In order for me or anyone to help with this, i need to ask a few questions.
    1. What is the min and max current level you need to work with?
    2. I take it this is AC current?
    3. What kind of basic accuracy are you after?
    4. What kind of time response to an overcurrent do you need?
     
    Last edited: Jun 25, 2009
  3. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    The diode and the RC formed a peak detector on the o/p of ACS712 now i am not sure if i need this since i sample the adc maybe a 100 times in half a mains cycle.There is also no dicharge path foe the C.I am thinking of adding it too.

    Please get back

    Thanks and regards
     
    Last edited: Jun 25, 2009
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ

    Hi again,

    You probably dont need a diode anymore for rectification because you
    can do that in software. The output signal is entirely above ground,
    you just have to find the center and calculate the dc average. The
    number of samples has to be large enough to guarantee a small error,
    but with your requirement of 0.5 to 1 full second reaction time you can
    certainly get enough cycles in there for a 50 or 60 Hz line.
    If you can get 100 samples in one cycle and you have 50 cycles in one
    second that is 5000 samples total, which should certainly be enough.
    Even 2500 samples would probably do it with good enough accuracy.
    Round to the nearest power of 2 gives us 2048 samples, to make the
    division fast.
    For the low end of your measurement range, 125ma, at 100mv per amp,
    that means you will only get 0.0178v out of the sensor, which with a
    5.12v reference and a 10 bit ADC that will be 3 counts, which
    means you wont get good accuracy at the low end of the range.
    At the high end, 2.5 amps, the sensor will put out 0.354v, which is a
    count of 70, also not too good but possibly doable.
    The problem with the low end measurement is that the average value
    may be hard to calculate. If the output of the sensor with 0 amps is
    2.500v, then the output peak with 0.1 amps is 2.514v. That's only a 14mv
    difference and that is a little bit of a problem because that's only 2 or 3
    counts. At 0 amps the count would be 512, and at 0.1 amps the count
    would be about 515, which isnt much to work with. If the samples
    come at randomly placed intervals, we might get a good average, but
    still we would not be able to make a distinction between 107 ma and 125ma
    because at 107ma we get a count of 3 peak (over the center) and with
    143ma we get a count of 4.
    I dont know if this would work out in real life because there are things
    like noise and drift to consider. With a setting of 107ma one time the
    next hour later it might turn into a 143ma set point instead.

    What you might have to do is use an op amp and automatic zero
    detector (averager) to get some amplification AFTER the zero is
    subtracted from the output of the sensor. This might not be too
    hard to accomplish, but you would have to add an op amp stage.
    Sound ok or no?
    The amplification factor would be about 6, where a 2.5 amp peak would
    provide the ADC with a voltage of 2.1v (plus the zero offset value) and
    that would represent a count of 420 (plus offset count) and for the
    0.125 amp peak it would be a voltage of 35, which is getting a lot more
    reasonable.
    Possibly going with an active rectifier (as i think you considered once before)
    combined with the auto offset compensator (possibly all in one op amp)
    we can turn the 0 to 2.5 amp range into maybe 0 to 4.5v, and obtain even
    more accuracy...about twice as good as before meaning the low end
    count is abut 70 (not bad).

    So i guess the big question is, can you add an op amp stage?
    Also, and i should have asked this last time, how many bits is your ADC?
     
    Last edited: Jun 26, 2009
  6. Ubergeek63

    Ubergeek63 Well-Known Member

    Joined:
    Apr 16, 2008
    Messages:
    1,886
    Likes:
    37
    Actually most current transformers will run you that much or more and will not respond to DC.

    The hall effect sensors are technically another IC but they are low power, do not require any line side power supply, and replace the input amplifier and filtering that you would need with other solutions.

    Dan
     
  7. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    MrAl

    How beautifully have you explained stuff :) .BIGG thanks

    My MCU works on 3.3v (1.8v to 3.6v).
    My ADC is 10bit.
    Noise on my Vcc < 30mV so here some 8 counts are lost.
    The PSU (if you can check my schm) is an unisolated derived out of LNK304 so i think i dont have any control over the ripple/noise.

    I think the use of an opamp is imperative at this stage.
    [EDIT: Which can be the lowest cost,lowest pin count op-amp for this if i have to use ?..i see some from Analog devices..]

    Can you help me figure that out?

    Awaiting precious reply

    Thanks and regards
     
    Last edited: Jun 27, 2009
  8. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    I really doubt that..since if you follow the latest discussion here..it seems that an amplifier is needed..
    If you can help me understand how my design can be achieved w/o using an external amplifier,that would be wonderful..

    Thanks and regards
     
  9. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi again,


    Well, you do know that a current transformer will provide all the amplification
    needed right? Also, it will also add isolation. Are you sure you dont want to
    go with a simple current transformer? You could rectify the output and then
    0 to 2.5 amps could become 0 to 4v or something like that.

    If you still want to go with the sensor, that's ok too. Apparently we would then
    need to add an amplifier. It's up to you though. Let me know...
     
  10. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    Hello
    There is a footprint limitation for this.I have already validated it with a ct but the space problem has got me shifted to the hall sensor..So pls help me with this
    thanks & regards
     
  11. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ

    Hi again,


    Ok then i will assume you want to go with the sensor as we talked about
    plus an op amp stage for signal conditioning.

    Give me a little while to draw this up and post it.
     
  12. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi again,


    Here is a circuit that should work pretty well.

    Notice there is a peak detector on the output...you can use that or try
    doing that operation in the micro controller code, or both.

    Notice also that there is a 2.5k resistor with one open end. The open end
    goes to a micro controller output pin that is capable of going to a high
    Z state when instructed to do so. This is a trick to get more gain at very
    low inputs. One of the design challenges with the range of 125ma to 2500ma
    is that represents a range of 20 to 1, and with 2500ma we get a nice signal
    to work with but 20 times less than that (125ma) we get hardly any signal
    to work with. What this resistor and associated pin do is boost the gain
    when the output signal gets say under 1v. The signal is then much more
    readable down to 125ma and gives us much more to work with.
    The drawback is that the code will be a little harder to write in that you will
    have to decide what hysteresis works good enough. One possible approach
    is to take two measurements, one with the high Z pin forced to high Z, and
    another reading with the high Z pin forced to ground. You can then decide
    which measurement to use for the best accuracy. This should work ok
    because your circuit doesnt have to be especially fast from what you had said.

    Please let us know how you make out with it...
     

    Attached Files:

    Last edited: Jun 27, 2009
  13. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    Hello MrAl

    I will try this and get back.

    Meanwhile what do you think of this circuit (attached)
    I get a gain of 3 and shifted by 2.5v.

    Thanks and regards
     

    Attached Files:

  14. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi,

    Sorry, i thought you were using the 712-20, and i thought that was a little
    strange, but now that you show the 712-5 that makes more sense. In this
    case you will have to reduce the gain of my circuit by a factor of
    100/185 to get it to work.
    I also thought that you said you were using a 3.3v source voltage?
    Your schematic shows a 5v source, so which is correct?
    I ask this because more improvements could be made to my circuit if you
    instead use a 5v source.

    I'll get back here a little later with some more info.

    Ok, i see your circuit puts out 2.5v for zero AC input. Is this what
    you really want? You do loose some ADC range that way.
    Also, you can not use an LM358 like that with a 2.5 amp signal because it
    will saturate near the peak, leading to a large error in the measurement.
    The gain has to be reduced or use another op amp and possibly still
    lower the gain a bit.

    If you make the circuit ac coupled you get rid of any dc offset drift.
     
    Last edited: Jun 29, 2009
  15. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    I have made some boards for the TPS61222 3v to 5v boost converter which are not yet here.So i m yet to check the consequences of that.
    Furthermore i found this project which has an exact objective which i have (at least with the ACS712 and the ADC) but since there is not much on the codes there to understand how he has done it.

    Is expecting more help from you wrong?:eek:

    Please get back if you can :)

    Thanks and regards
     
    Last edited: Jul 1, 2009
  16. smanches

    smanches New Member

    Joined:
    Mar 5, 2009
    Messages:
    986
    Likes:
    8
    Location:
    Oregon, USA
    What is the purpose of the diode on the output of the opamp?

    Other than that I think it's a pretty standard approach to increasing the range on the ADC. Are you having other specific issues right now?

    As for your 3.3V being unstable, it's probably from the 5V boost converter. Do you have a fairly large cap on the output of the 3.3V regulator? Boosting to 5V is going to cause a fairly large current ripple on the 3.3V line, ~30-40% ripple as a quick guesstimate. I may have missed something, but why not regulate to 5V, then a second regulator at 3.3V?

    Do you have a up-to-date schematic of the entire thing?
     
  17. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    sort of a charge-and-hold? or to level shift to an adc powered by a lower rail?

    ...
     
  18. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    432
    Likes:
    3
    Can you share your adc codes with me for the ACS712 readings?..atleast i can get some idea what you are doing..or else some kickstart in that direction too will help!
     

    Attached Files:

  19. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,049
    Likes:
    961
    Location:
    NJ
    Hi again,

    What else are you having a problem with?
    Did you try the circuit i gave you with reduced gain yet?
    Is it that you dont have any uC code to work with yet?
     
  20. smanches

    smanches New Member

    Joined:
    Mar 5, 2009
    Messages:
    986
    Likes:
    8
    Location:
    Oregon, USA
    I doubt it's going to help you much. It's for the PIC for one thing, also it's just reading the ADC input and using that figure as a current limiting parameter.

    if (adcCurrent > maxCurrent)
    dutyCycle--;

    It's a bit simplified, but that's all it does. If you're looking for integration formulas, I think the ones DK provided would probably be much better. All I do right now is average the last 4 samples just to reduce the transients and use the value directly to reduce the PWM duty cycle.
     
  21. larrybeaty

    larrybeaty New Member

    Joined:
    Jul 2, 2009
    Messages:
    14
    Likes:
    0
    Location:
    Saint Petersburg, fl
    Mains AC current

    I believe it is DigiKey that has a CT for about $2.50. I have used them.
    I am about to use the Allegro current sense IC in the automobile. Both are good and have their features.
     

Share This Page