View previous topic :: View next topic |
Author |
Message |
Rob_975
Joined: 14 Aug 2012 Posts: 16
|
Current Sensor ADC scaling. |
Posted: Sun Dec 01, 2013 3:57 am |
|
|
Hi all.
I'm using an ACS713 as current sensor with a 18F67k22 @ 12bit res.
I don't have any clue about how to calculate the scaling factor to get the right Ampere reading.
As per specs. this sensor has a 0.5V output @ 0Amps.
I tryed some kind of formulas that looked "barely" correct to but the outcome was completely wrong.
Cheers. |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Sun Dec 01, 2013 4:16 am |
|
|
Not that difficult. First work out the offset, 0.5v *4096/5v = 410. Now this get deducted from any ADC value you measure. If your current are 10A then the ADC value will be 0.5V + 10A * 185mV/A (for the 20A version) = 2.35V or 1925 digital. Less your offset of 410 gives 1515. Convert back to amps 1515 * 5V/4096 / 0.185= 9.997 Amps. Use this with scaled integers discussed on this forum a couple of times and you don't have to use floats.
Regards |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Dec 01, 2013 5:14 pm |
|
|
A bit of analog processing to zero the offset AND expand the input
ADC range of the PIC-- to your expected current range --
will extract the maximum usability from your design too.
Subtracting a presumed zero-I offset and lack of analog span control
actually makes the LEAST of the 12 bits you have.
Being able to apply 4095 steps to the expected range, and fully utilize
the ADC will be the best outcome, neh ??
SO....
what is the expected RANGE of current you wish to measure? |
|
|
Rob_975
Joined: 14 Aug 2012 Posts: 16
|
|
Posted: Mon Dec 02, 2013 2:38 pm |
|
|
OK, thank you very much guys.
Problem solved by means of Alan's formula and a few of small adjustments because of the components tolerances.
ASMboy, cant change the design, I already have the PCB with all the components on it.
It's a speriemental board that I designed to make experiements.
The ACS goes to a opamp buffer and then to the Pic's ADC.
The voltage reference is a 4.096V ref. generator.
The maximum current I would like to measure is 10A.
With the code I'm gonna share with you, the error of the system is 0.01A along the range 0-2A. My psu cant supply more than that on a load of 8ohm.
Code: | void read_analog(){
int i;
int16 value;
current=0;
for (i=0;i<=63;++i) {
set_adc_channel(8);
delay_ms (10);
value=read_adc();
current=(value+current);
}
current=(current/64)-516;
current=current* 4.091/4096 / 0.186;
} |
The code can be indeed optimised but its working well.
Cheers. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Dec 02, 2013 3:07 pm |
|
|
i sure hope the VAR 'current' is an int32
Code: |
current += read_adc();
|
in CCS the above also works with fewer wasted cycles
and this snippet my be of use to you as well
http://www.ccsinfo.com/forum/viewtopic.php?t=50320
Last edited by asmboy on Wed Dec 04, 2013 10:14 am; edited 1 time in total |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Dec 02, 2013 7:17 pm |
|
|
If you are only looking at one channel, you can set the adc channel outside the loop which eliminates that and the following delay from the inner loop.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Rob_975
Joined: 14 Aug 2012 Posts: 16
|
|
Posted: Wed Dec 04, 2013 1:53 pm |
|
|
asmboy wrote: | i sure hope the VAR 'current' is an int32
Code: |
current += read_adc();
|
|
No, it's an float.
Why? |
|
|
Rob_975
Joined: 14 Aug 2012 Posts: 16
|
|
Posted: Wed Dec 04, 2013 1:54 pm |
|
|
gpsmikey wrote: | If you are only looking at one channel, you can set the adc channel outside the loop which eliminates that and the following delay from the inner loop.
mikey |
Ok, corrected.
Thanks. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Dec 04, 2013 5:13 pm |
|
|
"No, it's an float. "
since you are always adding INTEGER ADC readings
in that variable -
make it an INT32 as FLOAT takes MANY more machine cycles
to to an "add" than an integer32 .....
only convert to a FLOAT if you need to do decimation fractional output |
|
|
ruth
Joined: 14 Apr 2014 Posts: 11
|
|
Posted: Tue Apr 15, 2014 10:31 am |
|
|
Alan, i had read your reply for the post of Current Sensor ADC scaling. Can u explain aboutt the "Less your offset of 410 gives 1515." Why 410 will give 1515? I am using LTS 15NP current sensor and i am trying to get back the ampere from the voltage output of the sensor. Thank for your concern Smile |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Tue Apr 15, 2014 10:59 am |
|
|
The LTS 15NP outputs 2.5V @ 0Amp, that will be your offset.
If current positive it will add 41.6mV for each ampere that flow through the sensor, similarly will subtract 41.6mV for each ampere.
So work out what your ADC reading will be @ 2.5V and that is what I call the offset, it is fixed throughout your calculations.
Meaning if you read 2.5416V (Nice ADC this ) work out what your ADC reading will be. If you subtract the offset from this it will give you a result 41.6mV in digital format (the value depends on the resolution of your ADC) which equals 1A.
Regards |
|
|
|