ericalbers / ICM20948_DMP_Arduino

Invensense 20948 chip working with DMP code for Arduino environment
41 stars 10 forks source link

Sample rate and ODR #4

Open romatou18 opened 4 years ago

romatou18 commented 4 years ago

HI Eric,

First of all congratulation on the really good working porting this TDK lib to ESP32 arduino, to say the least their code is not the most concise and readable.

I tried it somehow succefully-ish with esp32 but everytime i tried setting the ODR Output data rate it did not seem to do anything, kept outputing i.e. ACCELEROMETER or GYROSCOPE DMP events at 5Hz. I'd like to take it up to 50, 112 or 225HZ if possible.

I tried using the inv_device_set_sensor_period_us() or inv_device_set_sensor_period() methods but after adding timing code using the events timestamps, it kept telling me taht the period was +/- 200ms so 5HZ.

Have you tried changing it ? When using the DMP it doesn't seem to change a thing, while the application note manual says that it should and it is up to the user to verify that the value change was effective.

THanks !

romatou18 commented 4 years ago

So far my findings are the following:

/eMD_ICM20648_20948_Discovery_v1_3/eMD_ICM20648_20948_v1_3/emd-ICM20648-20948-stm32f4xx-1.3.0.rc1/emd-ICM20648-20948-stm32f4xx-1.3.0.rc1/embedded-motion-driver/Mems/dmp3a/dmp3Default_20648.c

To find that : 1) inv_set_odr() inv_error_t inv_set_odr(unsigned char androidSensor, unsigned short delayInMs) is called from main.c when a command is entered to change the data rate

2) This sets the array inv_dmp_odr_delays[ >>>SENSOR_ID<<<] = delayInMs; i.e. inv_dmp_odr_delays[INV_SENSOR_WAKEUP_NINEQ] = delayInMs;

3) calls inv_set_hw_smplrt_dmp_odrs() that takes this array and then 4) calls the following helper: DividerRateSet() i.e. result |= DividerRateSet (MinDelayGen (MinDelayGenAccel2List), hw_smplrt_divider, INV_SENSOR_ACCEL);

that finally calls

5) dmp_set_sensor_rate() i.e. Result |= dmp_set_sensor_rate(InvSensor, (DmpOdrDivider - 1));

6) which I have identified to be matching the following in your code base: int dmp_icm20948_set_sensor_rate(struct inv_icm20948 * s, int sensor, short divider);

Therefore I guess this helper needs to be called during the setup of the device somehow to set the ODR rate... Need to test that...

stefanodemartini commented 4 years ago

Hi Romatou, di u tested you guess? Do you have any result about it?

Cheers

romatou18 commented 4 years ago

Unfortunately not! My only icm20948 chip has died i don't know why, and given the lockdown I'm not gonna get one soon from a shop. I know a business in my town that has the chip without a breakdown board, and has suggested they can solder it in my breakout. I'll try that and keep you posted if it works... For now sadly im back working with the MPU9250.

stefanodemartini commented 4 years ago

:-) I own 2 of them and i'm struggling to raise that output which is around 5 HZ for me too. May you suggest me how and where you would modify ODR settings? May be i can try for u. Thanks in advance.

romatou18 commented 4 years ago

Been struggling too, tried in a couple of different ways before, also went through lots of blogs and the official datasheet and application notes.

The bottom line is that the demo code is not very well documented, there is the SDK ehich is now 4-5 years old, not maintained either, and not on git or similar proper repository.

Compare it to the Bosch/Hillcrest sensors i.e. BN0080 that i have ordered too for this reason: the code is on git, plenty of examples, and the official website proposes the free version, and the commercial version with even more features and support. Clearly TDK does not care about the Iot market, only about the big players like the mobile phone manufacturers that sell millions if unit.

I will send you the code i wanted to try when i can this weekend.

romatou18 commented 4 years ago

The code simplicity of the Bosch Hillcrest sensor BNxxx or BMXxxx is just no match, these are two or 3 times the price of the TDK, but that is the price to pay for good support for individual and low volume customers like us all here in the IOT sphere. As far as I'm concerned if the Bosch works with good results I'll never waste my time again on getting the ICM to work. I'd rather focus on interesting issues like creating a nice device instead.

stefanodemartini commented 4 years ago

rc = inv_icm20948_set_sensor_period(&icm_device, idd_sensortype_conversion(INV_SENSOR_TYPE_LINEAR_ACCELERATION), 5);

Set ODR as desided for the sensor desided

romatou18 commented 4 years ago

Hry Stefani,

Grazie mille for that.

I have been iff my project for a bit and totally omitted to send you my cide, i am really sorry !

I need to check but the method you mention i am almost sure i tried it before but without the expected result and success.

I have just received 2 new sensors 2days ago! At the same time as your comment! I need to try again.

I also have received a BNO080 bosch/hillcrest lab. Will give it a try and let you know if good, but the code to use it, get linear acc, gravity etc. Looks VERY simple!