HAL_TIM_Base_Stop() and HAL_TIM_Base_Start() adds time? (trying to have a nanoseconds (100ns) control delay using a BASE TIMER)
Hello,
I need to control signals in the order of nanoseconds magnitude (~ 100 ns). For this purpose, I have programmed a hardware timer in order to have an interrupt with 100 ns delay.
I'm using a STM32F746VE microcontroller at 216 MHz. I'm using the TIM6 as a Base_TIM and I'm programming it with the following configuration:
timConfig.Prescaler = 1;
timConfig.CounterMode = TIM_COUNTERMODE_UP;
timConfig.ClockDivision = TIM_CLOCKDIVISION_DIV1;
timConfig.RepetitionCounter = 0;
timConfig.Period = 5;
timConfig.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
Supposing that APB frequency of the bus is 108 MHz, this is a 111 ns timer (approx.).
Then in order, to measure the real delay of this timer I toggle a GPIO pin in its interruption handler, and measuring the time with an oscilloscope. The interruption handler is the following:
void TIM6_DAC_IRQHandler(void)
{
HAL_TIM_Base_Stop_IT(HAL_TIM6);
if ( i == 0 )
{
GPIOE->BSRR = GPIO_PIN_3;
i = 1;
}
else
{
GPIOE->BSRR = (uint32_t)GPIO_PIN_3 << 16;
i = 0;
}
HAL_TIM_Base_Start_IT(HAL_TIM6);
}Then, measuring the delay of the interruption is 1.4 us. And if I comment the Stop() and Start() functions I achieve a delay of 235 ns. But not the theoretical 111ns calculated previously with the formula ( T = (1/APB_TIM_CLK) * (PRESCALER_Value + 1) * (PERIOD_Value + 1) ).
Where is the problem here? What happens with HAL_TIME_Base_Start_IT() and HAL_TIME_BASE_Stop_IT()? These funcions add a lot of time.
Thank you in advance.
