cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L timebetween pulses

k_
Associate II
Posted on September 06, 2013 at 15:35

Hello,

I'm trying to measure time between two pulses on a pin. Time between pulses is in 10 - 100 uS range so I can't use millis function. What I'm trying to do is use TIM2 CNT register. Since my APB2 clock is runnig at 32MHz I should get a resolution of about  0.03 uS. 

The problem is that when I try to debug the CNT register is always at 0x0000 value :(

I use this code to initialize timer:

void Enable_Timer()

{

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

TIM_InitStructure.TIM_Period = 0xFFFFFFFF;

TIM_InitStructure.TIM_Prescaler = 0x0000;

TIM_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM2, &TIM_InitStructure);

TIM_Cmd(TIM2, ENABLE);

}

And this to read the CNT value:

tt= TIM_GetCounter(TIM2);

EDIT:

I am using STM32L152 board

#timer #discovery #stm32l #tim
10 REPLIES 10
Posted on September 12, 2013 at 13:58

I couldn't find any information regards to PB10 channel in reference manual. Where did you find it?

That would be the

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00277537.pdf

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