cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with TIM15 of Stm32F051 and HAL

Osto
Senior
Posted on April 30, 2015 at 03:33

Hi all,

I want to measure a ~5ms signal at TIM15 Channel 1.

Our examples and information I have dont work.

Can somebody help me with sample HAL code? 

Thanks,

Osto
3 REPLIES 3
l239955_stm1
Associate II
Posted on April 30, 2015 at 12:45

Hi,

you can used CubeMX tool to generating initialization code. There is code example of using timer from my project:

    TIM_HandleTypeDef            Tim6Handle;

   __TIM6_CLK_ENABLE();   

    /* TIM6 Time base configuration */

    Tim6Handle.Instance = TIM6;

    Tim6Handle.Init.Prescaler = TIM_ICPSC_DIV1;

    Tim6Handle.Init.CounterMode = TIM_COUNTERMODE_UP;

    Tim6Handle.Init.Period = xxx;

    Tim6Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

    HAL_TIM_Base_Init(&Tim6Handle);

    /* TIM6 IRQChannel enable */

    HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 1, 0);

    HAL_NVIC_ClearPendingIRQ(TIM6_DAC_IRQn);

    HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);

    __HAL_TIM_SetCounter(&Tim6Handle, 0);

    __HAL_TIM_CLEAR_IT(&Tim6Handle, TIM_IT_UPDATE);

    HAL_TIM_Base_Start_IT(&Tim6Handle);

Interrupt handling function is called at each period you set

void TIM6_IRQHandler(void) {

....

}

Osto
Senior
Posted on May 01, 2015 at 17:19

Dear Lukas,

This is an example for timebase but I need to measure a signal starting at rising edge and ending at falling edge and I need to measure the width in ~50ns resolution with 24MHz timwe clock.

I'm wondering if you have a soulution for my problem.

Reagrds,

Osto

l239955_stm1
Associate II
Posted on May 04, 2015 at 07:02

Oh I´m sorry :-).

Time measuring based on signal edge I implemented in my app by comparator. Comparator generates interrupt where I measure time. Second solution - comparator output can be connected direct to timer but you have to choose the other.