I'm learning a bit about general purpose timers on my STM32F4Discovery board, and would like to know how I can configure the timer to invoke a timer interrupt each second, or at least have the auto-reload value reset to 0 every 1 second.
I know the MCU runs at 168MHz, and I'm using the internal clock as the TIM2 clock source. I would like to understand better how I can calculate the appropriate prescale value, period and clock division to achieve 1 sec.
TIM_HandleTypeDef timeBase;
timeBase.Instance = TIM2;
timeBase.Init.Prescaler = 0;
timeBase.Init.CounterMode = TIM_COUNTERMODE_UP;
timeBase.Init.Period = 168000000; // Hypothetical value (Period cannot be greater than 65535)
timeBase.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&timeBase);
Am I correct in saying that the above, with a prescaler of 0, period of 168000000 and clock division of 1 will cause a the timer auto-reload value to reset to 0 each 1 second?
Now, the Period has a max value of 0xFFFF (65535), so to me that means I need to manipulate the prescaler value, and period to achieve a 1 second auto-reload value reset.
Is there a formula for doing this?