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.

Measure Mains AC current

Status
Not open for further replies.
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
 
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:
Hi,

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?
Minimum AC current =125mA
Maximum AC current = 2.5A
beyond these two limits i turn off the current carrying appliance/device.

2. I take it this is AC current?
Yes 230v AC

3. What kind of basic accuracy are you after?
Not very accurate.As i said earlier that i just need two limits beyond which is fault condition.But i guess the lower limit will define the accuracy.

4. What kind of time response to an overcurrent do you need?
Not very responsive.Maybe 500ms is good enough or even 1 second.

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:
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:
Thats a lot of cost.
This system will be manufactured in good quantity and current protection was just another feature thrown in at the last moment.

Also Allegro doesnt seem to have good support in my part of world.

I would really wind a Current Transformer myself in a really small form factor and that would be it!!!
I dont understand why you wont approve of a CT?
Since I dont require response and accuracy as much.


Thanks again
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
 
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:
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.

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
 
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...
 
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
 
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


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.
 
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...
 

Attachments

  • SensorInterface-01.gif
    SensorInterface-01.gif
    4.2 KB · Views: 1,009
Last edited:
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
 

Attachments

  • opamp gain 3.PNG
    33.3 KB · Views: 1,941
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:
Hi,

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 have two voltages 3.3v is for the MCU and 5v is for the ACS712.So the 5v could be used for the opamp as well.

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.

The value that ACS712 puts out at its VIOUT for zero i/p current is 2.5v.Subsequent currents will be higher or lower than this reference voltage at
185mv/A.So i am just removing this shift.And if 5v as Vcc is used then i dont think saturation will occur


If you make the circuit ac coupled you get rid of any dc offset drift.

The one like you did?.but remember that the o/p from ACS712 is NOT AC or if put in right words,just moves around +2.5v..so still AC coupling will help?

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:
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?
 
What is the purpose of the diode on the output of the opamp?

it is a peak detector.

Are you having other specific issues right now?

There are lots as i am continuing this thread.I am attaching a current approach which i am using now (as "tl431incl.png") and the proposed approach (as "with tps61222.PNG") with the boost converter.

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?

In the schematic you can see a ACST4 Triac which has to be fired only in this peculiar way.
Now if i use the LNK304 to generate the +5v first(actually its -5v ,i have only reversed the GND reference) then the Triac will always be fired,since the Neutral=+Vcc=+5v and the gate is at +3.3v ,MCU o/p pin for triac off condition...(you have to visualise a bit here)..so it is imperative that the Triac COMMON terminal and the GATE terminal share a common rail or to be precise;voltage levels, which you can see in the first schematic.I am using a 2.5v reference at the Vss terminal so effectively Vdd-Vss~2.6v (since Vcc=5.1v)..Now i have two grounds in my circuit .one with 5v and the other with 2.6v.This schem is not working for the ADC reading as it should.So i proposed another one using the boost converter so that both grounds are at same potential and i generate 3.3v first so that the Triac can be fired flawlessly.Now the ACS712 needs 5v so i am left with no other way to power that up unless i use a boost converter ic.The opamp too is a proposed idea and yet to be implemented once my printed boards for the TPS61222 arrive.(they are so tiny that almost impossible to solder on a general purpose board)

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!
 

Attachments

  • tl431incl.PNG
    88.8 KB · Views: 1,109
  • with tps61222.PNG
    92.3 KB · Views: 1,660
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

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?
 
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!

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.
 
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top