Measuring a time between two events with SysTick on STM32F4?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-10-23 11:45 AM
Posted on October 23, 2014 at 20:45
Hello all, i want to build a function like current_time = time_now - last_time, more exactly i wanna get the time from two of the same event (reading some mems sensors)
I'ved google`it a bit and found that most use the Systick timer built in the ARM M4 core, but here i have a question since my experience with systick is very small Logicaly speaking this means that i must have a timer that runs all the time in paralel with my software, some kind of RTO clock? But the systick does not gennerate interrupt when it overflows ? Supose i want to increment at every us, thus getting the timestamp in microseconds, and my concern is wouldn`t this generate a interrupt every us? Halting my code? Some advices would be apriciated... Thank You
This discussion is locked. Please start a new topic to ask your question.
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-10-23 11:53 AM
Posted on October 23, 2014 at 20:53
The SysTick is a 24-bit count, you get the ''SysTick'' interrupt when it reloads.
Suggest you use for very fine tick measurement (ie 168 MHz to 6 seconds), or a 32-bit TIMx (ie 84 MHz to 1 seconds)
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-10-23 11:57 AM
Posted on October 23, 2014 at 20:57
For 1us granularity suggest you prescale a 32-bit TIMx to 1MHz, you'd have a wrap time in the order of 4295 seconds (1.19 hours)
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-10-23 1:12 PM
Posted on October 23, 2014 at 22:12
Thank you clive, tryied using timer2 as a plain time base, like bellow
My core is running at 168MHZ , APB1 prescaler 4
So loading a value of 0xFFFFFFFF wich means 4294967295, this results in how many microseconds the timer counts before reset?
That means (4294967295/1000000)/3600 would give 1.19 hours ? It's sufficient for me (won`t be flying the quadcopter that much :))) )
TIM_InitStruct.TIM_Prescaler = ((SystemCoreClock / 1000000) / 2) - 1;
TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_InitStruct.TIM_Period = 0xFFFFFFFF;
TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_InitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &TIM_InitStruct);
TIM_Cmd(TIM2, ENABLE);
and for reading the actual ''uptime'' since last reset i just used uint32_t TIM_GetCounter(TIM_TypeDef* TIMx) from the stm32f4xx_tim.c library
