AnsweredAssumed Answered

MMA8451q ODR question

Question asked by Samuel Siegel on Jan 4, 2017
Latest reply on Jan 12, 2017 by Samuel Siegel

This is probably me missing something dumb...

I'm using the following settings for my accelerometer:


{ MMA8451q_CTRL_REG1, 0x00}, //Ensure Standby Mode
{ MMA8451Q_F_SETUP, 0x40 }, //FIFO on, circular buffer
{ MMA8451q_XYZ_DATA_CFG, 0x12 }, //8G Full Scale, HPF data enabled
{ MMA8451q_HP_FILTER_CUTOFF, 0x03}, //2 Hz cutoff, just removing gravity
{ MMA8451q_CTRL_REG2, 0x02}, //High Resolution mode
{ MMA8451q_CTRL_REG1, 0x0B}, //400 Hz ODR, Fast read, Enable chip


So, that's FIFO on, circular buffer, 400 Hz ODR, Fast Read mode.


My main loop looks something like this:














That's obviously pseudo-code, and not everything I'm doing, but it gets the idea across.  I check whether the FIFO is full each loop, pull it all in a burst if it is, process one sample per loop (my per-sample processing time is an order of magnitude faster than the accelerometer's sampling period), increment a processed-samples counter, and print something if I've processed 400 samples since the last print.

Looking at that, you'd think I'd get to that call to "print_something" approximately once per second - 400 Hz ODR (which I assume is the sample rate), print every 400 samples.

What happens is that I get to that print_something call 2 times per second.  Meaning I have an apparent ODR of 800 Hz (400 samples received in 1/2 a second = 800 samples per second).


I've checked the timing on all the various function calls and processing I'm doing, and everything is fast enough that I'm fairly certain I'm not missing any samples, but even if I were, that would make the "sample_counter" variable take longer to reach 400 than 1 second, wouldn't it?


So, what am I missing?

Feel free to ask follow-up questions if you need more info.