Anda di halaman 1dari 30

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

aspx

microchip.com

High Variance in ADC value with


ACS712 Current Sensor on PIC12F675
39-49 minutos

gailu96

New Member

Total Posts : 11

Reward points : 0

Joined: 3/1/2016

Location: 0

Status: offline

Hi Experts,

I am trying to read ACS712 sensor output on PIC12F675 and


values are not as expected. ACS712 sensor gives output VDD/2
i.e. 2.5V when no load is connected. So I expect that value
should be around 512, however I am getting peak reading up to
535.
Sensor is very stable and infect when I read exact same sensor
module on Ardunio board I get very stable reading (max 513 with
no load). If I have .1uf capacitor on sensor output the then it gets
slightly better (max 527) but nowhere close to 512. I am using

1 of 30 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.aspx

same VCC and Ground connection for sensor and PIC and using
internal clock.

Circuit attached (made on general purpose PCB) and below is


my code. (I use LED to indicated if my threshold is crossed).

I am struggling for two weeks and looking forward to advise.

/*
* File: main.c
*
* Created on 15 Jan, 2017, 10:04 AM
*/
#include <xc.h>

// Config word
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_ON &
MCLRE_OFF & BOREN_ON & CP_OFF & CPD_OFF);

// Define LED pins


#define LED GP4

//Define Channels
#define AN0 (1<<0)
#define AN1 (1<<1)
#define AN2 (1<<2)
#define AN3 (1<<3)

// ACS712 Sensor
#define MAX_SAMPLE 1000
#define PEAK_THRESHOLD 530

// Define CPU Frequency


// This must be defined, if __delay_ms() or
// __delay_us() functions are used in the code
#define _XTAL_FREQ 4000000

/*

2 of 30 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.aspx

* Function Name: InitADC


* Input(s) : Channel name, it can be AN0, AN1,
AN2 or AN3 only.
* Output(s): none
*/
void InitADC(unsigned char Channel) {
ANSEL = 0x30; // Internal FRC
ANSEL |= Channel; // Select Channel
TRISIO = 0x00; // All Output
TRISIO |= Channel; // Make selected channel
pins input
ADCON0 = 0x81; // Turn on the A/D Converter
CMCON = 0x07; // Shut off the Comparator, so
that pins are available for ADC
VRCON = 0x00; // Shut off the Voltage
Reference for Comparator
}

/*
* Function Name: GetADCValue
* Input(s) : Channel name, it can be AN0, AN1,
AN2 or AN3 only.
* Output(s): 10 bit ADC value is read from the
pin and returned.
*/
unsigned int GetADCValue(unsigned char Channel)
{
ADCON0 &= 0xf3; // Clear Channel selection
bits

switch (Channel) {
case AN0: ADCON0 |= 0x00;
break; // Select GP0 pin as ADC

3 of 30 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.aspx

input
case AN1: ADCON0 |= 0x04;
break; // Select GP1 pin as ADC
input
case AN2: ADCON0 |= 0x08;
break; // Select GP2 pin as ADC
input
case AN3: ADCON0 |= 0x0c;
break; // Select GP4 pin as ADC
input

default: return 0; //Return error, wrong


channel selected
}

__delay_us(25); // Time for Acquisition


capacitor to charge up and show correct value

GO_nDONE = 1; // Enable Go/Done

while (GO_nDONE); //wait for conversion


completion

return (((unsigned int) ADRESH << 8) +


ADRESL); // Return 10 bit ADC value

/*
* Function Name: ReadCurrentSensor
* Input(s) : Channel name, it can be AN0, AN1,
AN2 or AN3 only.
* Output(s): Return 1 if value is more than
PEAK_THRESHOLD, 0 otherwise
*
*/

4 of 30 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.aspx

int ReadCurrentSensor(unsigned char Channel) {


int readValue = 0; //value read from the
sensor
int maxValue = 0; // store max value here
int i;

for (i = 0; i < MAX_SAMPLE; i++) {


readValue = GetADCValue(Channel);
// see if you have a new maxValue
if (readValue > maxValue) {
/*record the maximum sensor value*/
maxValue = readValue;
}
}

if(maxValue > PEAK_THRESHOLD){


return 1;
}

return 0;
}

// Main function
void main() {
LED = 0;
InitADC(AN1);
__delay_ms(500);

while (1) {
__delay_ms(500);
LED = ReadCurrentSensor(AN1);
}
}

5 of 30 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.aspx

Attached Image(s)

Nikolay_Po

Super Member

Total Posts : 1692

Reward points : 0

Joined: 4/1/2012

Location: Russia, Novorossiysk

Status: offline

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


PIC12F675 Sunday, January 29, 2017 9:58 AM (permalink)

Revise the ground connection between Vss (GND) pins. Are you
sure that none currents are flow through the ground wire between
the sensor and PIC Vss?

gailu96

6 of 30 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.aspx

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 Sunday, January 29, 2017 10:14 AM (permalink)

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 Sunday, January 29, 2017 10:19 AM (permalink)

Weydert

7 of 30 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.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 Sunday, January 29, 2017 12:19 AM (permalink)

Hi,
what is the minimum reading of the ADC ?
You could also try a linear regulated 5V supply instead of the
switched mode power supply.

Bob White

Super Member

Total Posts : 193

Reward points : 0

Joined: 11/6/2010

Location: Denver, Colorado

Status: offline

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

8 of 30 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.aspx

PIC12F675 Sunday, January 29, 2017 12:39 AM (permalink)

How are you measuring the dc voltage into the PIC A/D channel?
Are you using a good quality DMM like an Agilent 34401A? If so,
what voltage are you reading?

Have you looked at the sensor output with a scope? Is there any
ripply and noise, especially at mains, or twice mains, frequency?

paulfjujo

paulfjujo

Total Posts : 58

Reward points : 0

Joined: 3/8/2011

Location: France 01700

Status: offline

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


PIC12F675 Sunday, January 29, 2017 1:08 PM (permalink)

hello,

You can use an AOP to have an higher input impedance


connected on the ACS712 output
i used a TLC271 AOP with AOP entry + to do it. and also to
cancel ZERO offset.
you have can have a look (details) Here
To cancel ACS712 noise., a software filter is recommanded to get
a very stable measurement..

9 of 30 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.aspx

Weydert

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 Sunday, January 29, 2017 3:14 PM (permalink)

The ACS712 has an OP-Amp on the output, the output


impedance is already low.
The ACS712 IC has an output for an external filter-capacitor. The
typical capacitance attached to
this pin is 1nF. But you can limit the bandwidth and reduce the
noise by choosing a higher value.
For 47nF for the 30 Ampere device the noise is said to be 7mV
Peak to Peak. ( which is less than 2 bits for a
10bit ADC with 5V reference) But with the 1nF it can be 5 times
this value.
It is not clear whether the noisy ADC readings are due to the
ACS712 noise or due to PIC noise.

Attached Image(s)

10 of 30 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.aspx

SpokaneNexus

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 Sunday, January 29, 2017 4:28 PM (permalink)

I have combined PIC's with the ACS series of parts for a long
time, they work very well together, so there's no question this
CAN work. We just need to figure out what is wrong in your setup.

Note 1: I strongly recommended you use an opamp to buffer


between the ACS and the A/D input. The output impedance of the
ACS is around 1.7K, not exactly a low impedance source. An
opamp will eliminate lots of possible gremlins in this application.
Use a rail to rail output opamp for best results.

Note 2: The ACS712 series is a bidirectional sensor, meaning it


can detect and report current flow in both directions (AC) through
its sense pins. There are other members of the family that are
unidirectional (DC) and you get twice the sensitivity if you're

11 of 30 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.aspx

measuring a DC current. This is the reason you're getting Vcc/2


as the quiescent output level - that's its "zero" output value.

Let's establish that things are actually working the way you
expect them to. What A/D result do you get if you short the A/D
input to ground? How about if you connect it to Vcc? This will
confirm you are actually converting what you think you are.

Next, with the ACS reconnected, short its input sense pins and
see what the A/D reports. This will help eliminate noise as a
potential problem. When those pins are shorted, the ACS should
see no current variation and thus you should see very little output
variation other than noise.

When you're getting these "zero" A/D outputs that are varying the
way you describe, what does an oscilloscope show is the
ACTUAL output signal from pin 7 of the ACS? You may have
some noise there, and depending upon when the A/D samples
and converts this could explain your output values moving around
like they do.

There are ACS versions which are magnetically differential,


meaning they reject external magnetic fields. The ACS712 is
NOT one of those, and I promise you the little Hall Effect sensor
is VERY happy to measure external magnetic fields that have
nothing to do with the current flowing through its sense terminals!
{grin} Make certain you don't have any little magnetic knick-
knacks on the bench... we spent quite a while debugging that
exact problem on a project a while back. Turned out nearby
relays were affecting the measurements when their coils were
engaged!

Check on these items and report back. We'll be glad to help but
we need more data!

gailu96

12 of 30 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.aspx

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 Sunday, January 29, 2017 4:42 PM (permalink)

I have many useful suggestion, let me try them and I will get back
with the results and answers to queries asked on this. Thanks
everyone for providing valuable inputs.

PStechPaul

Super Member

Total Posts : 2053

Reward points : 0

Joined: 6/27/2006

Location: Cockeysville, MD, USA

Status: offline

13 of 30 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.aspx

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


PIC12F675 Sunday, January 29, 2017 7:58 PM (permalink)

It would help a lot to add a resistor from the output of the current
sensor to the filter capacitor. Something like 5k should be good.
You might also check the ADC clock, and perhaps slow it down to
get a more stable reading. Since you are taking a reading only
every 500 mSec, you could use software averaging over multiple
readings. Something like this:

unsigned int AvgCurr=0;


for (i = 0; i < MAX_SAMPLE; i++)
AvgCurr += GetADCValue(Channel);
// see if you have a new maxValue
if (AvgCurr/MAXSAMPLE > maxValue)
/*record the maximum sensor value*/
maxValue = AvgCurr/MAXSAMPLE;
AvgCurr = 0;

You could also avoid the division "/MAXSAMPLE" and use


AvgCurr directly and make maxValue larger according to the
number of samples. So if you have MAXSAMPLE=8, AvgCurr will
effectively be a 13 bit value with a maximum possible value of
8191.

An even better way to do this is to use a timer interrupt to


perform the conversions every 10 mSec and use MAXSAMPLE =
10. This will give a reading averaged over 12 cycles at 50 Hz or
10 cycles at 60 Hz, which will cancel noise from AC mains.

14 of 30 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.aspx

simong123

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 Sunday, January 29, 2017 9:23 PM (permalink)

PStechPaul
You could also avoid the division "/MAXSAMPLE" and use
AvgCurr directly and make maxValue larger according to the
number of samples. So if you have MAXSAMPLE=8, AvgCurr will
effectively be a 13 bit value with a maximum possible value of
8191.

No.
To get n bits of extra resolution you have to average (2^n)^2

15 of 30 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.aspx

samples, for 3 bits you need to average 64 samples.

Edit:-
Well I suppose you do get a 13bit number with 8 samples, but the
extra bits are not significant.

If you stick with a power of 2 number of samples, the just right


shift (by 3 for your case)

post edited by simong123 - Sunday, January 29, 2017 9:28 PM

PStechPaul

Super Member

Total Posts : 2053

Reward points : 0

Joined: 6/27/2006

Location: Cockeysville, MD, USA

Status: offline

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


PIC12F675 Monday, January 30, 2017 0:22 PM (permalink)

Can you explain why you need so many samples to get the extra
resolution? OK, I found the following articles that help explain
this:
http://www.atmel.com/Images/doc8003.pdf
http://electronicdesign.c...-3-self-dithering-adcs
https://en.wikipedia.org/...g-to-digital_converter
https://en.wikipedia.org/wiki/Oversampling

16 of 30 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.aspx

The first and last are the most detailed. It explains that a 2x
oversampling provides 1/2 bit extra resolution. I pretty much
understand the theory, but in reality most 10 bit ADCs probably
do not have sufficient linearity to get any more than 1 or 2 extra
bits of true resolution and probably not even that much extra
accuracy.

Much depends on the randomness of signal noise as well as the


jitter in sampling frequency. It is easy to understand how
averaging two consecutive samples can provide interpolation and
an accurate value for a linearly rising or falling signal, but they
would not provide the correct value if the samples are equally
spaced before and after a peak. But oversampling will certainly
provide a better and more stable reading when there is
considerable noise.

In the OP's case, a Hall effect sensor will likely pick up 50 or 60


Hz power line noise, and samples averaged over an integral
number of cycles will effectively eliminate that noise.

post edited by PStechPaul - Monday, January 30, 2017 0:25 PM

CinziaG

morite

Total Posts : 3144

17 of 30 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.aspx

Reward points : 0

Joined: 12/7/2016

Location: Wien

Status: offline

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


PIC12F675 Monday, January 30, 2017 7:13 AM (permalink)

I would still love to be sure that a multimeter is showing exactly


2.500 so that it can be compared to PIC's reading...
OP did not mention instability of the readout, rather imprecision
(un-precision? )
which could have been due to the impedance issue (but it does
not seem to be the case)
or, as it happened to me with a 18F2553, simply poor linearity
from the ADC...

mi fate schifo, umani di merda.

Mysil

Super Member

Total Posts : 2885

Reward points : 0

Joined: 7/1/2012

Location: Norway

Status: offline

18 of 30 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.aspx

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


PIC12F675 Monday, January 30, 2017 11:17 AM (permalink)

Hi,
Measuring with a multimeter give very little information about
noise in a signal,
just as the OP code of making 1000 measurements and picking
out the single highest peak,
give incomplete information.

OP 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.
Most high resolution multimeters use a sigma-delta ADC with
filtering,
so give completely different information, than the code in
message #1.

Also, it is stated that measurements with a Arduino board give


stable readings,
but there is no information about the algorithm running in the
Arduino.
It might well be a library function with averaging,
which will give completely different information than the one-sided
peak detection in message #1.

Suggestion from Weydert in message #5, to also register


minimum values of ADC measurements,
make sense to me, in order to compare with max values.
Also suggestion to use a linear regulator instead of switched
power supply,
may reduce disturbances from switching noise.

Suggestion from robertwhite, to use an oscilloscope to analyze


noise or ripple, make sense to me.

19 of 30 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.aspx

In addition to ripple at mains frequency, or double of that,


switching noise at much higher frequencies may cause even
more trouble.

Note, that extra filtering in the signal from current sensor to ADC
input,
will not help if there is noise or ripple in Vdd power supply which
is used as reference voltage for the ADC.

Noise in the power supply may be reduced somewhat, by using


pin 6 GP1/AN1/Vref, for reference voltage with extra filtering.
Analog input from the sensor must then be connected to a
different pin.
A way to reduce noise from the microcontroller itself, is to make
the MCU sleep while the ADC is working.

Here are measurements done with a modification of the OP


program.
in addition to max peak value, mimimum reading and calculated
average of each measurement series is listed:

Max Min Average


0202 01F8 01FD
020D 01F5 01FD
0209 01EC 01FD
020F 01ED 01FD
020D 01F9 01FD
0211 01F5 01FD
020D 01EE 01FD
020D 01EE 01FD
020E 01F0 01FD
0208 01FB 01FD
020D 01F6 01FD
FFFF FFFF FFFF FFFF

20 of 30 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.aspx

Three values are stored in EEPROM each time a button


connected to pin 4 GP3/MCLR is pushed.
The Analog signal is just 2 resistors from my scrapbox connected
as voltage divider between Vdd and Vss.

I think the main purpose of oversampling and averaging in this


application,
is to get rid of noise, not to increase resolution.

Regards,
Mysil

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 7:50 AM (permalink)

@Mysil
First of all, I would like to clear aim of project then answer your
queries.

Purpose: We need to know if there is a load connected on AC


Line or not measuring min up to .09 amp (20w LED bulb @ 220V)

21 of 30 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.aspx

without any error (false report). Max AC that can flow is 15A, so
we can not use ACS712-5A that gives 185mv/A. We are using
ACS712-20A that gives 100mv/A. For 10 bit ADC (1024 ssteps)
@ 5V, 1 step = 4.88mV.
To measure .09A i.e. DC volt 9mV we can only tolerate error of
max 2 steps. But we are getting peaks floating around 15-20
steps so we are not able to determine if line is idle or a load is
connected due the noise.

Now coming to your questions.


1.
>>OP 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.
2.
>>Also, it is stated that measurements with a Arduino board give
stable readings,
but there is no information about the algorithm running in the
Arduino and giving reading between 510 to 513 on no load
Below is the arduino code running on Seeeduino V3 board.

void setup(){

Serial.begin(9600);
}

22 of 30 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.aspx

void loop(){
RawValue = analogRead(analogIn);
Serial.print("Raw Value = " );
Serial.print(RawValue);
delay(2500);
}

3.
>>Suggestion from Weydert in message #5, to also register
minimum values of ADC measurements,
make sense to me, in order to compare with max values.
Min values are around 495 with capacitor

4. The code provided is to show to problem. Actually below is the


code that I am using to know if load is connected or not.

int ReadSensor(unsigned char Channel) {


int result = 0, i;

int readValue = 0; //value read from the sensor


int maxValue = 0; // store max value here
int minValue = 1024; // store min value here

23 of 30 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.aspx

for (i = 0; i < MAX_CURRENT_SAMPLE; i++) {


readValue = GetADCValue(Channel);
// see if you have a new maxValue
if (readValue > maxValue) {
/*record the maximum sensor value*/
maxValue = readValue;
}
if (readValue < minValue) {
/*record the minimum sensor value*/
minValue = readValue;
}
}

result = (maxValue - minValue)/2;

if(result < CURRENT_THRESHOLD){


return 1;
}
return 0;
}

I am not sure how averaging will help.

5. The reason for collecting 1000 samples is to ensure that both


min and max peak is captured.

24 of 30 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.aspx

I am not expert in electronics and started learning year back with


arduino boards. I am from Computer Science background and
most of the time do software coding. I do not have sophisticated
equipment to troubleshoot but I though that my schematics and
code is clean enough to get going which seems to be proving
wrong. If my fluke multimeter can't help me I think I should stop
asking on forum and try to figure out myself.

@CinziaG
Yes multimeter does not report exact 2.500, it reports 2.478.
SMPS Output is reported 4.925

post edited by gailu96 - Tuesday, January 31, 2017 8:06 AM

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 7:55 AM (permalink)

Ok, so in theory we should read less than 512, provided PIC's


power and reference is 5V

Then, apart from a still-possible non-linearity of the PIC (see

25 of 30 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.aspx

above), I would focus more on the averaging:

how far apart are the samples you're collecting, i.e. how often is
GetADCValue() called? I'd place some fixed delay in between,
just to be sure;

and, instead of measuring the upper peak and the lower peak
and then averaging between these 2, I'd rather perform a full sum
and average - this may make a difference.

mi fate schifo, umani di merda.

rpg7

Super Member

Total Posts : 1363

Reward points : 0

Joined: 11/7/2003

Status: online

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


PIC12F675 Tuesday, January 31, 2017 10:35 AM (permalink)

From the datasheet of the 12f675:


4: When the device frequency is greater than 1 MHz, the A/D RC
clock source is only recommended if the
conversion will be performed during Sleep.

for a 4MHz clock A/D clock source is recommended as 8 or 16


Tosc.

One MUST always make sure that unused analog input pins are

26 of 30 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.aspx

kept between VDD and VSS at all times. This includes pins that
are set as digital but have analog capability. Voltages that are out
of this range, even by a small amount, can cause A/D
conversions to become wildly inaccurate.

SpokaneNexus

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 11:51 AM (permalink)

gailu96We need to know if there is a load connected on AC Line


or not measuring min up to .09 amp (20w LED bulb @ 220V)
without any error (false report). Max AC that can flow is 15A, so
we can not use ACS712-5A that gives 185mv/A. We are using
ACS712-20A that gives 100mv/A. For 10 bit ADC (1024 ssteps)
@ 5V, 1 step = 4.88mV. To measure .09A i.e. DC volt 9mV we
can only tolerate error of max 2 steps. But we are getting peaks
floating around 15-20 steps so we are not able to determine if line
is idle or a load is connected due the noise.

Do you need to accurately measure current flow all the way up to


15A? Or just tolerate current that high, while actually needing

27 of 30 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.aspx

more resolution at far lower currents?

Carefully reading what you wrote, it sounds like you need to


somewhat accurately measure a small load (~90mA). And you
probably want to *know* if there's a larger load (up to 15A) but
may not need sub-100mA accuracy if the current is 15A. Is that
accurate?

If so, I'd suggest using the buffer opamp I recommended earlier


to scale the output of the ACS so that you get more resolution in
the range you actually care about. This means your input will
"saturate" well before 15A, but you'll still know there is current
flowing and you'll get far more resolution in the low current ranges
that apparently matter most.

Also, keep in mind that while you are measuring AC, you do not
HAVE to use a bidirectional version of the ACS family. The
connection through the ACS is almost a pure short and will
happily pass current both ways (so your load won't care), but
using a unidirectional version will double your sensitivity
immediately. This will also base your measurement signal nearer
0V, making it easier to further optimize that analog signal to take
maximum benefit of your A/D's input range.

Edit: For example, the ACS723LLCTR-10AU-T would increase


your sensitivity to 400mV per amp of current. Your 90mA thus
represents 36mV, which is 7 LSB's - an improvement, but in my
opinion that's still far too little for reliable operation. So I'd scale
that with an opamp. If your target load is 90mA, let's presume you
want to accurately measure currents up to 1000mA (over 10x
your target value, lots of headroom). This means you could use
an opamp with a gain of 10. Now you'd have sensitivity of 4V per
amp of current flow, dynamic range of 0-1A, you'd still know about
current beyond 1A (because the A/D would saturate), and your

28 of 30 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.aspx

target current flow would present 360mV to the A/D. That's 70


LSB's, over 6% of full scale, and now you're starting to give your
A/D a more reasonable S/N ratio. Note you can scale this
further... if you only need to accurately measure currents up to,
say, 200% of your expected load you can use more gain to
improve your S/N even more.

As to the question of running more current through the ACS than


the specific part is designed to measure: The ACS leadframe is
spec'd for 80A peaks. I can't find that appnote right now, but we
use these devices continuously on motors that draw 70A+ inrush
currents so we made certain. You can flow more than the
specified current, all that happens is the output saturates.

In short, I think you would benefit from giving more thought to the
circuitry before you try to fix things in firmware. Decide the current
ranges where you really, honestly need high resolution; take
advantage of the fact that for a symmetrical AC current waveform
you really only need to measure one half of the waveform; and
optimize your hardware to feed a more ideal signal to the A/D.
THEN do what is necessary in the firmware.

Hope this helps!

post edited by SpokaneNexus - Tuesday, January 31, 2017 12:33


AM

SpokaneNexus

Super Member

Total Posts : 386

29 of 30 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.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 11:59 AM (permalink)

gailu96To measure .09A i.e. DC volt 9mV we can only tolerate


error of max 2 steps.

To be more clear: Unless you're building a lab-grade instrument,


it's probably unrealistic to expect +/-2 LSB accuracy. 90mA is just
0.6% of 15A... you're trying to base a go/no-go decision on sixth-
tenths of a percent of full scale, which by definition is surrounded
by 60Hz AC and who knows what other sources of noise.

That's why I'm recommending you re-evaluate how you're


managing the analog signal before it hits the A/D. You need a
change that represents far more than 2 LSB's to have reliable
operation. Simply stated, you're trying to measure too small a
change... it's down near your likely noise floor and you'll have
variation unit to unit that will be frustratingly unreliable.

Measuring 90mA isn't the problem. The problem is trying to


measure 90mA in a dynamic range of 15,000mA. You need to
rescale those numbers so the A/D has better S/N to work with.

30 of 30 02/11/2018 11:26

Anda mungkin juga menyukai