📜 ⬆️ ⬇️

Working with Hall Effect Current Sensors: ACS758

Hello!

Perhaps, it is worth introducing a bit - I am an ordinary circuit engineer, who is also interested in programming in some other areas of electronics: DSP, FPGA, radio communication and some others. Recently, he plunged into SDR receivers. I first wanted to devote my first article (I hope, not the last one) to a more serious topic, but for many it will become just reading material and will not be useful. Therefore, the topic chosen is highly specialized and extremely applied. I also want to note that, probably, all the articles and questions in them will be considered more by the circuit engineering, and not by the programmer or anyone else. Well - let's go!

Not so long ago, I ordered the design of a system for monitoring the energy supply of a residential house, the customer is engaged in the construction of country houses, so that some of you may have even seen my device. This device measured the consumption currents at each input phase and voltage, simultaneously sending data via the radio channel to the already installed Smart Home system + was able to cut down the starter at the input to the house. But the conversation today will go not about him, but about his small, but very important component - the current sensor. And as you already understood from the title of the article, these will be “contactless” current sensors from the company Allegro - ACS758-100 .
________________________________________________________________________________________________________________________________________
')
Datasheet, on the sensor about which I will talk, you can see here . It is easy to guess that the number “100” at the end of the marking is the limiting current that the sensor can measure. To be honest, I have doubts about this, it seems to me that the conclusions simply will not withstand 200A for a long time, although it is fine for measuring inrush current. In my device, the sensor at 100A without any problems constantly passes through itself at least 35A + there are consumption peaks up to 60A.

image
Figure 1 - Appearance of the sensor ACS758-100 (50/200)

Before going to the main part of the article, I suggest that you familiarize yourself with two sources. If you have basic knowledge of electronics, they will be redundant and feel free to skip this paragraph. The rest I advise you to run for general development and understanding:

1) Hall effect. Phenomenon and principle of operation
2) Modern current sensors
________________________________________________________________________________________________________________________________________

Well, let's start with the most important, namely the labeling. I buy components in 90% of cases on www.digikey.com . Components come to Russia in 5-6 days, there is probably everything on the site, also a very convenient parametric search and documentation. So the full list of sensors of the family can be found there for the request " ACS758 " My sensors were purchased in the same place - ACS758LCB-100B .

Inside the datasheet for marking everything is painted, but I still pay attention to the key point " 100V ":

1) 100 is the measurement limit in amperes, that is, my sensor can measure up to 100A;
2) " B " - here you should pay special attention to this letter, instead of it you can also have the letter " U ". The sensor with the letter B can measure alternating current, and accordingly the constant current. The sensor with the letter U can measure only direct current.

Also at the beginning of the datasheet there is a great sign on this topic:
image
Figure 2 - Types of current sensors of the ACS758 family

Also one of the most important reasons for using such a sensor has become - galvanic isolation . The power terminals 4 and 5 are not electrically connected to the terminals 1,2,3. In this sensor, communication is only in the form of an induced field.

Another important parameter appeared in this table - the dependence of the output voltage on the current. The beauty of this type of sensor is that they have a voltage output, and not a current like a classic current transformer, which is very convenient. For example, the output of the sensor can be connected directly to the input of the ADC of the microcontroller and take readings.

For my sensor, this value is 20 mV / A. This means that when current 1A flows through terminals 4-5 of the sensor, the voltage at its output will increase by 20 mV . I think the logic is clear.

The next moment, what is the output voltage? Given that the power is “human,” that is, unipolar, then when measuring AC, there should be a “point of reference.” In this sensor, this reference point is equal to 1/2 of the power (Vcc). Such a solution is often convenient. When current flows in one direction, the output will be “ 1/2 Vcc + I * 0.02V ”, in the other half period, when the current flows in the opposite direction, the output voltage will be “ 1/2 Vcc - I * 0.02V ”. At the output we get a sine wave, where "zero" is 1 / 2Vcc . If we measure direct current, then the output will be " 1/2 Vcc + I * 0.02V ", then when processing data on the ADC, we simply subtract the constant component 1/2 Vcc and work with the true data, that is, with the remainder I * 0.02V .

Now it's time to test in practice what I described above, or rather, read it in datasheet. To work with the sensor and check its capabilities, I built such a “mini-stand”:

image
Figure 3 - Platform for testing the current sensor

First of all, I decided to apply power to the sensor and measure its output in order to make sure that 1/2 Vcc is taken as its “zero”. You can take the wiring diagram in the datasheet, but just wanting to familiarize myself, I didn’t waste my time and make a filter capacitor on the power supply + RC chain of the low-pass filter at the Vout pin. In the real device without them anywhere! Got a picture like this:

image
Figure 4 - Measurement result of "zero"

When powering 5V from my STM32VL-Discovery, I saw these results - 2.38V . The first question that arose was: “ Why is 2.38, but not described in datasheet 2.5? ” The question disappeared almost instantly - I measured the power bus for debugging, and there 4.76–4.77. But the thing is that the power comes from USB, there is already 5V, after USB there is a linear stabilizer LM7805, and this is clearly not an LDO with a 40 mV drop. Here it is about 250 mV and fall. Well, okay, this is not critical, the main thing is to know that the "zero" is 2.38V. It is this constant that I will read when processing data from the ADC.

And now let's take the first measurement, so far only with the help of an oscilloscope. I will measure the short-circuit current of my regulated power supply, it is equal to 3.06A . This and the built-in ammeter shows and the fluke gave the same result. Well, we connect the outputs of the power supply unit to the legs of the 4th and 5th sensors (in the photo I have a vitaha thrown) and see what happened:

image
Figure 5 - Measurement of short-circuit current PSU

As we can see, the voltage at Vout increased from 2.38V to 2.44V . If we look at the dependence above, then we should have got 2.38V + 3.06A * 0.02V / A , which corresponds to the value of 2.44V. The result is in line with expectations, at current 3A we received an increase to “zero” equal to 60 mV . Conclusion - the sensor works, you can already work with it using the MK.

Now it is necessary to connect the current sensor with one of the ADC pins on the STM32F100RBT6 microcontroller. The pebble itself is very mediocre, the system frequency is only 24 MHz, but this scarf I have experienced a lot and has established itself. I own it already, probably, about 5 years, because it was obtained free then during the times when ST distributed them right and left.

At first, out of habit, I wanted to install an op amp with a coefficient after the sensor Gain "1", but, looking at the block diagram, I realized that he was already inside. The only thing worth considering is that at maximum current, the output power will be equal to the power of the Vcc sensor, that is, about 5V, and the STM can measure from 0 to 3.3V, so it is necessary in this case to set a resistive voltage divider, for example, 1: 1.5 or 1: 2. I have the current miserable, so for now I neglect this moment. My test device looks like this:

image
Figure 6 - We assemble our “ammeter”

Also, to visualize the results, I screwed the Chinese display on the ILI9341 controller, the benefit was lying at hand, and my hands did not reach it. To write a full-fledged library for him, he killed a couple of hours and a cup of coffee, since the datasheet surprisingly turned out to be informative, which is rare for the handicrafts of Jackie Chan’s sons.

Now you need to write a function for measuring Vout using the microcontroller ADC. I will not tell in detail, according to STM32 there is already a sea of ​​information and lessons. So just look:

uint16_t get_adc_value() { ADC_SoftwareStartConvCmd(ADC1, ENABLE); while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); return ADC_GetConversionValue(ADC1); } 

Further, in order to obtain the measurement results of the ADC in the executable code of the main body or interrupt, it is necessary to state the following:

  data_adc = get_adc_value(); 

Pre-declaring the variable data_adc:

  extern uint16_t data_adc; 

As a result, we get the variable data_adc, which takes a value from 0 to 4095, because ADC in STM32 is 12 bit. Next, we need to turn the result “in parrots” into a more familiar form, that is, into amps. Therefore, it is necessary to first calculate the price of division. After the stabilizer on the 3.3V bus, my oscilloscope showed 3.17V, did not begin to figure out what this is connected with. Therefore, dividing 3.17B by 4095, we obtain the value 0.000774 - this is the price of division. That is, having received the result from the ADC, for example, 2711, I will simply multiply it by 0.000774V and get 2.09V.

In our task, the voltage is only a "mediator", we still need to convert it into amps. For this, we need to subtract 2.38B from the result, and divide the remainder by 0.02 [B / A]. The result is this formula:

 float I_out = ((((float)data_adc * presc)-2.38)/0.02); 

Well, it's time to pour the firmware into the microcontroller and see the results:

image
Figure 7 - Measurement results of data from the sensor and their processing

Measured own consumption of the circuit as seen 230 mA. Measuring the same attorney fluke, it turned out that the consumption of 201 mA. Well - the accuracy of one decimal place is already very cool. Let me explain why ... The range of measured current is 0..100A, that is, the accuracy up to 1A is 1%, and the accuracy up to tenth of amperes is 0.1%! And please note this without any circuit solutions. I was even too lazy to hang the filter Conder on nutrition.

Now it is necessary to measure the short circuit current (CC) of my power source. I twist the handle to the maximum and get the following picture:

image
Figure 8 - Short-circuit current measurements

Well, actually testimony at the source with its native ammeter:

image
Figure 9 - The value on the scale of BP

In fact, it showed 3.09A, but while I was photographing, the vituku heated up, and its resistance increased, and the current, respectively, fell, but this is not so bad.

In conclusion, I do not even know what to say. I hope my article will somehow help novice radio amateurs in their difficult path. Maybe someone will like my presentation form, then I can continue to periodically write about working with various components. Your wishes on the subject can be expressed in the comments, I will try to take into account.

And of course, I am attaching the source code of the program , you see, who needs a library to work with the display or ADC. The project itself in Keil 5.

Source: https://habr.com/ru/post/397641/


All Articles