ACS197 5A current sensor problems

I just started testing my 5A current sensor to integrate it into a larger project so I did a basic sanity test by hooking it up to a power supply. I carefully set the PS to 1A (confirmed by expensive multimeter) and monitored the output by serial terminal. It was WAYYY OFF.

Now, I assumed that the chip I had was 0.185 V/A per the spec sheet but after seeing the values I saw, I was like screw it, I'm going to calibrate this myself. So I started playing around with the multiplier and the offset to get both 0A and 1A matching my multimeter.

What I started with was 0.185V/A and no offset. What I ended up with was 0.1V/A and an offset of -0.197! The offset is terrible. The gain factor however makes me think that I had one of the other sensitivities of chip made by Allegro since they also have a 100mV version.

More serious than all of that, is that the drift/jitter is absolutely terrible. I sampled 1500 points at precisely 1 amp and ran the results through MiniTab. Take a look at the garbage in the attached screenshot. Sure I managed to get the average dead on but I can't work with data like that... the spec sheet said error <= 1.5%. Yeah, and I'm Santa Claus.

Well, I'm hoping somebody can shed some light on why this is happening and whether there's a fix. I could use a capacitor on the signal line. I could sample and average 1000 points before I use it in my code but neither option is attractive because I lose responsiveness in my system and there's not enough RAM to have huge averaging arrays.

I've always found hall-effect sensors to be flaky but before you ask, there was no EMI affecting my test.

I'd like to help but I can't find any info on the ACS197 so please include a link if you can.

Secondly please provide a Schematic of some sort.

I have used many Hall Effect Current Sensors and I've always found them to be reliable.

Sorry, I posted the wrong model number. It's ACS712:

There's really no schematic to post. I was just bench testing the thing. The breakout board has 2 screw terminals so I jammed 2 wires in there, hooked up my power supply (with a multimeter in series in current mode) and adjusted it to 1A constant current. There's nothing else in the circuit. This thing is just noisy. I wouldn't rule out the fact that the nano I was using could be causing the noise however. In fact I think it's plausible because a hall effect sensor in a stable environment with the EM field at a fixed distance (because the loops are etched into the PCB), driven by a fixed current wouldn't behave erratically like that. I was polling the sensor on A0 with a 50mS delay.

I should add that a similar MiniTab normal distribution taken at 0A shows the same smooth histogram shape on the right side (current > 0) but on the left it had 2-3 bars of equal size and then nothing to the left of that (ie. there were magic numbers that would always appear such as -0.17). Somehow, despite this lopsided distribution, the sample mean remained at the center point of the distribution, as you would expect if the bars were symmetrically equal.

What about power the sensor from arduino +5V? And common ground?

I powered the sensor from 5V and GND, not from the PS. The nano itself was powered from the mini-USB going to my laptop so I could see the data on the terminal viewer.

You are saying 1A, its not clear AC or DC? And does arduino measure Vcc/2 (about 512) when nothing connected or current 0?

Do you at least have the Ground from the Sensor Board connected to the Ground of the Arduino board.

If not that will cause most of your problems.

MasterT:
You are saying 1A, its not clear AC or DC? And does arduino measure Vcc/2 (about 512) when nothing connected or current 0?

I was just doing a DC test with a positive supply voltage and the sensor does bisect the 5V so 2.5V would be 0 sensor volts.

...however the way I did my sketch, all the math was done already and the output was simply the amperage.

technogeekca:
Do you at least have the Ground from the Sensor Board connected to the Ground of the Arduino board.

If not that will cause most of your problems.

The ground of the sensor was connected the Arduino GND pin. The Arduino was grounded via the USB cable going to my laptop. The only thing that wasn't common was the power supply, which was grounded to my house utility ground.

The only thing I can think to do in that case is store the output values in EEPROM and pull them later, so that I don't need my laptop and I can have a common ground. But EEPROM memory is limited and I need a large sample size to calibrate the gain and offset.

W/o looking at your sketch, we have no means to know if you do your math properly

Well whether the math is right or wrong, you don't get the data distribution I showed up above unless there's noise... BUT here it is:

int sensorValue

double amps

amps = (double)sensorValue/1023*5 // gives you the voltage on A0
amps = abs(amps - 2.5); // gives you the deviation from "sensor" 0 which is 2.5
amps = amps/0.1 - 0.197; // gives you amps based on the sensor's gain and offset

Amps therefore yields a value of 1 when you pass 1 amp through the sensor, at least that's the average value of all the noise you get.

Based on what I thought I bought, 0.1 above should have been 0.185 (V/A) and -0.197 should not exist at all.

After thinking about it some more I seem to recall testing a magnetometer I bought a while ago and it had horribly bad precision... numbers jumping around all over the place.

I also recall there being some sort of a command that would turn off something that makes noise in the Arduino so that the ADC could sample more cleanly. It wasn't a sleep mode IIRC but some single register that made ADC sampling less noisy.

Is there any way that you could scope the output of the sensor.

Umm... possibly?

Gimme a sec. I have a shitty scope on my computer.

Gahhhrrrlic:
I've always found hall-effect sensors to be flaky but before you ask, there was no EMI affecting my test.

Yes, they are noisy, you need to bandwidth-limit for accuracy - what anti-aliasing filter and sample rate did you use?

BTW such sensors usually have a bandwidth of 200kHz or so, if you don't need anything like that you get to lose massive amounts of noise by low pass filtering, noise power depends on bandwidth.

Scope shots below.

MartT: Are you referring to how often I sampled A0 in my sketch or something to do with configuring the hall effect sensor registers to do some intrinsic filtering? I didn't modify the chip at all. I just sampled A0 at 50 mS intervals.

Well then you'll get full spectrum noise(*) but you only need 25Hz of bandwidth at that sample rate.
Install a suitable filter capacitor on pin, 3u3 will give about 25Hz and 3000 time less noise power
(50 times less noise voltage).

(*) 80kHz according to the datasheet

What I started with was 0.185V/A and no offset. What I ended up with was 0.1V/A and an offset of -0.197!

Are you powering the Arduino through USB? The USB specification has VBUS range from 4.40V up 5.25V. If the voltage dips to 4.606V, then your offset would be -0.197V from 2.5V.

Just some notes:

  • 1A test current would only represent 185mV change in output level with about 21mV noise (11.4% of reading) with a clean supply.
  • For 10-bit DAC code, this only represents a change of 38 counts. 512 ---> 550.
  • ±5A represents ±925mV which represents ±175 change in ADC value (about 0.03A resolution per count)
  • Using a rail-rail op amp circuit with gain of 2.9, could improve resolution to about 0.01A per count.
  • Better yet, using the internal 1.1V reference would improve noise levels and resolution and offset problems. Need an op amp to shift to 550mV and amplify appropriately.
    Have you got the suggested 0.1µF decoupling capacitor from VCC to GND at the ACS712 breakout board?

Sorry let me go through your post again so I understand...

  1. The 80 kHz bandwidth (which I remember reading) means what? That the sensor spits out readings 80000 time per second? Are you aware of a means of reducing the bandwidth via chip settings?

  2. "Install a suitable filter capacitor on pin _____". Sorry, which pin were you about to refer to?

  3. "3u3" is that the code for the cap? how many pF/nF/uF is that?

Thank you.

dlloyd:
Are you powering the Arduino through USB? The USB specification has VBUS range from 4.40V up 5.25V. If the voltage dips to 4.606V, then your offset would be -0.197V from 2.5V.

Just some notes:
1A test current would only represent 185mV change in output level with about 21mV noise (11.4% of reading) with a clean supply.
For 10-bit DAC code, this only represents a change of 38 counts. 512 ---> 550.
±5A represents ±925mV which represents ±175 change in ADC value (about 0.03A resolution per count)
Using a rail-rail op amp circuit with gain of 2.9, could improve resolution to about 0.01A per count.
Better yet, using the internal 1.1V reference would improve noise levels and resolution. Need an op amp to shift to 550mV and amplify appropriately.

Have you got the suggested 0.1µF decoupling capacitor from VCC to GND at the ACS712 breakout board?

I'm hearing that uSB sucks for voltage stability so maybe this is the root of my problems.

A few mins ago it dawned on me how little of the ADC range I'm actually using. I blame the chip :slight_smile: 100mV/A?? What good is that?

The 1.1V ref is a neat idea but I an using just about every analog channel on the nano for something different. I need 5V for most of the stuff.

I tried a 30 something pF ceramic cap because it was laying derelict on the table next to me when I was testing... it had no effect :frowning: I can try something bigger.