cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate delta T ??

Posted on December 29, 2016 at 11:57

I have a 10DOF sensor that is calculating 3 angles(roll,pitch,yaw). I need to know how can i calculate the time of execution of my code so i can get the delta t, like in arduino we used as i remember a function called micros. I was thinking about using timer interrupt but i am trying to avoid it because i am not good with it.

6 REPLIES 6
Nesrine M_O
Lead II
Posted on December 30, 2016 at 13:48

Hi

Rabah.Mohamed

‌,

To calculate execution period maybe you can useSysTick timer (STK) :

    • Create a variable 'start time=0' whichread thecurrent value of the SysTick counter from theSTK_VAL register
    • Start the Systicktimer :SysTick_Config(0xFFFFFF);
    • Stop the Systick Timer and get the encoding time (stop time) ,thenclear the SysTick Counter
    • Finally calculate the delta :tmp+=(0xFFFFFF -

      stop time

      ); (Systick timercounts down from the reload value to zero)tmp-=

      start time

      ;
    • please refer toSysTick timer (STK) section in yourrelated productProgramming manual (PM0214)
  1. if you are cube user you can useHAL_GetTick function

    which

    provide a tick value in millisecond
  2. Refer to this example thatshow how to use the default configuration of SysTickSTM32Cube_FW_F4_V1.0\Projects\STM324x9I_EVAL\Examples\Cortex\CORTEXM_SysTick

-Nesrine-

Posted on December 30, 2016 at 17:15

For microsecond or nanosecond granularity I'd use the DWT_CYCCNT to benchmark code. 32-bit up counter as core frequency.

More practically consider using a free running 32-bit TIM, clocking at 1 MHz (or as desired) to provide a high resolution timeline.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 31, 2016 at 02:19

i aim for 0.1 sec or maximum 0.01 so i would be glad if u explain to me what you mean.

Posted on December 31, 2016 at 02:19

Thanks. I will try it and update you

Posted on December 31, 2016 at 03:20

If you are unfamiliar with the DWT_CYCCNT I suggest you Google it, or the site here, I've posted multiple examples. ARM has Technical Reference Manuals describing the core.

If you clock one of the 32-bit TIM peripherals at 1MHz, reading TIMx->CNT will give you a ticking timestamp equivalent to micros() on Arduino

You can't interrupt at rates like 1MHz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 31, 2016 at 03:58

Thanks for your help.