kh

ghi
ghi

Monday, November 23, 2015

USING ACS712 to measure AC current



Features and Benefits
  • Low-noise analog signal path
  • Device bandwidth is set via the new FILTER pin
  • 5 us output rise time in response to step input current
  • 80kHz bandwidth 
  • Total output error 1.5% at Ta = 25C
  • Small footprint, low-profile SOIC8 package
  • 1.3mOhm internal conductor resistance
  • 2.1 kVRMS minimum isolation voltage from pins 1-4 to pins 5-8
  • 5.0 V, single supply operation
  • 66 to 185 mV/A output sensitivity
  • Output voltage proportional to AC or DC currents
  • Factory-trimmed for accuracy
  • Extremely stable outpput offset voltage
  • Nearly zero magnetic hysteresis
  • Ratiometric output from supply voltage
download full datasheet here 





When measuring AC current, there usually is no need for taking readings of the negative part of the cycle, so we can stick to the positive half by tying our Vref to 2.5 volts as the negative voltage reference. This will enable you have more resolution for your ADC conversion. But for the sake of simplicity, the code bellow will span the whole 0 -5V by having the negative voltage reference set to 0V.

////////////////////////////---------------------------------------------------------------------------------------------
// You can include this code to your microC project and make appropraite calls to the specific functions
// Usually, a single call to getpeakCurrent() does all the job.
//
int  getMax(int a, int b){
    return a>=b? a:b;
}

unsigned int getPeakCurrentVal(){
 int a, b;
 int i;
 int buffer[400];

 for(i=0; i< 400; i++){
  buffer[i] = ADC_Read(0) ;                 //Change the ADC channel to the specific channel you are using
  delay_us(100);
  }
 a = buffer[0];
 for(i=0; i<400; i++){
  b = buffer[i];
  a = getMax(a,b);
  }
 return a;
}

unsigned int Average10(){
unsigned int times;
unsigned long int ret = 0;
   for(times = 0; times < 10; times++) {
   ret += getPeakCurrentVal();
   }
 ret /= 10;
 return (unsigned int)ret;
}

float getPeakCurrent(){
 float p_current;
 p_current = (float)((Average10()- 512)/20.0);                      //scale peak current to actual current in Amps
 if(p_current < (float)0.0){
  p_current = 0.0;
 }
 return p_current;
}

         

0 comments:

Post a Comment