Timer runtime config issue
Hi guys,
I have a simple timer config, which I want to change based on some conditions. I set GPIO high and when OPM timer INT happens, GPIO is set low. Default timer setup 50ms, which is changed to 500ms in the while() loop.
Problem: the first pulse duration after change is incorrect (old setup), then all works fine. Could some point out what is wrong in my setup?
A short code sample is here:
int main(void)
{
....
MX_TIM7_Init();
if (HAL_TIM_Base_Start_IT(&htim7) != HAL_OK) {
/* Starting Error */
Error_Handler();
}
while (1)
{
HAL_Delay(1000);
GPIOA->BSRR = (uint32_t)GPIO_PIN_0;
TIM7->CNT = 0;
TIM7->PSC = 800-1;
TIM7->ARR = 50000-1;
TIM7->CR1 |= TIM_CR1_CEN | TIM_CR1_OPM;
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM7) {
GPIOA->BRR = (uint32_t)GPIO_PIN_0;
}
}
static void MX_TIM7_Init(void)
{
...
htim7.Instance = TIM7;
htim7.Init.Prescaler = 80-1;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
htim7.Init.Period = 50000-1;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
...
}
Thanks in advance
