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.
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 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
(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.
MobileWill:
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.
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?
MobileWill:
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.
MobileWill:
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.
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:
long microAmps = (analogRead(pin) - 512) * 73982L;
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?
MobileWill:
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.