Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] A Variable Control of Timer Period

Status
Not open for further replies.

uranyumx

Advanced Member level 4
Full Member level 1
Joined
Mar 5, 2011
Messages
102
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
2,098
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,

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 */
 
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top