2014-10-23 11:45 AM
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 You2014-10-23 11:53 AM
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)2014-10-23 11:57 AM
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)
2014-10-23 01:12 PM
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