MMA8451q ODR question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MMA8451q ODR question

1,894 Views
samuelsiegel
Contributor I

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:

while(1){

   get_Data_From_Fifo_If_Full();

   if(unprocessed_data){

      process_1_sample();

      samples_counter++;

   }

   if(samples_counter==400){

      print_something;

      samples_counter=0;

   }

}

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.

Thanks.

Labels (1)
Tags (2)
0 Kudos
Reply
4 Replies

1,478 Views
samuelsiegel
Contributor I

PROBLEM SOLVED:

Per AN4073, Section 4.3:

   Note: F_MODE must be equal to 00 when changing the F_READ bit to change between 8-bit or 14-bit data. Also the part    must be in Standby mode

I was turning on my FIFO before setting the F_READ bit, meaning I wasn't entering F_READ mode.

Yup.

0 Kudos
Reply

1,478 Views
samuelsiegel
Contributor I

I've discovered what's going on.  The "Fast Read" option doesn't appear to be working.  Especially noisy data, combined with this double-speed problem, led me to test what the data looked like if I treated it as though it were 14-bit data.  Suddenly, it's much less noisy and FFT plots actually make sense.

My method for tracking my number of samples processed worked by counting bytes processed.  Since I was expecting 1-byte data, this effectively halved my apparent sampling period (since the accelerometer was pushing out data in 2-byte chunks).

So, that leads to another problem - Why isn't fast read working?  Has that happened for anybody else?

Thanks,

Sam

0 Kudos
Reply

1,478 Views
samuelsiegel
Contributor I

Diego,

Thanks for the reply.  No, I don't expect the FIFO to fill in 2.5 ms.  I expect (if my sample rate is set to 400 Hz) to pull 400 samples from the FIFO in approximately 1 second.  The results I'm getting have me pulling 400 samples from the FIFO every half a second.  My assumption was that, with the FIFO enabled, those data points that are available at the output every 2.5 ms are instead put into the FIFO at that rate.  And so can be pulled from the FIFO at approximately that same rate as well.  Am I wrong?

My main loop structure is as follows:

1) Check the accelerometer to see if the FIFO is full.

   1a) if it is, pull all the data from the accelerometer FIFO into my own local FIFO.

2) If there's data in my local FIFO, process it, one sample at a time

   2a) For each sample processed, increment a sample counter

3) If my sample counter reaches 400, flip the state of an output pin and reset my sample counter

4) Restart loop

I've attached a screenshot from Logic capturing the state of that output pin:

pastedImage_2.png

As you can see, the state of the pin changes approximately every 500 ms, meaning I'm processing 400 samples in that time, meaning the accelerometer is outputting data at approximately 800 Hz.

I'm fairly confident of my settings (posted above), the relevant one being my setting for Control Register 1 (0x0B - Fast Read, 400 Hz ODR, Enable chip), but there may be something I'm missing.

Any further help would be highly appreciated.

Thanks,

Sam

0 Kudos
Reply

1,478 Views
diegoadrian
NXP Employee
NXP Employee

Hello Samuel,

Thank you for writing.

I think that you are misunderstanding, how the FIFO works.

The 400 Hz from the ODR, is not saying that the FIFO is going to be filled in 2.5 ms. The 400 Hz from the ODR says that you are going to have every 2.5 ms, a value on the MMA8451 output.

In this application note, you could find more information about the FIFO.

http://www.nxp.com/assets/documents/data/en/application-notes/AN4073.pdf

Furthermore, I made an example code, where the results are similar from the application note.MMA8451 FIFO 400 hz ODR.png 

I attached the code.

I am using the FXOS8700. But practically, the accelerometer is the same. The only difference is that, the FXOS8700 also has a magnetometer.

I hope this information will be useful for you.

Best Regards,

Diego.

P.S.

I used the FRDM-K64.

0 Kudos
Reply