SCA3000 triple axis digital interface accelerometer
Revision 1:f5f2e79304fb, committed 2011-06-09
- Comitter:
- aberk
- Date:
- Thu Jun 09 14:29:16 2011 +0000
- Parent:
- 0:fe041345c169
- Commit message:
- Added functionality for getting the acceleration values in raw counts as opposed to milli-gs.
Changed in this revision
| SCA3000.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SCA3000.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SCA3000.cpp Sun May 29 14:13:20 2011 +0000
+++ b/SCA3000.cpp Thu Jun 09 14:29:16 2011 +0000
@@ -73,6 +73,12 @@
float SCA3000::getAcceleration(int axis) {
+ return getCounts(axis) * 0.75;
+
+}
+
+int SCA3000::getCounts(int axis){
+
int acceleration = 0;
int axis_lsb = 0;
int axis_msb = 0;
@@ -107,30 +113,22 @@
}
- acceleration = ( axis_msb << 8 | axis_lsb );
-
- return countsToMg(acceleration);
-
-}
-
-float SCA3000::countsToMg(int counts){
-
- float acceleration = 0.0;
-
+ int counts = ( axis_msb << 8 | axis_lsb );
+
//If this looks like nonsense it's because
//the datasheet is completely wrong.
if(counts & 0x8000){
counts = (counts >> 3) & 0x1FFF;
- counts = (~counts & 0x1FFF)+ 1;
- acceleration = counts * -0.75;
+ counts = (~counts & 0x1FFF) + 1;
+ acceleration = counts * -1;
}
else{
counts = (counts >> 3) & 0xFFF;
- acceleration = counts * 0.75;
+ acceleration = counts;
}
return acceleration;
-
+
}
int SCA3000::oneByteRead(int address) {
--- a/SCA3000.h Sun May 29 14:13:20 2011 +0000
+++ b/SCA3000.h Thu Jun 09 14:29:16 2011 +0000
@@ -85,13 +85,24 @@
/**
* Get the register contents acceleration value for the
- * given axis.
+ * given axis, using the nominal sensitivity values
+ * found in the datasheet.
*
* @param axis The axis to get acceleration values for.
*
* @return The acceleration on the specified axis in mg.
*/
float getAcceleration(int axis);
+
+ /**
+ * Get the register contents acceleration value for the
+ * given axis, in counts.
+ *
+ * @param axis The axis to get the counts values for.
+ *
+ * @return The acceleration on the specified axis in counts.
+ */
+ int getCounts(int axis);
private:
@@ -100,16 +111,6 @@
DigitalOut nR_;
/**
- * Converts the contents of acceleration registers (MSB << 8 | LSB)
- * to mg.
- *
- * @param counts The contents of acceleration registers.
- *
- * @return The acceleration in mg.
- */
- float countsToMg(int counts);
-
- /**
* Read one byte from a register on the device.
*
* @param address Address of the register to read.
SCA3000 Digital Accelerometer