cancel
Showing results for 
Search instead for 
Did you mean: 

calculating dt for calculate angle with LSM9DS1 gyro

MDoğr.1
Associate II

I want to calculate angle from gyro and for this issue formula is this: angle=angle+gyro*dt

For dt; since my code is too long, instead of usind sample rate directly , ı want to calculate time that code consume's gyro reading part to gyro reading part. For this ı tried timer2 period:9999, presc.:83999 with the code below but I relasied that this function doesn't calculate time in HAL_Delay function because HAL_Delay works with systick interrupt.

So, how can I solve this problem and write a function that calculate's the time it consumed to come that function again?

void timesince(){

countnew=__HAL_TIM_GET_COUNTER(&htim2);

if (countnew>countold)

 dt=(countnew-countold)/1000.0;

else

dt=10.0-((countold-countnew)/1000.0);

countold=countnew;

}

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @Mehveş Zehra Doğruel​ ,

did you try to use the "ODR-related" timebase? I mean the dt derived from the device ODR (i.e. 1/ODR, for example when ODR = 952Hz).

I would suggest you to calculate the "dt" basing on the LSM9DS1 data-ready interrupt, routing the INT1_ DRDY_XL of the INT1_CTRL (0Ch) register on the INT1, and then managing it into the project routine.

-Eleon