Go Down

Topic: ac current meter using acs758 hall sensor (Read 7 times) previous topic - next topic

hozone


The max value you can read is indeed 1023, but the correct value to use in the calulation is 1024. See section 24.7 of the atmega328p datasheet.

Thank you for this info!


Are you trying to measure alternating current? If so, you need to average the square of the current, and take the square root of the average (that's what RMS means). Easiest way is to subtract the zero-current value (512 or thereabouts) from the raw readings, square that, and add it to an accumulator variable. When you have accumulated enough samples, take the square root if the accumulator and divide by the number of readings.

Yes ac current.

so,
for AC current something like this
Code: [Select]
samplesnum = 100;
adc_zero = 512; //as read when there is no current on the load
sensitivity = 0.04; //as read from datasheet
for(i=0; i<samplesnum ; i++)
 adc_raw = analogRead(1);
 currentacc += (adc_raw - adc_zero) * (adc_raw - adc_zero); //subtract the zero-current value (512 or thereabouts) from the raw readings, square that, and add it to an accumulator variable
}
currentac = sqrt(currentacc)/samplesnum; //take the square root if the accumulator and divide by the number of readings.


for DC current something like this
Code: [Select]
adc_zero = 512; //as read when there is no current on the load
sensitivity = 0.04; //as read from datasheet
currentdc = (adc_raw - adc_zero) * 5/(sensitivity * 1024)


right?

dc42


reason for 1024, correct me if i'm wrong
adcraw is a 10bit values, so from 0(min) to 1023(max = 2^10-1), so the max values here is 1023


The max value you can read is indeed 1023, but the correct value to use in the calulation is 1024. See section 24.7 of the atmega328p datasheet.


i get adc samples for adc current making an avarage of "many" values, i.e. at least 2 times the period of my 50Hz primary current, and my adc values are stable.


Are you trying to measure alternating current? If so, you need to average the square of the current, and take the square root of the average (that's what RMS means). Easiest way is to subtract the zero-current value (512 or thereabouts) from the raw readings, square that, and add it to an accumulator variable. When you have accumulated enough samples, take the square root if the accumulator and divide by the number of readings.


thank you for reply


but maybe my formula is not correct, i'm using this one:
amp = (adcraw*adcvref/adcdiv- adcvref/2) / sensitivity;


The device is ratiometric, so its sensitivity varies with Vcc. Use:

  current = (adc_raw - adc_zero) * 5/(sensitivity@5V * 1024)

(where adc_zero is the ADC reading you get when the current is zero, which will be close to 512), which is almost the same.


because with "small" adcraw changes i have "big" change in amp
es.
(  512  *5/1023 - 5/2)/0.04 = 0.062   
(  516  *5/1023 - 5/2)/0.04 = 0.54    (1/2Amp!)
and also consider the max raw value of 1023
(  1023  *5/1023 - 5/2)/0.04 = 62.5
acs758-050b is rated as 50Amp max, the max raw value i should read is almost 900


That's the nature of the device. If you put more than 50A through it then the accuracy will degrade.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

hozone

thank you for reply


The value adcdiv in your calculation should be 1024, not 1023

reason for 1024, correct me if i'm wrong
adcraw is a 10bit values, so from 0(min) to 1023(max = 2^10-1), so the max values here is 1023


A value of 512 with no current flowing is exactly right, however the device may have an offset of a few mV, so the value may be a few counts out. Noise on the +5V line will affect the reading.

which is the math to use for transform adc values to amepere using an acs758.

i get adc samples for adc current making an avarage of "many" values, i.e. at least 2 times the period of my 50Hz primary current, and my adc values are stable.
but maybe my formula is not correct, i'm using this one:
amp = (adcraw*adcvref/adcdiv- adcvref/2) / sensitivity;

because with "small" adcraw changes i have "big" change in amp
es.
(  512  *5/1023 - 5/2)/0.04 = 0.062   
(  516  *5/1023 - 5/2)/0.04 = 0.54    (1/2Amp!)
and also consider the max raw value of 1023
(  1023  *5/1023 - 5/2)/0.04 = 62.5
acs758-050b is rated as 50Amp max, the max raw value i should read is almost 900

dc42

The value adcdiv in your calculation should be 1024, not 1023. A value of 512 with no current flowing is exactly right, however the device may have an offset of a few mV, so the value may be a few counts out. Noise on the +5V line will affect the reading.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

hozone

hello,

i'm trying to read ac current using a bidirection allegro hall sensor acs758-050b
i've a problem using it.
when i do not connect anything to this sensor i read
* a raw value of 516 with a input voltage of 4.80V +-0.05V
* a raw value of 512 with a input voltage of 4.70V +-0.05V

to convert the value to current i use the current formula
adcvref = 5
adcdiv = 1023
sensitivity = 0.04 ( acs758-050b sensitivity datasheet)
amp = (adcraw*adcvref/adcdiv- adcvref/2) / sensitivity;

anyway the problem with the raw value persist, even if i change the reference (adcvref) current value to real adcvalue (4.80 or 4.70)

can anyone help me?
thanks!

Go Up