Documente Academic
Documente Profesional
Documente Cultură
aspx
microchip.com
gailu96
New Member
Total Posts : 11
Reward points : 0
Joined: 3/1/2016
Location: 0
Status: offline
Hi Experts,
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.
/*
* 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 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
/*
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: 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
/*
* 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
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
Reward points : 0
Joined: 4/1/2012
Status: offline
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
gailu96
New Member
Total Posts : 11
Reward points : 0
Joined: 3/1/2016
Location: 0
Status: offline
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
Reward points : 0
Joined: 7/2/2008
Location: Aachen/Germany
Status: offline
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
Reward points : 0
Joined: 11/6/2010
Status: offline
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
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
Status: offline
hello,
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
Reward points : 0
Joined: 7/2/2008
Location: Aachen/Germany
Status: offline
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
Reward points : 0
Joined: 2/5/2013
Location: 0
Status: offline
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.
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
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.
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
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
Reward points : 0
Joined: 6/27/2006
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
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:
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
Reward points : 0
Joined: 2/7/2012
Status: offline
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
Edit:-
Well I suppose you do get a 13bit number with 8 samples, but the
extra bits are not significant.
PStechPaul
Super Member
Reward points : 0
Joined: 6/27/2006
Status: offline
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.
CinziaG
morite
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
Mysil
Super Member
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
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.
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
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.
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
Regards,
Mysil
gailu96
New Member
Total Posts : 11
Reward points : 0
Joined: 3/1/2016
Location: 0
Status: offline
@Mysil
First of all, I would like to clear aim of project then answer your
queries.
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.
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
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
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
@CinziaG
Yes multimeter does not report exact 2.500, it reports 2.478.
SMPS Output is reported 4.925
CinziaG
morite
Reward points : 0
Joined: 12/7/2016
Location: Wien
Status: offline
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
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.
rpg7
Super Member
Reward points : 0
Joined: 11/7/2003
Status: online
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
Reward points : 0
Joined: 2/5/2013
Location: 0
Status: offline
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
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.
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
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.
SpokaneNexus
Super Member
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
30 of 30 02/11/2018 11:26