View Single Post
  #6   Spotlight this post!  
Unread 03-02-2010, 10:46
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: 2010 Accelerometer I2C Object/Class

Quote:
Originally Posted by Geek 2.0 View Post
I'm not 100% sure, but by the looks of it (after reading the datasheet), it looks as if you're only taking the least significant byte when reading an axis. Wouldn't that give you a bad number? Again, I'm not sure.

Also, did this code work? I didn't see anything wrong with it.
Code worked fine in my testing.

If you look at the getAxis method you will see that I am doing a 2-byte read when I get the data (2 consecutive registers in one read). This insures that the data does not get corrupted. If two individual 1-byte reads were performed there is a chance that in between the first and second read the data could change. This would result in first read getting the low byte of the prior value and second read getting the high byte of the subsequent value. Putting the two together again could create some really funny numbers. See page 18 of the ADXL345 data sheet "Register 0x32 to Register 0x37" section for more information about this.

Here is an example of the problem: prior value is 0x0100 subsequent value is 0x00ff, a 1 bit change. Two single byte reads would read low byte 0x00 and high byte 0x00 giving 0x0000. No where near close to what the sensor is actually reading.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010

Last edited by charrisTTI : 03-02-2010 at 10:56.
Reply With Quote