cancel
Showing results for 
Search instead for 
Did you mean: 

For STM32F303 I seek more literature about PWM managing, configuration, etc... as much as possible. Can somebody help me?

LRoss.12
Associate
 
1 REPLY 1
LACTIC
Associate II
  1. Enable board timer with its CHANNEL.
  2. give Prescaler value.
  3. clock division value
  4. config pwm
  5. set pwm polarity.
  6. set pwm in fast aor normal mode.

Config GPIO value .

if you are using STM32cube MX set these value in that .

e.g

/* TIM14 init function */

static void MX_TIM14_Init(void)

{

 TIM_OC_InitTypeDef sConfigOC;

 htim14.Instance = TIM14;

 htim14.Init.Prescaler = 16;

 htim14.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim14.Init.Period = 100;

 htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 if (HAL_TIM_Base_Init(&htim14) != HAL_OK)

 {

  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_SET);

HAL_Delay(100);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_RESET);

HAL_Delay(100);

 }

 if (HAL_TIM_PWM_Init(&htim14) != HAL_OK)

 {

  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_SET);

HAL_Delay(100);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_RESET);

HAL_Delay(100);

 }

 sConfigOC.OCMode = TIM_OCMODE_PWM1;

 sConfigOC.Pulse = 0;

//sConfigOC.OCIdleState=TIM_OCIDLESTATE_SET;

 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH ;

 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

 if (HAL_TIM_PWM_ConfigChannel(&htim14, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)

 {

  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_SET);

HAL_Delay(50);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4,GPIO_PIN_RESET);

HAL_Delay(50);

 }

 HAL_TIM_MspPostInit(&htim14);

}

this is example of pwm of timer 14 channel1.