uranyumx
Advanced Member level 4
Hello,
I want to control a timer period with a variable. The variable value is correct because I monitored it in the watch window. But the variable was not working in the timer settings. Because when I write a digit in there, it works. Are there any suggestions about this issue?
Thank you,
I want to control a timer period with a variable. The variable value is correct because I monitored it in the watch window. But the variable was not working in the timer settings. Because when I write a digit in there, it works. Are there any suggestions about this issue?
Thank you,
Code:
volatile int AmpModFreqCalculation;
int main(void)
{
....
while (1)
{
HAL_StatusTypeDef usart2_status;
usart2_status = HAL_UART_Receive(&huart2, Rx_dmux_mux, 98, 200000); //receive 86 bytes (0-86) of data from MATLAB, 60 sec timeout
...
ModulationFreq = (Rx_dmux_mux[65]<<8) | Rx_dmux_mux[64];
...
AmpModFreqCalculation = round((1000000 / (ModulationFreq * 128)));
}}
static void MX_TIM6_Init(void)
{
/* USER CODE BEGIN TIM6_Init 0 */
/* USER CODE END TIM6_Init 0 */
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 = AmpModFreqCalculation - 1; // (ModulationFreq * 128) = TriggerFreq; (Period) = (1.000.000 Hz / (ModulationFreq * 128)) - 1
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 */
}