I am thinking of using ACS712 to measure AC mains current on my teensy project which takes only 3.3v analog in.
If I add say an 1N4004 diode at the AC input to essentially get the lower half wave of the AC, given the 20A version of ACS712 specs says 100mv per ampere sensitivity, that means at 20amps peak current, the output will be 20 x 0.1 = 2v, but since the chip is only receiving the negative half wave, the reading will be 2.5-2 = 0.5v correct? and I don't have to worry about level shifting since the output will not go higher than 2.5V.
I figure my device will use only 6amp RMS or about 8.5amp peak.
Anyone tried this? Any reason why this won't work?
I would try running the sensor on 5volt, and use a (10k)resistor between sensor out and analogue in.
No current would be 2.5volt, so ~75% on the A/D scale.
With the 20A version of the ACS712 you probably won't have any clipping.
Larger currents will clip the top of the sine wave.
You could try reading only the negative half of the sinewave in software.
Leo..
The analog in of teensy (MK20 arm processor) is not 5v tolerant, and I'm not sure how much above 3.3v it can tolerate.
I don't think more than 8amp peak actual will be used, so the max positive should be 3.3v so you are right that the positive won't clip, and all I need to do is ignore any reading above the 75% value (16bit resolution for teensy analog input) . I was just thinking for safety, to add the diode on the AC input and I did not find anything in the datasheet saying full AC wave is required for this to work. I suppose if I use the 30amp version, I won't have to even use the diode, but the reading resolution will get quite low. I like the 20amp resolution 1mv=10ma.
Also, I am thinking, to get the RMS value, instead of actually calculating the square of each reading, taking the avg then the sq root, I will just get the max over say 250 samples over 100ms (read every 400us) then multiply that by 0.707. I'll test/compare this to result of actually calculating rms to see if they are close.
I just realized, if half the cycle is not present, I probably need to increase the sample time.
hmm, I will need at least a 10amp diode for this to work.
doughboy:
The analog in of teensy (MK20 arm processor) is not 5v tolerant, and I'm not sure how much above 3.3v it can tolerate.
Above ~3.8volt input, the input protection diode starts to conduct.
The 10k resistor would limit pin current to 120uA.
Another way is a 1:2 voltage divider on the output of the sensor.
e.g 5k from sensor to pin, and 10k from pin to ground.
That will idle the analogue pin at mid-voltage (1.65volt).
No clipping, and always <3.3volt.
Leo..
ok, I just realized the acs712 is connected in series to the load, so I don't think I can add the diode to the ac input.
although the output is a sine wave, it will be biased to 2.5v, so I can't really use the diode on the output.
if I scale using 1:2, the resolution will go from 100mV/amp to 66mV/amp.
Another option is, I could just use the 30amp version, where the resolution is 60mV/amp, and I don't need to add any additional component.
the datasheet states minimum output resistive load is 4.7k. so if it is the case where I must add a resistor load, then I might as well use the divider.
The datasheet has this application note on scaling to 3.3v.
Not sure what the diode is for.
I am guessing the voltage divider will scale to 3.75v and the diode drop will decrease the voltage further down to 3.3?
doughboy:
Another option is, I could just use the 30amp version, where the resolution is 60mV/amp, and I don't need to add any additional component.
the datasheet states minimum output resistive load is 4.7k. so if it is the case where I must add a resistor load, then I might as well use the divider.
You still have to use that 10k pin-current limiting resistor if you use the 30A version.
Load will be 14.7k with a 4k7:10k divider, because the analogue input pin resistance is almost infinite.
I would use the 20Amp chip, and the voltage divider option.
Leo..
The diode is a "top detector"
It rectifies AC to DC, so the micro doesn't have to sample that often.
It is also less accurate.
No current is already ~1.5volt.
And the diode's forward voltage is temp dependent.
They have forgotten to add a bleed resistor across the cap (C1).
Without that, current readings can't go down.
Leo..
I did a search and found this good explanation for the diode (essentially what you described)
However the diode will prevent any discharge of the capacitor back through the source, so the voltage on the capacitor will be the peak voltage (maximum positive excursion, less diode drop) - but will be slowly discharged via any parallel resistor and of course the loading of the WC board itself (about 200K)
so the circuit will always give the peak reading (calibration is needed to figure the right value), so anytime you do an analog read, it will be the peak and just multiply by 0.707 to get the rms.
Remember that with a 100mV/A sensor, and a 1:2 divider, you will have 66mV *1.414 *2 = 186.6mV peak/peak per amp.
About 230 digital values per amp in your case.
Should be enough to get a good resolution.
Leo..
I prefer less component so I'd rather not have the diode. I was considering it if it can actually give a good peak reading, that will save cpu time from calculating rms. It would be nice to just do analogRead at any time, map the value, and just multiply by .707 as the only calculation to get the rms value.
66mv/amp on 16bit adc will give about 1300 digital values per amp right? (may be subject to more noise though)
isn't the resolution given in terms of instantaneous reading value and not RMS? So like the 20amp version is referring to 20amps peak and not 20amps RMS? Hence most code I find takes 250 readings over 100ms, sum the square of each reading and divide by 250 then take the sq root of that to get rms. And by reading, it is always with reference to the midpoint.
So after scaling to 3.3v, if say the reading is 2v, is your calculation taking that as peak to peak reading? Isn't it going to be 2-1.65=.35x2 = 0.7v is the peak to peak value?
That's why I did not follow why the need to convert to peak if the reading value is already a peak value.
What I understand of a ACS712-20 sensor is that it can read 20A DC either way.
Idle is 2.5volt, sensitivity is 100mV/A, so 20A could give 4.5volt or 0.5volt.
A 1Amp AC current is 100mV RMS, 141mV peak, and 282mV peak/peak (current goes both ways).
In your case, you have to add the 1:2 resistor divider ratio to the maths (* 1.5).
By now you will have noticed that the 20A ACS712 is only good for 14Amp AC.
Leo..