2017-12-24 11:31 AM
Hi all,
I'm trying to developpe microseconds delay based on STM32L0. I resort to use timer, which will generate an interrupt once the delay_time will be elaspsed.
__HAL_RCC_TIM7_CLK_ENABLE();
/* Set TIM7 instance */
OneWireTimHandle.Instance = TIM7;
OneWireTimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
OneWireTimHandle.Init.Prescaler = 31;
OneWireTimHandle.Init.Period = 9;
HAL_TIM_Base_Init(&OneWireTimHandle);
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(TIM7_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM7_IRQn);
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{ TimCall++;}
The GPIO_LED signal displayed on the scope is not well adjusted, the LED is blinking in every 12 or 13 microseconds instead of 10 microseconds.
Did any one know the cause of this issue?
Best Regards.
Arwa
#stm32-timer #timer-delay #tim-counter #timer2017-12-24 01:33 PM
Such an interrupt rate is undesirable, just use the TIM count to observe elapsed time in microseconds or CPU ticks.
2017-12-24 02:07 PM
Thanks for your quick response.
I think that when removing the Tim interrupt, it will be mandatory to use a blocking while instruction.
Have you please an other idea to enssure a non-blocking microseconds delay?
2017-12-24 03:22 PM
And how is that any different from spinning in a loop like you are now? Except you aren't burning cycles entering/exiting interrupt context, and loading instructions that do very little useful work.
At 32 MHz, you have 320 cycles to use every 10us, look very carefully at what you are doing, especially how much gets burned doing software division, and wading in/out of the HAL abstraction.
Clock the TIM at 32 MHz, and watch TIM->CNT advance 320 ticks. Shave off a few ticks to account for entry/exit, tune/benchmark by toggling a GPIO and scoping.