AnsweredAssumed Answered

PWM Output on STM3210E-EVAL board

Question asked by DWORD32 on Aug 27, 2015
Latest reply on Nov 2, 2015 by Clive One
I'm trying to setup one of the LEDs on the STM3210E-EVAL board as a PWM output so that I can vary the brightness.  I am targeting the red LED, which is on port F, pin 8.  I have setup timer 13 which should be tied to that pin for PWM output, but I feel like like I am missing a step somewhere.   Here is the current function to initialize the pin, setup the timer, and setup the PWM:

void led_init(void)
{
  TIM_OC_InitTypeDef sConfigOC;
  TIM_HandleTypeDef htim13;
 
 
  /*Configure GPIO pins : PF8 */
  __HAL_AFIO_REMAP_TIM13_ENABLE();
  __GPIOF_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
 
 
 
  htim13.Instance = TIM13;
  htim13.Init.Prescaler = (uint32_t)(72000000 / 2000000) - 1;
  htim13.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim13.Init.Period = 700;
  htim13.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&htim13);
 
  HAL_TIM_PWM_Init(&htim13);
 
  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 350;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  sConfigOC.OCNPolarity  = TIM_OCNPOLARITY_HIGH;
  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
  sConfigOC.OCIdleState  = TIM_OCIDLESTATE_RESET;
 
  HAL_TIM_PWM_ConfigChannel(&htim13, &sConfigOC, TIM_CHANNEL_1);
  HAL_TIM_PWM_Start(&htim13, TIM_CHANNEL_1);
}

Any advice would be greatly appreciated! 

Thank you!

Outcomes