cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f-4 Motor control - PWM not generate

benjaminguillot.699
Associate II
Posted on January 16, 2013 at 11:39

Hi, i'm using the stm3240f board with a stm32f4-series.

I try to generate PWM but nothing happen.

what i did : 

/*declaration-----------------------------------------*/

TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

TIM_OCInitTypeDef  TIM_OCInitStructure;

uint16_t CCR1_Val = 333;

uint16_t CCR2_Val = 249;

uint16_t CCR3_Val = 166;

uint16_t CCR4_Val = 83;

uint16_t PrescalerValue = 0;

/* Private function prototypes -----------------------------------------------*/

void TIM_Config(void);

/*MAIN---------------------------------------------------*/

int main(void)

{

  TIM_Config();

 /* Compute the prescaler value */

  PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 21000000) - 1; //slowndown count

  /* Time base configuration */

  TIM_TimeBaseStructure.TIM_Period = 665;

  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration: Channel1 */

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC1Init(TIM3, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel2 */

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = CCR2_Val;

  TIM_OC2Init(TIM3, &TIM_OCInitStructure);

  TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel3 */

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = CCR3_Val;

  TIM_OC3Init(TIM3, &TIM_OCInitStructure);

  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel4 */

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = CCR4_Val;

  TIM_OC4Init(TIM3, &TIM_OCInitStructure);

  TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);

  TIM_ARRPreloadConfig(TIM3, ENABLE);

  /* TIM3 enable counter */

  TIM_Cmd(TIM3, ENABLE);

 

while (1){ }

}

/**

  * @brief  Configure the TIM3 Ouput Channels.

  * @param  None

  * @retval None

  */

void TIM_Config(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  /* TIM3 clock enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  /* GPIOC clock enable */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

  

  /* GPIOC Configuration: TIM3 CH1 (PC6), TIM3 CH2 (PC7), TIM3 CH3 (PC8) and TIM3 CH4 (PC9) */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;

  GPIO_Init(GPIOC, &GPIO_InitStructure); 

  /* Connect TIM3 pins to AF2 */  

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM3);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM3); 

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM3); 

}

I see nothing on the motor control connactor (CN5) exept the 5V on the pin number 25.

Any suggestions?

Thanks for helping!!
3 REPLIES 3
Posted on January 16, 2013 at 16:27

Well the code doesn't appear unreasonable. You should be able to see a 31.5KHz signal at PC6..9 on the scope. I'd start verifying that and then move further out the circuit, referring to the schematic.

Is there perhaps a control signal enabling the 5V interface, the STM32F4 doesn't output such voltages, look at the buffering circuits?

So which board is this exactly? Can you provide a link? STM3240F google-whacks to your singular post.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
benjaminguillot.699
Associate II
Posted on February 25, 2014 at 15:34

Hi clive, sorry but i didnt see ure answer!!

Thank you a lot, but i fixed the problem! That's why i didnt come back on st community^^

My first message i had post, i got no reponse, so thanks for urs!

benjaminguillot.699
Associate II
Posted on February 25, 2014 at 15:34

Hi clive, sorry but i didnt see ure answer!!

Thank you a lot, but i fixed the problem! That's why i didnt come back on st community^^

My first message i had post, i got no reponse, so thanks for urs!