You are on page 1of 15

High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.

aspx

microchip.com

High Variance in ADC value with


ACS712 Current Sensor on PIC12F675
22-28 minutos

gailu96

New Member

Total Posts : 11

Reward points : 0

Joined: 3/1/2016

Location: 0

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 1:07 PM (permalink)

@SpokaneNexus
I need to measure 90mA accurately without any fail. I DO NOT
need 15A measurement at all.However I care about 15A for
following reasons because 15A is the max current that can flow
through ACS712 IC.

Suppose I use ACS712-5A model (185mv/A),


1) I doubt that it is recommended to use ACS712-5A for 15A

1 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

application
2) Suppose ACS712-5A works well for 15A or I use LM321 to
increase gain as specified in ACS712 data sheet (page-12,
Typical Application) I see following danger.
a) At 15A voltage increase would be .185*15 = 2.77V so sensor
output on positive side would be 2.5+2.77 = 5.2 and on negative
side it will be in minus. I suspect that could damage the micro
controller pin.

CinziaG

morite

Total Posts : 3144

Reward points : 0

Joined: 12/7/2016

Location: Wien

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 1:19 PM (permalink)

Clamping the voltage would not be a big issue...


But still I'd like to understand if the ADC module has issue.

Indeed I agree that relying upon 9mV is not much...

mi fate schifo, umani di merda.

Weydert

2 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Super Member

Total Posts : 472

Reward points : 0

Joined: 7/2/2008

Location: Aachen/Germany

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 1:21 PM (permalink)

@Mysil:
Did you use a similar PIC as gailu96?
From your results the PIC seems to make the noise.
You get an overall max. of 529dez and an overall min. of 492dez.
,but the average is stable.
The max. and min. values compare to the results of gailu96 (max.
527dez, min. 495 dez.) when he
shortcuts the analog input with 100nF.
These high noise is unacceptable for an ADC.
Unless the noise (with input at Vdd/2 from a resistive divider) can
be reduced by hardware dramaticly
noboddy will have any fun with this A/D converter

simong123

3 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Lab Member No. 003

Total Posts : 1272

Reward points : 0

Joined: 2/7/2012

Location: Future Gadget Lab (UK Branch)

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 1:34 PM (permalink)

gailu96
@SpokaneNexus
I need to measure 90mA accurately without any fail. I DO NOT
need 15A measurement at all.However I care about 15A for
following reasons because 15A is the max current that can flow
through ACS712 IC.
Suppose I use ACS712-5A model (185mv/A),
1) I doubt that it is recommended to use ACS712-5A for 15A
application
2) Suppose ACS712-5A works well for 15A or I use LM321 to
increase gain as specified in ACS712 data sheet (page-12,
Typical Application) I see following danger.
a) At 15A voltage increase would be .185*15 = 2.77V so sensor
output on positive side would be 2.5+2.77 = 5.2 and on negative
side it will be in minus. I suspect that could damage the micro
controller pin.

1) All three models (5A,20A,30A) have the same overcurrent


specification (60A). Only the output sensitivity changes. I see no
problem using the 5A model.
2) a) Read the datasheet. The ACS712 clamps the output voltage

4 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

to Vcc*0.0625 - Vcc*0.9375.
An Op-Amp cannot output outside it's supply rails, so use a R-R
I/O Op-Amp with Vss=PIC 0V & Vcc= PIC Vcc.

gailu96

New Member

Total Posts : 11

Reward points : 0

Joined: 3/1/2016

Location: 0

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 2:35 PM (permalink)

@simong123
Thanks for your great inputs. Can you please let me know page
numbers where I could find clamping details in ACS712
datasheet. I am referring to (http://www.allegromicro.com/~/media
/files/datasheets/acs712-datasheet.ashx) and not able to find the
clamping details you mentioned. Am I referring to a wrong
document? Can you please provide link to the document you are
referring?

simong123

5 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Lab Member No. 003

Total Posts : 1272

Reward points : 0

Joined: 2/7/2012

Location: Future Gadget Lab (UK Branch)

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 3:05 PM (permalink)

Hmm. My copy shows more than the one that you linked.
Screen cap of relevant section attached

Attached Image(s)

Mysil

Super Member

Total Posts : 2885

Reward points : 0

Joined: 7/1/2012

6 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Location: Norway

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 3:49 PM (permalink)

Hi,
@Weydert:
I did use PIC16F688 in 14 pin PDIP package,
I believe this to be the similar family and generation as 8 pin
PIC16F675 used by original poster.

In my experiment, it is mounted in socket on PICkit 2 Low Pin


Count Demo Board,
with the voltage resistors connected thru a row of sockets along
the side of the board.
The setup is powered directly from a low cost wall wart switching
power supply.
There is no local voltage regulation or power supply filtering on
the board.

PIC16F688 and similar old devices with few pins and no


debugging features,
are cramped and awkward to use for experimentation and
development in my opinion.
I mostly avoid it.

My experiment was not intended to demonstrate good analog


circuit layout,
instead to make a possibly realistic approximation of what original
poster may have done.

Measurements on small AC currents, using a sensor designed


for 15 A,
may be challenging indeed.

7 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

The program posted with the first message, have nominal


acquisition time of 25 microsecond,
and doing conversion with the local FRC in ADC module at
somewhere around 500 kHz,
will use another 25 microsecond, so sampling interval may be
something like 50 microsecond,
so the 1000 samples collected in each measurement series, will
take some 50 millisecond, or maybe a little more.

It may be possible to do measurements of AC current, by


accumulating both average value, and squared values for RMS
calculation.
Still, reducing the noise may be important, and a well designed
board with sensor chip, any op-amp circuit, microcontroller, and
power and reference reguation, on a multilayer board with good
ground-plane,
may help a lot.

The Arduino like board used for comparision, have external 9V


supply, and local regulation to 5 V and 3.3 V on the board.
I have no experience doing AD conversion with the processor in
sleep state, and do not know how much it may help.
More modern PIC devices, have internal bandgap voltage
references that may be used.

Regards,
Mysil

SpokaneNexus

Super Member

8 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Total Posts : 386

Reward points : 0

Joined: 2/5/2013

Location: 0

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 4:58 PM (permalink)

gailu96I need to measure 90mA accurately without any fail. I DO


NOT need 15A measurement at all.However I care about 15A for
following reasons because 15A is the max current that can flow
through ACS712 IC.
Suppose I use ACS712-5A model (185mv/A), I doubt that it is
recommended to use ACS712-5A for 15A application

Flowing more current through it is not a problem, as I mentioned


above and as was separately confirmed by another member here.

2) Suppose ACS712-5A works well for 15A or I use LM321 to


increase gain as specified in ACS712 data sheet (page-12,
Typical Application) I see following danger. At 15A voltage
increase would be .185*15 = 2.77V so sensor output on positive
side would be 2.5+2.77 = 5.2 and on negative side it will be in
minus. I suspect that could damage the micro controller pin.

The ACS parts, and any opamp you care to use, cannot drive an
output voltage beyond their own supply rails. Since you're running
on a 5V rail, you're not going to get anything above 5V or below
0V. The A/D input will be just fine as long as you're using a PIC
that is itself running on 5V.

SpokaneNexus

9 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Super Member

Total Posts : 386

Reward points : 0

Joined: 2/5/2013

Location: 0

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 5:09 PM (permalink)

gailu96OP state that output from the sensor is very stable when
there is no current in the measurement circuit, but there is no
explanation how this is verified. We have verified from Multimeter.
Exact Model - Fluke 101. Unfortunately I do not have scope.

If I might offer another polite suggestion: You need to find an


oscilloscope. You need to see, and understand, the signals you
are trying to use.

Forgive me if you already know the following....

The frequency response of the ACS parts is ~80KHz. Do you


realize you're not going to get a DC voltage level out of pin 7 on
the ACS? Presuming (for simplicity) that you have a resistive
load, you're going to get a sine wave out of pin 7 that is centered
on 2.5VDC, because the current flowing through the device is AC
and by definition AC flows alternately both ways.

Sampling a sine wave is going to be an interesting timing


challenge for your firmware and A/D. Presumably you don't want
to detect the zero crossings and time your samples to be 90

10 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

degrees later, etc. So... you put a cap on the filter pin of the ACS,
and/or you put a simple RC filter on pin 7 heading toward the A/D
input, to average out the signal to something stable for the A/D.
What is the average of a sine wave? Zero. In this case, with zero
centered on 2.5VDC, the average will be 2.5VDC. No matter how
much current is flowing, the average will always be at or near
2.5VDC.

You need to be looking at these signals, so you can understand


what you're trying to do. A meter is not the correct tool.

This is one of several reasons I recommended the unidirectional


version(s) of the ACS. A unidirectional version will magically give
you rectification of the AC, so that you'll only see the positive half
of the current waveform. Suddenly, your output filters will start
working the way you expect. And thanks to the fact that you're
only asking the ACS to look at the positive half of the signal, you'll
get an increase in sensitivity too, which is vital given the
extremely low currents you're trying to measure.

Get a scope and start looking at the signals involved. I suspect


you'll see a whole of things you didn't realize were happening.

post edited by SpokaneNexus - Tuesday, January 31, 2017 5:40


PM

PStechPaul

Super Member

Total Posts : 2053

Reward points : 0

11 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Joined: 6/27/2006

Location: Cockeysville, MD, USA

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 5:49 PM (permalink)

OK, now that there is more information, I can make better


observations and suggestions. And here is a link to the datasheet
for the ACS512:
http://www.allegromicro.c...2-Datasheet.ashx?la=en

(1) You are measuring an AC current signal of 90 mA RMS which


has a peak current of +/- 130 mA, so the ACS512-20 will give a
50/60 Hz sine wave signal of +/- 13 mV at 100mV/A.

(2) The ACS512 can operate at 5x overcurrent, so the 5A version


can tolerate the 15A maximum rated current of the circuit, and the
5A version can handle that and with 185mV/A will give +/- 262
mV.

(3) Keep in mind that a 15A circuit protected by a 15A breaker


might see overcurrent surges of 50 amps for a few seconds, and
the breaker (or fuse) has a time/current curve that may allow as
much as 10x for 100 mSec. The ACS512 can handle a non-
repetitive surge of 100A for 100 mSec, so it may be OK. But you
must be sure that the PCB traces from the line to the device can
handle the current.

(4) Since you are monitoring power line AC current of 50/60 Hz,
you might want to consider a simple and inexpensive donut type
CT where you just run the current lead through it. Such as:
http://www.mouser.com/ds/2/410/media-1067465.pdf
http://www.mouser.com/ds/2/599/4622-X011-288041.pdf

12 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

http://www.mouser.com/ds/2/410/media-346111.pdf (Has leads for


PCB mounting)
http://www.mouser.com/ds/2/192/CT08-1003175.pdf
https://sensing.honeywell.com/CSLH3A9-open-loop-current-
sensors (Hall effect)

(5) In any case, you need to read the AC current, preferably


RMS. I have been doing this for over 30 years. For 50/60 Hz you
can use a sampling rate of 1200/sec and perform an RMS
conversion on 60 samples (50 mSec) which is 12 cycles at 60 Hz
or 10 cycles at 50 Hz. Use a timer ISR to initiate conversions.
Use the ADC ISR to read each sample and square it (fastest to
use ADCreading*ADCreading, and add each result to the
previous total in an unsigned long (ADCtotal). When 60 samples
have been taken, store the ADCtotal in another variable
(oldADCtotal) and set ADCtotal to zero for the next sample. In the
main loop, divide oldADCtotal/60 and take the square root. This
will give you the true RMS reading. Since the readings may be
very small (perhaps 50 counts/1024) you could instead not do the
division and get higher resolution, or effectively 50 * sqrt(60) =
387 counts.

(6) A faster method is to do an average of absolute value


readings, also over the same time period which is an integral
multiple of cycles.

(7) I did not see a specification on the offset stability of the


ACS512, but Hall Effect sensors typically have some drift,
perhaps 0.5% of full scale, and a similar accuracy. So there could
be as much as 1% of 20 amp, or 200 mA, of uncertainty and drift
of the reading, which is greater than the signal you are trying to
measure. The simple CTs do not suffer from this limitation, and
you can easily shift the AC output to a reading centered on the
supply rail by using a voltage divider to Vdd.

13 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

gailu96

New Member

Total Posts : 11

Reward points : 0

Joined: 3/1/2016

Location: 0

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 6:05 PM (permalink)

At this point best option seems to be going with ACS712 5A


model as confirmed by members that there is no side effect. Will
try that in tomorrow.

SpokaneNexus

Super Member

Total Posts : 386

14 of 15 02/11/2018 11:26
High Variance in ADC value with ACS712 Current Sensor on PIC12F675 about:reader?url=https://www.microchip.com/forums/m971651-p2.aspx

Reward points : 0

Joined: 2/5/2013

Location: 0

Status: offline

Re: High Variance in ADC value with ACS712 Current Sensor on


PIC12F675 Tuesday, January 31, 2017 8:33 PM (permalink)

The '712 is still a bidirectional part. You're throwing away half of


the potential sensitivity and will still need to deal with the
averaging problem of the symmetrical waveform. I strongly
encourage you to use the lowest current UNIDIRECTIONAL
version you can obtain, for all of the reasons stated above.

15 of 15 02/11/2018 11:26

You might also like