AnsweredAssumed Answered

timer 3 setting

Question asked by yang hong on Apr 10, 2018
Latest reply on Apr 13, 2018 by yang hong

Hello,

 

I am using STM32F429ZI, I would like to use timer 3 to generate a timer with high resolution something like 4000Hz  My Timer 3 setting is following:

 

static void MX_TIM3_Init(void)
{

TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;

htim3.Instance = TIM3;
htim3.Init.Prescaler = 419;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period =49;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.RepetitionCounter=0;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

}

 

I use global interrupt event TIM3_IRQHandler to handle event update

void TIM3_IRQHandler(void)
{
/* USER CODE BEGIN TIM3_IRQn 0 */

/* USER CODE END TIM3_IRQn 0 */
HAL_TIM_IRQHandler(&htim3);
/* USER CODE BEGIN TIM3_IRQn 1 */

printf("timer 3 update: %d\n",timer_counter);

if (timer_counter>=10000)
{
HAL_TIM_Base_Stop_IT(&htim3);
}
else
{
HAL_GPIO_TogglePin(NOMIGBT_GPIO_PORT,NOMIGBT_PIN);
__HAL_TIM_CLEAR_FLAG(&htim3,TIM_IT_UPDATE);

timer_counter++;
}

/* USER CODE END TIM3_IRQn 1 */
}

 

I trigger digital output to verify my timer. It looks my timer locked by 3Hz. Does anybody knows what is happen?

 

Thank you so much.

Outcomes