cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding timer delay & Interrupt

saiteja
Associate II

void MX_TIM5_Init(void)

{

 TIM_ClockConfigTypeDef sClockSourceConfig;

 TIM_MasterConfigTypeDef sMasterConfig;

 htim5.Instance = TIM5;

 htim5.Init.Prescaler = 84;

 htim5.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim5.Init.Period = 99; //interrupt in 100 micro sec

// htim5.Init.Period = 50; //interrupt in 50 micro sec

 htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 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();

 }

}

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)

{

 if(tim_baseHandle->Instance==TIM5)

 {

 /* USER CODE BEGIN TIM5_MspInit 0 */

 /* USER CODE END TIM5_MspInit 0 */

  /* Peripheral clock enable */

  __HAL_RCC_TIM5_CLK_ENABLE();

  /* Peripheral interrupt init */

  HAL_NVIC_SetPriority(TIM5_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(TIM5_IRQn);

 /* USER CODE BEGIN TIM5_MspInit 1 */

 /* USER CODE END TIM5_MspInit 1 */

 }

}

void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)

{

 if(tim_baseHandle->Instance==TIM5)

 {

 /* USER CODE BEGIN TIM5_MspDeInit 0 */

 /* USER CODE END TIM5_MspDeInit 0 */

  /* Peripheral clock disable */

  __HAL_RCC_TIM5_CLK_DISABLE();

  /* Peripheral interrupt Deinit*/

  HAL_NVIC_DisableIRQ(TIM5_IRQn);

 }

 /* USER CODE BEGIN TIM5_MspDeInit 1 */

 /* USER CODE END TIM5_MspDeInit 1 */

This is how i have initialised the timer now i am looking to put delay between

SetPWM(x,dutycycle);

SetPWM(y,dutycycle);

SetPWM(z,dutycycle);

delay();

SetPWM(x,0);

SetPWM(y,0);

SetPWM(z,0);

when iam using timer delay or normal delay the system is hanging as i am changing the PWM during delay is there any solution for this.

12 REPLIES 12
T J
Lead

do you use the cube ?

do you have a scope ?

google this "stm32 timer cookbook

5 PDFs are presented.

No, I am using Keil. Got the solution for this, thank You

dbgarasiya
Senior II

Thannks @Community member​