cancel
Showing results for 
Search instead for 
Did you mean: 

Time-stamp by chaining two STM32 timers.

phani_hellboy
Associate II

Hello Everyone,

I have a requirement to track time and generate timestamps when an event occurs.

I have tried time_base, input capture methods and trying with chaining two timers now.

I wanted to know if it is possible to chain 2 timers in STM32L0 and keep counting the pulses without generating interrupts (normally as done in Time_base).

And when i need the timestamp, i should be able to access the counter registers from the two timers and calculate the time on my own.

Any ideas or suggestions would be of great help. 🙂

thanks and good day. 🙂

3 REPLIES 3

Timers only interrupt if you enable that functionality.

Yes, you can chain two timers together in master/slave mode. Reading the CNT values can't be don't atomically, so consider how you read them. You might want to latch the value in a CCRx channel register, so you should look for a combination that would permit a common trigger source for the capture.

Look for examples under the CubeL0 HAL trees.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

Thank you for the reply.

I understand that i need to use input capture method to latch the counter values to CC register when there is an event. And using a Read_reg on counter register cannot fetch the counter value at that instant.

phani_hellboy
Associate II

Today i came across an option of LL_TIM_GET_COUNTER.

/**

* @brief Get the counter value.

* @rmtoll CNT CNT LL_TIM_GetCounter

* @param TIMx Timer instance

* @retval Counter value (between Min_Data=0 and Max_Data=0xFFFF)

*/

__STATIC_INLINE uint32_t LL_TIM_GetCounter(TIM_TypeDef *TIMx)

{

return (uint32_t)(READ_REG(TIMx->CNT));

}

Will this function be able to return the counter values without latching them to capture registers or channels ?