Timer not working as expected
Hi,
I want to measure time between two events. The events come in as ext- interrupts.
I set up a timer like this:
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM6_Init 1 */
/* USER CODE END TIM6_Init 1 */
htim6.Instance = TIM6;
htim6.Init.Prescaler = 49;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 1;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}Starting the timer
HAL_TIM_Base_Start(&htim6);Trying to read its value in the ext-it gives always 1 or 0.
I dont really understand what I am doing wrong.
// diff is allways 0 or 1 (even when different times went by between the calls)
uint32_t diff = __HAL_TIM_GET_COUNTER(&htim6);
__HAL_TIM_SET_COUNTER(&htim6,0);