2024-03-19 11:32 PM
/////////////////////////////////////////////TIMER 5 /////////////////////////////////////
void MX_TIM5_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim5.Instance = TIM5;
htim5.Init.Prescaler = 29999;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 399999; ////////////how to calculate period of timer 5??????????????
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}
/////////////////////////////////////////////TIMER 5 END /////////////////////////////////////
///////////////////////////////////////////TIMER 6 /////////////////////////////
void MX_TIM6_Init(void)
{
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim6.Instance = TIM6;
htim6.Init.Prescaler = 29999;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 699999; //////////// how to calculate period of timer 6????????
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}
BOTH OF THIS ONE MINUTE DIFFRENT WORK TIM5 IS CURRECT WORK BUT TIM6 NOT A PROPER WORK BOTHs TIMER Period calculation formula give me ???????///
2024-03-20 03:17 AM
Which STM32?
What is the system clock and how are APB clocks set?
TIM5 is a 32-bit timer, so 399999 is OK; but TIM6 is a 16-bit timer so the maximum Period is 65535 (and so is maximum Prescaler).
So, you cannot achieve one minute period with TIM6. You can set it to e.g. a one second period, and then in the Update interrupt, count a variable up to 60 and perform whatever action you want to do once in a minute, when that is reached.
JW
2024-03-20 09:14 PM
THANKS SIR