calculating dt for calculate angle with LSM9DS1 gyro
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;
}
