CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Offsetting Accelerometer outputs
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Matro
Guest







PostPosted: Tue Apr 08, 2008 11:14 am     Reply with quote

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

View user's profile Send private message

It's 3:29Am here!
PostPosted: Tue Apr 08, 2008 6:12 pm     Reply with quote

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!
PostPosted: Wed Apr 09, 2008 1:58 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
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