Skip to main content
Dick Lin
Senior
July 10, 2018
Question

TIM16 for LL_TIM_SetCounter/LL_TIM_GetCounter

  • July 10, 2018
  • 2 replies
  • 995 views
Posted on July 10, 2018 at 22:55

Hi,

I am trying to use TIM16 for timer counter for Nucleo-144 board. After init, I do have code to SetCounter/EnableCounter.

After that the counter value get from GetCounter never increase as I am expecting.

Is there anything I am missing here? Anything else I need to make counter works?

Thx

/* TIM16 init function */

void MX_TIM16_Init(void)

{

htim16.Instance = TIM16;

htim16.Init.Prescaler = 0;

htim16.Init.CounterMode = TIM_COUNTERMODE_UP;

htim16.Init.Period = 0;

htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim16.Init.RepetitionCounter = 0;

htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

if (HAL_TIM_Base_Init(&htim16) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

LL_TIM_SetCounter(m_tim->Instance, counter);

LL_TIM_EnableCounter(m_tim->Instance);

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    July 10, 2018
    Posted on July 10, 2018 at 22:59

    Enable clock to given timer in RCC (APBxENR)?

    JW

    [EDIT]

    htim16.Init.Period = 0;

    This tells the timer not to run.

    Dick Lin
    Dick LinAuthor
    Senior
    July 10, 2018
    Posted on July 10, 2018 at 23:22

    Seems working after set Period to 0xFFFF. Now I have to verify if my clock divider correct or not. Thx

      htim16.Init.Period = 0xFFFF;