Question
STM32L timebetween pulses
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