Accelerometer MMA7361 incorrect values adc
Topic last updated
29 May 2011, by
Andrew Cook.
5 replies
accelerometer,
adc
So I'm trying to sample data from an MMA7361 triax accelerometer at 100Hz.
I've managed to interface with the accelerometer, and I got it sampling at 100Hz, however I'm getting values that confuse me.
I am measuring 1.65V at the pin from the triax, however when I sample this pin using x = accelerometer.getAccelX(); i get a value of 0.02.
It's my understanding that this should actually be 4.74, as x = ((xout * 3.3)-1.65)/0.8;
The important parts of the code are:
#include "Accelerometer.h"
...
Accelerometer accelerometer(p15, p16, p17, p18, p19, p20);//MMA7361 Initialization
...
float * acquire_triax() {
float accel[3];
accel[0] = accelerometer.getAccelX();
accel[1] = accelerometer.getAccelY();
accel[2] = accelerometer.getAccelZ();
printf("X: %5.3f Y: %5.3f Z: %5.3f\n",(accel[0]),(accel[1]),(accel[2]));
return (accel);
...
If anyone is able to help, it'd be greatly appreciated.
Replies
Hi, Andrew
Acceleration means speed change. So a value near zero means there is no acceleration.
The library converts your 1.65V value into 0 acceleration. Check datasheet of MMA7361, page 6.
In your example at least one of axes should have an output value different from 1.65V.
Earth's gravity has this effect.
The equation of the accelerometer is (depending on g-range):
Uout = a [m/s^2] * 0.800 [V] + 1.65 [V] ... for 1.5g range
Uout = a [m/s^2] * 0.206 [V] + 1.65 [V] ... for 6g range
Therefore
a [m/s^2] = (Uout[V] -1.65 [V]) / 0.800[V] ... for 1.5g range
a [m/s^2] = (Uout[V] -1.65 [V]) / 0.206[V] ... for 6g range
So, your 1.65V output yields to a = (1.65 - 1.65) / 0.8 => a = 0 whichever the g-range.
Hope, that helped.
Regards.
Hi Andrew, i think you make a small calculating/thinking error.
1.65v at analog in gives an result of 1.65/3.3=0.5 ( range 0.0 .. 1.0 where 1.0 eq 3.3v)
xout=0.5 > ((0.5*3.3)-1.65)/0.8=0 ! so i think this is the right value.
maybe try first show the raw measured data.
I wonder why there is no offset and gain variabele in the analog in function because everyone needs that calculation.
Your answer X=(analogin-offset)*gain where offset = 1.65/3.3v and gain= 1/0.8 what gives the same result.
succes
I agree with you that that's what I'm getting, but Accelerometer.cpp contains:
00001 #include "Accelerometer.h"
00002
00003 Accelerometer::Accelerometer(PinName xoutPin, PinName youtPin,PinName zoutPin,
00004 PinName sleepPin, PinName zeroGDetectPin, PinName gSelectPin) :
00005 xout(xoutPin), yout(youtPin), zout(zoutPin), zeroGDetect(zeroGDetectPin),
00006 sleep(sleepPin), gSelect(gSelectPin), zeroG(zeroGDetectPin) {
00007 sleep = 1; // normal mode
00008 gSelect = 0; // 1.5G mode
00009 scale = 0.8;
00010 }
00011
00012 float Accelerometer::getAccel() {
00013 float x = getAccelX();
00014 float y = getAccelY();
00015 float z = getAccelZ();
00016 return sqrt(x * x + y * y + z * z);
00017 }
00018
00019 float Accelerometer::getAccelX() {
00020 return ((xout * 3.3) - 1.65) / scale;
00021 }
00022
00023 float Accelerometer::getAccelY() {
00024 return ((yout * 3.3) - 1.65) / scale;
00025 }
00026
00027 float Accelerometer::getAccelZ() {
00028 return ((zout * 3.3) - 1.65) / scale;
00029 }
So the output should be: ((1.65*3.3)-1.65)/0.8 = 4.74
Or am I still missing something simple?
Yes Andrew, you or I are missing something :)
the acceleration at this moment is 0 or not ? so your answer should be 0 ?
your formula is right but your interpretation fails i think
the value of xout for a voltage at p15 from 1.65v is 0.5 ( while the full scale of 3.3 volt gives a result of 1.0 in the variabele xout).
When xout=0.5 than must the offset also 0.5 and the gain 1/0.8=1.25
((xout-offset)*gain > (0.5-0.5)*1.25=(0.5-0.5)/0.8=0 , so 0.02 is 1.666 volt
or in your formula:
((1.65*3.3)-1.65)/0.8 = 4.74
((0.5 *3.3)-1.65)/0.8 = 0
((0.5048*3.3)-1.65)/0.8=0.0198 and thats your 0.02
Thats the reason that i advise you first look at the raw data from xout than you see that your xout=0.5 .
I hope you see the point because its very difficult for me to bee clear in my bad english
Ah of course.
That makes sense now. Should look at the data for what it is, not what I want it to be.
Thanks
Please log in to post a reply.
So I'm trying to sample data from an MMA7361 triax accelerometer at 100Hz. I've managed to interface with the accelerometer, and I got it sampling at 100Hz, however I'm getting values that confuse me. I am measuring 1.65V at the pin from the triax, however when I sample this pin using x = accelerometer.getAccelX(); i get a value of 0.02. It's my understanding that this should actually be 4.74, as x = ((xout * 3.3)-1.65)/0.8; The important parts of the code are:
#include "Accelerometer.h" ... Accelerometer accelerometer(p15, p16, p17, p18, p19, p20);//MMA7361 Initialization ... float * acquire_triax() { float accel[3]; accel[0] = accelerometer.getAccelX(); accel[1] = accelerometer.getAccelY(); accel[2] = accelerometer.getAccelZ(); printf("X: %5.3f Y: %5.3f Z: %5.3f\n",(accel[0]),(accel[1]),(accel[2])); return (accel); ...If anyone is able to help, it'd be greatly appreciated.