|
|
View previous topic :: View next topic |
Author |
Message |
Matro Guest
|
|
Posted: Tue Apr 08, 2008 11:14 am |
|
|
Since the "res" variable represents nothing "real" even in its value, the ">>4" is not needed because proportionality will be respected even without.
And it will avoid a loss of precision.
Now the question is : does this code works?
Matro |
|
|
kein
Joined: 23 Jul 2007 Posts: 103
|
It's 3:29Am here! |
Posted: Tue Apr 08, 2008 6:12 pm |
|
|
Thanks matro. My previous code works and because I've modified the it as per your contribution, I've not tested it yet. It's 3:29AM here now and I'm very heavy eyed. I'll test it tomorrow and comeback to you.
Just lil clarification if I'm summing readings 16 times
"
for(i = 0; i < 16; i++)
{
Quote: | res += (signed int16)(read_adc()^ 0x0200); |
}
return (res = res>> 4) //return average
"
won't it be wise to get the average? In doing this, I'm trying to mimmick a running average filter to remove noise. |
|
|
Guest
|
Re: It's 3:29Am here! |
Posted: Wed Apr 09, 2008 1:58 am |
|
|
kein wrote: | Thanks matro. My previous code works and because I've modified the it as per your contribution, I've not tested it yet. It's 3:29AM here now and I'm very heavy eyed. I'll test it tomorrow and comeback to you.
Just lil clarification if I'm summing readings 16 times
"
for(i = 0; i < 16; i++)
{
Quote: | res += (signed int16)(read_adc()^ 0x0200); |
}
return (res = res>> 4) //return average
"
won't it be wise to get the average? In doing this, I'm trying to mimmick a running average filter to remove noise. |
I understood what you are doing. ;-)
But once again, the values that you read thanks are digital integer values that don't represent (in their digits) the "real" value.
So divide it by 16 (equivalent to >>4) is a loss of accuracy and changes almost nothing.
It is interesting if you compare this result with only ONE acquisition fo ADC.
But if you always work with "average" value so it is the same thing but saving execution time and accuracy.
To take the filter example.
If the >>4 is present, you have an average filter (16 values) but with a limited resolution.
If it is not present, you have an average filter (16 values) with a 16x amplification with full resolution.
I take an example, imagine 3 situation.
1 - the adc result is always 0x0003
2 - the adc result is once 0x0003 and once 0x0004 and so on
3 - the adc result is once 0x0003 and three times 0x0004 ans so on
#With the >> 4
1 - res = 16*0x0003 >> 4 = 0x0003
2 - res = (8*0x0003+8*0x0004) >> 4 = 0x0003
3 - res = (4*0x0003+12*0x0004) >> 4 = 0x0003
#Without the >> 4
1 - res = 16*0x0003 = 0x0030
2 - res = (8*0x0003+8*0x0004) = 0x0038
3 - res = (4*0x0003+12*0x0004) = 0x003C
We can see that in the 2nd case the accuracy and resolution is definitely better.
And you don't care about the "pure" value since when adc gives 0x0003, the "3" is nothing "real" but just 0x0003/0x03FF of the full range.
Do you understand what I mean?
Matro. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|