Another Microsecond Delay
NUCLEO-64 STM32L476RG
STM32CubeIDE 1.10.1
Trying to get a microsecond delay to work based on this post.
APB1 Timer = 80 MHz from HSI->PLLCLK.
TIM6 = 1 MHz (Prescaler = 79, ARR = 0xFFFF)
My main (after MX stuff) looks like this and sets delay to 5000 us (5 ms).
LL_TIM_EnableCounter(TIM6);
while (1)
{
LL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
DelayUs(5000);
}
My delay function looks like this.
static inline void DelayUs(uint16_t us)
{
uint16_t start = TIM6->CNT;
while((TIM6->CNT - start) < us);
}
The scope on LD2 shows this.
So I'm getting 5 ms pulses but occasionally it doesn't switch and essentially doubles up. I'm very much still learning all this and dug into the datasheets as much as I could, but at this point I need help from people far smarter than me :) Any help is greatly appreciated!
