cancel
Showing results for 
Search instead for 
Did you mean: 

Timer isn't accurate

DavidL_
Associate

I am using an stm32 timer calculator ( https://deepbluembedded.com/stm32-timer-calculator/ ) to get the settings for a 20ms timer and got the following values: https://imgur.com/a/oMHS17r which I set for my TIM16 timer.

I am using the following code:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(htim == &htim16)
    {
      int t = HAL_GetTick();
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, SET);

      HAL_TIM_Base_Start_IT(&htim15);

      char m[30];
      sprintf(m, "1: %d\r\n", t);

      HAL_UART_Transmit(&huart2, (uint8_t*)m, 30, HAL_MAX_DELAY);
    }
}

 

to check if it works as expected every 20ms and it doesn't seem to work as intended, since it triggers every 17-18ms.

Does someone have an idea why its not working correctly?

PS: Here is an image of my clock tree: https://imgur.com/a/7bcML52 and I am using a STM32 Nucleo-32 L432KC

1 ACCEPTED SOLUTION

Accepted Solutions
DavidL_
Associate

The UART transmission duration was accounting for the lost 2-3 ms

View solution in original post

1 REPLY 1
DavidL_
Associate

The UART transmission duration was accounting for the lost 2-3 ms