Skip to main content
jakob.brunhart
Associate III
June 18, 2019
Solved

TIM16 and LSI frequency Measurment

  • June 18, 2019
  • 2 replies
  • 1313 views

Hi,

I'm using STM32H743ZI. I want to measure the LSI frequency by timer TIM16.

  1. Configure TIM16 by CubeMX (5.2.1)
    1. "Input Capture direct mode from Remap"
    2. "TI1 remap capabilities for TIM16 => "TIM16 TI1 is connected to RCC LSI"
    3. TIM16 global interrupt => "Enabled"
  2. Call "MX_TIM16_Init()"

In my opinion in line 29 Register TI1SEL should be set to 0x1. But the register does not change. If I set the register manually it seems to work.

/* TIM16 init function */
void MX_TIM16_Init(void)
{
 TIM_IC_InitTypeDef sConfigIC = {0};
 
 htim16.Instance = TIM16;
 htim16.Init.Prescaler = 0;
 htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim16.Init.Period = 0xFFFF;
 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();
 }
 if (HAL_TIM_IC_Init(&htim16) != HAL_OK)
 {
 Error_Handler();
 }
 sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
 sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
 sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
 sConfigIC.ICFilter = 0;
 if (HAL_TIM_IC_ConfigChannel(&htim16, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_TIMEx_RemapConfig(&htim16, TIM_TIM16_TI1_RCC_LSI) != HAL_OK)
 {
 Error_Handler();
 }
 
}

Any Idea?

Regard

Jakob

This topic has been closed for replies.
Best answer by jakob.brunhart

Thank for your help.

The following does work

MX_TIM16_Init();
 
if ( HAL_TIMEx_TISelection( &htim16, TIM_TIM16_TI1_RCC_LSI, TIM_CHANNEL_1 ) != HAL_OK )
{
 // error
}

Thank you

Jakob

2 replies

Tesla DeLorean
Guru
June 18, 2019

Use HAL_TIMEx_TISelection() with TIM_TIM16_TI1_LSI

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
jakob.brunhart
jakob.brunhartAuthorBest answer
Associate III
June 18, 2019

Thank for your help.

The following does work

MX_TIM16_Init();
 
if ( HAL_TIMEx_TISelection( &htim16, TIM_TIM16_TI1_RCC_LSI, TIM_CHANNEL_1 ) != HAL_OK )
{
 // error
}

Thank you

Jakob