Skip to content

Files

This branch is 86 commits ahead of, 3 commits behind MYaqoobEmbedded/STM32-Tutorials:master.

Tutorial 08 - PWM

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Sep 11, 2021
Sep 12, 2021
Sep 12, 2021
Sep 12, 2021
Sep 11, 2021
Sep 11, 2021
Sep 11, 2021
Sep 11, 2021
Sep 11, 2021
Sep 11, 2021
Sep 11, 2021
Sep 11, 2021
Sep 12, 2021

PWM & Output Compare

1. PWM Generation

  • Timer PWM start
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);

2. Output Compare

  • Timer Output Compare start
HAL_TIM_Base_Start_IT(&htim4);
HAL_TIM_PWM_Start_IT(&htim4, TIM_CHANNEL_1);

3. Timer interrupt callback function

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  if (htim->Instance == TIM4)
  {
    HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_SET);
    HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET);
  }
}

void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
  if (htim->Instance == TIM4)
  {
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
          HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET);
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2)
          HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_RESET);
  }
}