Pages: [1]   Go Down
Author Topic: ACS714 30A  (Read 5314 times)
0 Members and 1 Guest are viewing this topic.
Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to come up with a good solution for the AC714 30A current sensor. I have read a few different sites and their formulas come with different results. I need to figure would which is right/acurrate way.

This site http://embedded-lab.com/blog/?p=4529
Says the Sensitivity changes if the Vcc changes, is that right?
Quote
The calculations shown above considered supply voltage Vcc = Vref = 5.0 V. Interestingly, the final equation relating I and Count remains the same even the power supply fluctuates. For example, suppose Vcc fluctuates and becomes 4.0 V. Then, the sensitivity of the ACS712-05B also changes to 0.185 x 4/5 = 0.148 mV. If you repeat the above calculations with Vcc = Vref = 4.0 V and sensitivity = 0.148 mV, you will end up with the same equation for I and Count. This was possible because of the ratiometric output of the ACS712 sensor.

This site http://www.lucadentella.it/en/2011/11/29/sensore-di-corrente-con-arduino/
Code:
float average = 0;
  for(int i = 0; i < 1000; i++) {
    average = average + (.0264 * analogRead(A0) -13.51) / 1000;
    delay(1);
In my case .0264 would be .0074 since I have the 30A version.

Finally this site http://arduino.cc/playground/Main/CurrentSensing
Code:
int    Sensitivity    = 66; // mV/A
  long   InternalVcc    = readInternalVcc();
  double ZeroCurrentVcc = InternalVcc / 2;
  double SensedVoltage  = (RawADC * InternalVcc) / 1024;
  double Difference     = SensedVoltage - ZeroCurrentVcc;
  double SensedCurrent  = Difference / Sensitivity;

This takes into account of the Vcc dift but do I need to if the sensor has ratiometric output? If so I need to adjust the sensitivity? I tired with and without adjusting sensitivity and didn't change much
I adjust by doing this
Code:
(Sensitivity*InternalVcc/5)/1000)

What I don't understand is with nothing going through the sensor shouldn't I get straight 512? Or is 512-510 normal for nothing passing through it?

The example from arduino.cc varies a bit. My goal after I get a good formula is to average it out and to log power usage over time.

Thanks for any help you can provide.
 
I have this sensor
http://www.pololu.com/catalog/product/1187
Datesheet
http://www.pololu.com/file/0J196/ACS714.pdf
« Last Edit: June 06, 2012, 11:28:58 pm by MobileWill » Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

> What I don't understand is with nothing going through the sensor shouldn't I get straight 512? Or is 512-510 normal for nothing passing through it?

You should get 512 but the hall effect sensor is probably sensitive to external magnetic fields.

Being off by 2 (510 instead of 512) is an offset of less than 0.15 Amps.  Is that a problem?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It shouldn't be, I am sensing AC power.

So which formula would be better to base my code on?

I eventually want to figure out watt-hour and such.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So which formula would be better to base my code on?

I expect the three sets of formulas are mathematically the same.

If you measure in increments of 1/4 microamp you can keep everything in long integers and not have any round-off errors.

The data you have is 0 to 1023 representing -30A to +30A.  60/1024 = 0.05859375 A/step.  Multiply by 4,000,000 to get 234375 quarter-milliamps per step = 58593.75 microamps per step.

Using long integers you could use:
Code:
long quA = (analogRead(pin) - 512) * 234375L;
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, I will try and figure this out tonight.

So do I need to worry about adjusting the sensitivity?

I think I like the formula that takes into account Vcc but does take longer to run for doing fast sampling. Unless I read the internal Vcc once on boot up. I am using a switch PS embedded in my enclosure. So far the internalVcc doesn't change while it is running.

The internal Vcc registers at 5.239 but my DIMM reads 5.18, that is close enough right?

Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I forgot to mention that if I used the formula, either one 1023 would calculate about 37A. Is that right? Much higher than what the sensor range is.

Overtime the average would cover the jitter...?
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The internal Vcc registers at 5.239 but my DIMM reads 5.18, that is close enough right?

The sensor is ratiometric.  As long as the Sensor Vcc is the same as the analog input Aref the voltage doesn't matter.

I forgot to mention that if I used the formula, either one 1023 would calculate about 37A. Is that right? Much higher than what the sensor range is.

I get very close to 30 Amps at full scale.

1023 - 512 = 511 * 234375 = 119,765,625 quarter microamps  / 4,000,000 = 29.9410625 Amps
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks! Seems like both those formulas are off.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I will use that and then just sample it over time to figure out power usage overtime, sweet. Can't wait to try it tonight.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like my assumption that 0-1023 matches -30 to 30A is wrong.  With a sensitivity of 66 mV per A the optimized -30 to 30 range would be (Vcc/2)-1.98V to (Vcc/2)+1.98V (0.52V to 4.48V).

That's something like .073982 A per step.  73,982 microamps per step. 

The corrected formula is:
Code:
long microAmps = (analogRead(pin) - 512) * 73982L;
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tired it and yours gets the same as the Arduino.cc site but with more decimal places.

Thanks for the help, its still not perfectly clear how you got the 73829 from the range but at least it works. It just has to be converted to A and remove the negative.

Do you think your short form would sample faster than the arduino.cc version?

How fast would I have to sample for 60hz AC to figure out power usage?

I was thinking every second take the average of samples taken during that second, store that in an array. Then using the array I could figure out usage since each entry is 1 second of time.

Edit: I forgot, should I used a interrupt timer to get accurate consistent samples?
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well I am done for the night, i couldn't get it to avg right.

I tired 60 times a second or 1000/sec then added up and divided and didn't get expected results

I tired:

Code:
if (time <= (millis() + 1)) {
time=millis();
countAvg++;
update_current();
}
if (countAvg == 1000){
 currAvg = currAvg/1000;
 //printDouble(currAvg, 2);
 Serial.println(currAvg);
 currAvg = 0;
 countAvg = 0;
 

and
Code:
float average = 0;
  for(int i = 0; i < 1000; i++) {
    average = average + (.0074 * analogRead(A0) -3.78) / 1000;
    delay(1);
  }
  Serial.println(average);

Do should both work?

Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Monterey CA
Offline Offline
Sr. Member
****
Karma: 1
Posts: 323
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Forgot to mention that the 2nd doesn't feel right to me. Shouldn't it add up and then divide after its sampled?

I adjusted the values from the original formula for 66m/v instead of the 184m/v from the 5A version.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Santa Rosa, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help, its still not perfectly clear how you got the 73829 from the range but at least it works. It just has to be converted to A and remove the negative.

As I'm currently noodling using the ACS714 for current measurement, I went back to figure out why 73.829 mA was the number he gave. It ends up it's just how an ADC works.

10 bits = 1024 steps (from 0 for 0v to 1023 for full AVCC) - theoretically, mind you; there can be plenty of external reasons (read: noise) that can prevent a consistent and precise reading on the ADC pins
0.52V would approximately read as 106 in the ATmega (assuming AVCC is 5V)
4.88V would approximately read as 917, meaning that the actual range of numbers you'd read would be between 106 and 917 (or 811 steps)
Divide 60A (the range of +/-30A) by 811, you get 73.829 mA per step.

Finally, as a best practice, always oversample the ADC and average across several measurements. I've never used a single sample reliably.
Logged

Pages: [1]   Go Up
Jump to: