Problem in raising output rate of kx132 accelerometer

Hi there. I’ve been playing with the kx132 accelerometer and I want to speed up the sampling rate but I don’t know how to do it.

Here’s something I tried (and failed):
I used the arduino example code and used the following, but it didn’t work.

kxAccel.setOutputDataRate(1000); // Default is 50Hz

I checked the imported cpp source code and saw something like this:

bool QwDevKX13X::setOutputDataRate(uint8_t rate)
{
if (rate > 15)
return false;

So I tried number greater than 15, say 20, and the output rate stayed around 50hz, which makes sense.
but when i tried number not greater than 15, say 15, i got something like 250hz.

I tried to remove the if block. And then for every number I entered it just gave me a random output rate, no more than a few hundreds.

I also tried adjusting the delay(). Nothing changed

I’m using a Sparkfun Logic Level PCA9306, which only supports I2C, and then an Arduino Leonardo. Besides the Arduino example code (example1, basic reading), I also used a Python code to store the data. My goal is to maximun the output rate to the claimed 10kHz.

Any advice or experience would be greatly appreicated.
Thank you!

Instead of using the library’s setOutputDataRate(), directly write the desired ODR setting to the CNTL1 register (0x1B) and see if it works.

For example, to set 6.4 kHz, you need to write 0x0D to the CNTL1 register.

Thanks!
Can you please specify how to do this? In which file can I find CNTL1 register (0x1B)?

Hi @violette ,

The Output Data Rate is set by the four OSA bits in the ODCNTL (0X21) register, not the CNTL1 register. That is why setOutputDataRate is limited to 15.

The Technical Reference Manual has more information.

Best wishes,
Paul

Thanks for the information!
I tried setting setOutputDataRate to 14 and 15 and they all gave me ~200hz. I used a python code to extract the data, could this be the bottleneck?

Hi @violette ,

SPI will give you better results than I2C.

On I2C, use 400kHz (Wire.setClock(400000);) to speed up the data transfers.

For the best results, you will need to use interrupts. Use the code in routeHardwareInterrupt to route the data ready bit to one of the interrupt pins. Read the accel data when you receive the interrupt. This is much more efficient that reading (polling) data ready over I2C / SPI.

I hope this helps,
Paul

1 Like