Microsecond Resolution Timing

4 posts / 0 new
Last post
envirosenjason
Offline
Last seen:4 years 2 weeks ago
Joined:2016-08-05 21:11
Microsecond Resolution Timing

Timer1 is reserved for the FreeRTOS ticks, which is running with the 32 kHz clock giving a resolution of ~30.5 microseconds. If I wanted to get the current execution time in a smaller resolution of microseconds, is there somewhere where the 16/32 MHz XTAL or 48/96 MHz PLL ticks are stored? The only place I could find to change the RTOS clock was dg_configUSE_LP_CLK in custom_config_qspi.h which modifies FreeRTOSConfig.h, but it seems that only choices are the 32000, 32768, and RCX (10.5 kHz) clocks. Is there a way to change the OS tick to a faster clock, so I can use OS_GET_TICK_COUNT to keep track of execution time?

Keywords:
Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi envirosenjason,

Hi envirosenjason,

Timer1计时器,权力自由操作系统,使用s only the LP clock and it runs continiously, you cannot change the source of this timer into another clock in order to have greater granularity to your time measurement, so the resolution of this timer is the one that you mention on your post depending on the LP clock. You can directly read the ticks of the timer 1 clock simply by reading the CAPTIM_TIMER_VAL_REG register. Also make sure that you only read the value and never write it since this could di-stabilize the system. Regarding the OS_GET_TICK_COUNT() this will get you a resolution of 2 ms.

The tick of the Free RTOS isn't driven directly from the LP clock but uses a prescaler that scales the tick to a 2 ms resolution with the current configuration, you could lower that by changing the configTICK_RATE_HZ to a larger value in order reduce the time of the tick but you should be cautious with that modification since it will affect the entire OS since it will be operating by a smaller or larger tick.

Thanks MT_dialog

ArminL
Offline
Last seen:4 years 2 weeks ago
Joined:2016-09-30 07:23
Hi MT_dialog,

Hi MT_dialog,

Why is FreeRTOS powered by Timer1 and not by SysTick?

Thanks
Armin

MT_dialog
Offline
Last seen:2 months 1 week ago
Staff
Joined:2015-06-08 11:34
Hi ArminL,

Hi ArminL,

I trust that this is because timer1 operates constantly even when the device goes in sleep mode but the systick doesn't operate in that case since ARM is in WFI() state. So since you allready have one timer that constantly operates and is dedicated to keep time you can use this timer to tick the FreeRTOS instead of having another timer like the systick module for that operation.

Thanks MT_dialog