AnsweredAssumed Answered

STM32F3 Discovery - TIM PWM

Question asked by Gomes.Albin on May 10, 2017
Latest reply on Jun 4, 2017 by Omar BOUZOURRAA

I am trying to generate an output PWM signal using the TIM-PWM mode using the STM32F3VCT6 board. I have initialized and setup the timer and GPIO accordingly, but I don't get any output signal. The following is my code:

 

#include "cpu.h"

#include "stm32f3xx_hal.h"

  

TIM_HandleTypeDef htim2;

void GPIOInit(void);

void GPIOInit1(void);

void TIM2Init(void);

  

int main()

{

cpu_init(); //  Sets up system PLL and derived clocks

GPIOInit();

TIM2Init();

  

HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);

  

 

 

return 0;

}

  

void GPIOInit(void)

{

static GPIO_InitTypeDef GPIO_InitStruct;

  

GPIO_InitStruct.Pin = GPIO_PIN_1;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;

  

__HAL_RCC_GPIOA_CLK_ENABLE();

  

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  

}

  

  

void TIM2Init(void)

{

 

TIM_MasterConfigTypeDef sMasterConfig;

TIM_OC_InitTypeDef sConfigOC;

  

__HAL_RCC_TIM2_CLK_ENABLE();

  

htim2.Instance = TIM2;

htim2.Init.Prescaler = 71;

htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

htim2.Init.Period = 60000;

htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 

sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = 60000;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

  

  

}

 

I would really appreciate any help I can get. 

Outcomes