2020-08-11 03:44 AM
Please find the details below:
Part - STM32F072VB
stm32cube mx for code generation
timer clock - 24MHz
static void MX_TIM7_Init(void)
{
/* USER CODE BEGIN TIM7_Init 0 */
/* USER CODE END TIM7_Init 0 */
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM7_Init 1 */
/* USER CODE END TIM7_Init 1 */
htim7.Instance = TIM7;
htim7.Init.Prescaler = 2000-1 ;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
htim7.Init.Period = 1;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM7_Init 2 */
/* USER CODE END TIM7_Init 2 */
}
/**
* @brief TIM14 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM14_Init(void)
{
/* USER CODE BEGIN TIM14_Init 0 */
/* USER CODE END TIM14_Init 0 */
/* USER CODE BEGIN TIM14_Init 1 */
/* USER CODE END TIM14_Init 1 */
htim14.Instance = TIM14;
htim14.Init.Prescaler = 1600-1;
htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
htim14.Init.Period = 20;
htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM14_Init 2 */
/* USER CODE END TIM14_Init 2 */
}
Solved! Go to Solution.
2020-08-11 03:49 AM
> timer clock - 24MHz
> TIM7 for 1ms
1/1ms = 1kHz. You can leave prescaler = 0 and set period = (24MHz/1kHz - 1) = 24000 - 1
> & TIM 14 for 20 ms
1/20ms = 50Hz. You'll need some prescaler here, e.g. prescaler = 20 - 1 and period = 24000 - 1.
JW
2020-08-11 03:49 AM
> timer clock - 24MHz
> TIM7 for 1ms
1/1ms = 1kHz. You can leave prescaler = 0 and set period = (24MHz/1kHz - 1) = 24000 - 1
> & TIM 14 for 20 ms
1/20ms = 50Hz. You'll need some prescaler here, e.g. prescaler = 20 - 1 and period = 24000 - 1.
JW
2020-08-11 04:01 AM
Thank you so much for the guidance.
Can you share the formulas how prescaler & period is calculated???
2020-08-11 04:11 AM
timer update frequency = timer input frequency / (TIM_PSC + 1) / (TIM_ARR + 1)
JW