Ic For Fun: A brief overview of Allegro ACS712 current sensor (Part 1) |
- A brief overview of Allegro ACS712 current sensor (Part 1)
- A brief overview of Allegro ACS712 current sensor (Part 2)
- How to measure dc current with a microcontroller?
A brief overview of Allegro ACS712 current sensor (Part 1) Posted: 13 May 2012 01:09 PM PDT Sensing and controlling current flow is a fundamental requirement in a wide variety of applications including, over-current protection circuits, battery chargers, switching mode power supplies, digital watt meters, programmable current sources, etc. One of the simplest techniques of sensing current is to place a small value resistance (also known as Shunt resistor) in between the load and the ground and measure the voltage drop across it, which in fact, is proportional to the current flowing through it. Whereas this technique is easy and straightforward to implement, it may not be very precise because the value of the shunt resistor slightly varies with its temperature, which in fact is not constant because of the Joule heating. Besides, this simple technique does not provide an isolation between the load and current sensing unit, which is desirable in applications involving high voltage loads. Today, we will talk about Allegro ACS712 device which provides an economical and precise way of sensing AC and DC currents based on Hall-effect. This discussion is divided into two parts. The first part will provide a brief overview of the ACS712 sensor and its characteristics. In the second part, a test experiment will be carried out to interface the sensor with a PIC microcontroller to measure a dc current. ACS712-05 current sensor module
TheoryThe current sensing technique based on a shunt resistor is described in How to measure dc current with a microcontroller? and implemented in the Multi-functional power supply project. The major disadvantages of this technique are:
The Allergo ACS712 current sensor is based on the principle of Hall-effect, which was discovered by Dr. Edwin Hall in 1879. According to this principle, when a current carrying conductor is placed into a magnetic filed, a voltage is generated across its edges perpendicular to the directions of both the current and the magnetic field. It is illustrated in the figure shown below. A thin sheet of semiconductor material (called Hall element) is carrying a current (I) and is placed into a magnetic field (B) which is perpendicular to the direction of current flow. Due to the presence of Lorentz force, the distribution of current is no more uniform across the Hall element and therefore a potential difference is created across its edges perpendicular to the directions of both the current and the field. This voltage is known Hall voltage and its typical value is in the order of few microvolts. The Hall voltage is directly proportional to the magnitudes of I and B. So if one of them (I and B) is known, then the observed Hall voltage can be used to estimate the other. Principle of Hall-effect The ACS712 device is provided in a small, surface mount SOIC8 package. It consists of a precise, low-offset, linear Hall sensor circuit with a copper conduction path located near the surface of the die. When current is applied through the copper conductor, a magnetic field is generated which is sensed by the built-in Hall element. The strength of the magnetic field is proportional to the magnitude of the current through the conduction path, providing a linear relationship between the output Hall voltage and input conduction current. The on-chip signal conditioner and filter circuit stabilizes and enhances the induced Hall voltage to an appropriate level so that it could be measured through an ADC channel of a microcontroller. The pin diagram of ACS712 device and its typical application circuit is shown below. Pins 1, 2 and 3, 4 forms the copper conduction path which is used for current sensing. The internal resistance of this path is around 1.2 mΩ, thus providing low power loss. As the terminals of this conduction path are electrically isolated from the sensor leads (pins 5 through 8), the ACS712 device eliminates the risk of damaging the current monitoring circuit due to the high voltage on the conduction side. The electrical isolation between the conduction current and the sensor circuit also minimizes the safety concerns while dealing with high voltage systems. Pin diagram and a typical application circuit of ACS712 In low-frequency applications, it is often desirable to add a simple RC filter circuit at the output of the device to improve the signal-to-noise ratio. The ACS712 contains an internal resistor (RF) connected between the the output of the on-chip signal amplifier and the input of the output buffer stage (shown below). The other end of the resistor is externally accessible through pin 6 (Filter). With this architecture, users can implement a simple RC filter through the addition of an external capacitor (CF) between the Filter pin and ground. It should be noted that the use of external capacitor increases the rise time of the sensor output, and therefore, sets the bandwidth of the input signal. The maximum bandwidth of the input signal is 80 KHz at zero external filter capacitor. The bandwidth decreases with increasing CF. The datasheet of ACS712 recommends to use 1 nF for CF to reduce noise under nominal conditions. Functional block diagram of ACS712 Sensitivity and output of ACS712 The output of the device has positive slope when an increasing current flows through the copper conduction path (from pins 1 and 2, to pins 3 and 4). The ACS712 device comes in three variants, providing current range of±5A (ACS712-05B), ±20A (ACS712-20B), and ±30A (ACS712-30A). The ACS712-05B can measure current up to ±5A and provides output sensitivity of 185mV/A (at +5V power supply), which means for every 1A increase in the current through the conduction terminals in positive direction, the output voltage also rises by 185 mV. The sensitivities of 20A and 30A versions are 100 mV/A and 66 mV/A, respectively. At zero current, the output voltage is half of the supply voltage (Vcc/2). It should be noted that the ACS712 provides ratiometric output, which means the zero current output and the device sensitivity are both proportional to the supply voltage, VCC. This feature is particularly useful when using the ACS712 with an analog-to-digital converter. The precision of any A/D conversion depends upon the stability of the reference voltage used in the ADC operation. In most microcontroller circuits, the reference voltage for A/D conversion is the supply voltage itself. So, if the supply voltage is not stable, the ADC measurements may not be precise and accurate. However, if the reference voltage of ADC is same as the supply voltage of ACS712, then the ratiometric output of ACS712 will compensate for any error in the A/D conversion due to the fluctuation in the reference voltage. Let me explain this with an example. Suppose, an ADC chip uses Vcc = 5.0V as a reference for A/D conversion and the same supply voltage powers an ACS712 sensor chip. The analog output of the ACS712 will be digitized through the ADC chip. When there is zero current through the current sensor, the output is Vcc/2 = 2.5V. If the ADC chip is 10-bit (0-1023), it will convert the analog output from the ACS712 sensor into digital value of 512 count. Now, if the supply voltage drifts and becomes Vcc = 4.5V, then, due to the ratiometric nature, the new output of the ACS712 sensor will be 4.5/2 = 2.25V, which will still be digitized to 512 by the ADC as its reference voltage is also lowered to 4.5V. Similarly, the sensitivity value will also be lowered by a factor of 4.5/5 = 0.9, which means if the ACS712-05B is powered with a 4.5V supply, the sensitivity is reduced to 166.5 mV/A, instead of 185mV, A. This concludes that any fluctuation in the reference voltage will not be a source of error in the analog-to-digital conversion of the ACS712 output signals. The curve below shows the nominal sensitivity and transfer characteristics of the ACS712-05B sensor powered with a 5.0V supply. The drift in the output is minimum for a varying operating temperature, which is attributed to an innovative chopper stabilization technique implemented on the chip (read ACS712 datasheet for detail). Output voltage vs sensed current of ACS712-05B at 5.0 V power supply and varying temperature SummaryThis article briefly described the ACS712 current sensor and its basic features. Continue reading the second part of this discussion to see how to use it with a PIC microcontroller to measure DC current. A brief overview of Allegro ACS712 current sensor (Part 2)Related posts:
|
A brief overview of Allegro ACS712 current sensor (Part 2) Posted: 13 May 2012 01:08 PM PDT In the first part of this discussion, the features of ACS712 device were briefly discussed. Now we will use that theory to implement the ACS712 sensor to make a simple DC current meter. The analog output voltage from the sensor is measured through an ADC channel of the PIC16F1847 microcontroller. A voltage to current conversion equation will be derived and implemented in the firmware of the PIC microcontroller and the actual load current will be displayed on a character LCD. Measuring dc current with ACS712 sensor
Experimental circuit setupWe are going to setup a test experiment to demonstrate the use of ACS712 to measure a DC current. I am using an ACS712-05B breakout module (you can find them cheap on ebay) for this purpose. It has got a 1 nF filter capacitor connected between pin 6 and ground, a 100 nF decoupling capacitor between power supply lines, and a power on LED soldered on the board. The power supply and output lines are accessible through header pins on one side, whereas, the current terminals are connected to a 2-pin terminal block on the opposite side, as shown below. ACS712-05 current sensor module The experimental circuit diagram of the DC current meter is shown below. A 2.7 Ω (rated 2 Watt) resistor is connected in series with the current terminals and a varying dc voltage is applied to vary the current through the resistor and the current path. The output of the sensor module goes to AN0 (pin 17) ADC channel of the PIC16F1847 microcontroller. A 16×2 character LCD is used to display the measured current output. Circuit diagram (Click to enlarge it) I am using my PIC16F1847 breadboard module along with the Experimenter's I/O board to demonstrate this experiment. Sensor setup is done on a breadboard Complete setup The microcontroller uses the supply voltage (+5V) as reference for A/D conversion. The digitized sensor output is processed through software to convert it to the actual current value. The mathematics involved in the process is described in the white board below. Mathematics involved in ADC conversion Important note: 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. The equation clearly tells that the current resolution for this setup is 26.4 mA, which corresponds to count 513, one count higher than the zero current offset. Therefore, this kind of arrangement is not suitable for measuring low current. You need an external Op-Amp circuit to enhance the resolution and be able to make more sensitive current measurement. If you are interested on that, you can visit Sparkfun's ACS712 Low Current Sensor Breakout page that provides a circuit diagram for such an arrangement. SoftwareThe current-Count equation described above is implemented in the firmware of PIC16F1847 to compute current from digital count. The result is finally displayed on the LCD with a precision of two decimal places. The following software is written in C and compiled with the mikroC Pro for PIC compiler from mikroElektronika. /* Project: Use of ACS712 sensor for DC current measurement MCU: PIC16F1847 running at 4.0 MHz using external resonator and MCLR is enabled Written by: Rajendra Bhatt (www.embedded-lab.com) Jan 22, 2012 */ // Define LCD connections sbit LCD_RS at RB0_bit; sbit LCD_EN at RB1_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB0_bit; sbit LCD_EN_Direction at TRISB1_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections void Display(unsigned int num){ char temp[] = "I = 0.00 Amp"; temp[4] = num/1000 + 48; temp[6] = (num/100)%10 + 48; temp[7] = (num/10)%10 + 48; LCD_Out(2, 3, temp); } char message[] = "ACS712-05 Sensor"; unsigned int ADC_Value, Factor; unsigned long temp; main(){ ANSELA = 0x01; // PORTA.0 is analog TRISA = 0b00100001; // RA5 and RA0 are inputs ANSELB = 0x00; // PORTB pins are all digital TRISB = 0x00; // PORTB pins are all output Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); // CLEAR display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,message); Factor = 264; // To conver Count into current do{ // Read multiple samples for better accuracy ADC_Value = ADC_Read(0); ADC_Value = ADC_Value + ADC_Read(0); ADC_Value = ADC_Value + ADC_Read(0); ADC_Value = ADC_Value/3; temp = (ADC_Value-512)*Factor ; ADC_Value = temp/10; Display(ADC_Value); Delay_ms(1000); } while(1); } OutputAt zero input current, the ACS712 output should be ideally Vcc/2, which is equivalent to an ADC count of 512. A drift of 4.9 mV in the output voltage of ACS712 results in an offset of 1 LSB in the A/D conversion (for Vref = 5.0V, resolution of 10-bit ADC is 5V/1024 = 4.9 mV). Interestingly, one LSB is equivalent to 26mA of current for ACS712-05B. The drift of 4.9 mV or more in the zero current output voltage is considered likely to happen, which is reflected in the output shown on the LCD. I have seen the ACS712 output for zero input current fluctuating between 512 and 513 ADC counts. If it is 513, the displayed current would be 0.02 A. So it is always better to take multiple ADC measurements and then take their average. Offset of 20 mA corresponding to 1 count When the variable DC is set to 1.0 V, the current through the 2.7 Ω resistor should be 370 mA. The measured value is 390 mA, which is off by 1 LSB. Output for variable DC input equal to 1.0V Output when DC input equal to 2.0 V
This concludes the discussion on the ACS712 current sensor. However, one concern is still not addressed. How would you measure an AC current with the ACS712 sensor? Keep in mind that the ACS712 sensor provides an instantaneous output corresponding to the current flowing through the conduction terminals. If the current flow is in positive direction (from pins 1 and 2 to pins 3 and 4), the sensitivity of the device is positive, and the ACS712 output voltage rises above Vcc/2. But if the current changes its direction, the sensitivity will be negative and the output of the ACS712 decreases below Vcc/2. This means, for an AC current, the 10-bit ADC output measured by the microcontroller oscillates about 512 counts. Therefore, the microcontroller needs to sample the sensor output fast enough so that the RMS value of the current can be computed from them. Related posts:
This posting includes an audio/video/photo media file: Download Now |
How to measure dc current with a microcontroller? Posted: 13 May 2012 01:01 PM PDT Microcontrollers usually don't have specific ports for measuring currents, but they do have ADC channels through which you can measure analog voltages of a certain range. This means a dc current can be indirectly measured by a microcontroller's ADC channel by first converting the current into voltage. The simplest way of doing this is to place a resistance in series with the current path and measure the voltage drop across it. But hold on, if you place an additional resistance in the circuit, it will affect the original current. Therefore, we need to use a very small value resistance so that it's effect in the circuit current won't be significant. Resistors with values less than 1 Ω are available in electronics stores. Depending upon the amount of current in the circuit, you need to choose proper power rating for the resistor. Suppose, if you pick 0.47 Ω, and the maximum current in the circuit is about 2 A, then the resistor should have the capacity of dissipating 4 x 0.47 ≈ 2 Watts of heat. You can also make a small value resistance by yourself. Yes, by simply winding a copper wire into coil. I have made one from a 5 ft long solid copper wire (22 AWG) with plastic insulation on outer side, as shown below. Current sensing resistance Now lets measure its resistance. The resistance can be measured directly with a digital multimeter. My digital meter shows its value equal to 0.3 Ω. This measurement may have higher uncertainty as it is very small and most multimeter does not show values beyond 1 decimal digit. The resistance can also be measured using Ohm's law. Connect a 47 Ω resistor in series with the coil resistance (Rs) and supply a 5V power as shown below. Next, measure the voltage across Rs and current through it separately using the multimeter. In my case, I found the measured voltage and current values to be 24.1 mV and 84.3 mA, respectively. This gives the resistance of the coil is about 0.286 Ω. Now, suppose that the range of current to be measured using this coil resistance is from 0-2 A. Then the voltage drop across the coil resistance will be somewhere from 0 – 0.57 V. Because of its low dynamic range, this voltage signal may not be accurately measured with a microcontroller's ADC module. So this requires some sort of voltage scaling. One way to achieve that is by using an operational amplifier circuit as shown below. Opamp as a voltage scaler In the circuit, Rs is the low value current sensing resistor (our coil resistor) which is connected in series with the load resistor. Our objective is to derive the load current (I). The low voltage drop across Rs is amplified by the non-inverting amplifier. The gain of the amplifier is set by Rf and Ri resistors. For Rf = 10 K, and Ri = 1.3 K, the gain of the amplifier would be about 8.7. This is enough to linearly scale Vs (0-0.57 V) to Vo (0- ≈5 V). Now you have 0-5 V voltage signal that corresponds to 0-2 A current through Rs. This voltage signal is now more appropriate for ADC conversion with Vref = 5 V. Vo = 8.7 x I x Rs = 2.49I (Rs = 0.286 Ω) => I = Vo/2.49. For 10-bit ADC with Vref = 5 V, resolution = 5/1024 = 0.0049 V. For input signal Vo, the ADC O/P will be Vo x 0.0049. Thus, I = ADC O/P x 0.0049/2.49 = 0.00197 x ADC O/P The current resolution would be therefore 0.00197 A (≈ 2 mA). No related posts. |
You are subscribed to email updates from WORLD OF ELECTRO To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |