First off I'm a complete n00b and just getting started with STM32. I'm encountering some weird behavior while setting up TIM1 and also using external interrupt EXTI3. I'm attempting to measure a low input frequency on the external interrupt and using TIM1 to increment a 1 MHz counter, so I can measure in microseconds. I'm doing this as it seems SysTick isn't fast enough (1 ms) to give me an accurate measurement.
The core clock is 16 MHz, and TIM1 is set up as follows:
htim1.Instance = TIM1;
htim1.Init.Prescaler = 16; // 16 MHz / 16 = 1 MHz
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 1; // 1Mhz no sub-dividing
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
...
HAL_NVIC_SetPriority(EXTI3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
...
void TIM1_UP_TIM10_IRQHandler(void)
{
timerTicks++;
HAL_TIM_IRQHandler(&htim1);
}
...
void EXTI1_IRQHandler(void)
{
previousTimerTicks = currentTimerTicks;
currentTimerTicks = timerTicks;
}
...
// Start the timer as interrupt
HAL_TIM_Base_Start_IT(&htim1);
...
while(1){
// Blink a light so we know the program is running
HAL_GPIO_TogglePin(GPIOB, Led_Green_Pin);
HAL_Delay(100);
}
However, the program pretty much locks up and the while() run loop doesn't seem to execute. Yet, I can see the TIM1 counter is incrementing. If I slow the Period down to say, 100, the main application loop seems to run OK.
Is this a problem with TIM1 and EXTI3 conflicting at that speed - or something else going on here? I figure the device should have no issue providing a 1 MHz counter, but maybe I'm doing this all wrong.