uranyumx
Advanced Member level 4
Hello,
I have a question about timer period control based on the received UART value. The code piece was attached to the thread. In the code, ModulationFreq value comes from UART receive. The problem is that I didn't get a signal update based on the ModulationFreq value. If you have any suggestions, I would appreciate it.
Thank you,
I have a question about timer period control based on the received UART value. The code piece was attached to the thread. In the code, ModulationFreq value comes from UART receive. The problem is that I didn't get a signal update based on the ModulationFreq value. If you have any suggestions, I would appreciate it.
Thank you,
Code:
static void MX_TIM6_Init(void)
{
/* USER CODE BEGIN TIM6_Init 0 */
/* USER CODE END TIM6_Init 0 */
if (ModulationFreq == 100)
{
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM6_Init 1 */
/* USER CODE END TIM6_Init 1 */
htim6.Instance = TIM6;
htim6.Init.Prescaler = 96-1;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
//htim6.Init.Period = (1000*(128*(ModulationFreq/2)))-1;
htim6.Init.Period = 5000-1;
// 96-1 Prescaler and 5000-1 Period equals = 100 Hz
// 96-1 Prescaler and 10000-1 Period equals = 50 Hz
// 96-1 Prescaler and 20000-1 Period equals = 25 Hz
// 96-1 Prescaler and 50000-1 Period equals = 10 Hz
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM6_Init 2 */
/* USER CODE END TIM6_Init 2 */
}
}