Author Topic: Timer Delay & Interrupt in STM32  (Read 1697 times)

0 Members and 1 Guest are viewing this topic.

Offline saiTopic starter

  • Newbie
  • Posts: 1
  • Country: in
Timer Delay & Interrupt in STM32
« on: October 26, 2018, 09:09:46 am »
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);


PWM pins iam using are PB0,PC6,PC7 in STM32F407VG Controller

i Have 3 PWM channels i want to take the present dutycycle and after some delay i want to make it zero nothing but i want to blink. dutycycle may be changed continuously but not constant change in interval time that depends on user. delay is also different depends on user selection it should be between 25 to 250 ms. during blinking if change in PWM it has to take that PWM and continue blinking. if iam giving constant PWM and using then there is no problem if i change the PWM continuouslt then it is hanging
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf