AnsweredAssumed Answered

Problems with PWM

Question asked by Neiro on Oct 27, 2012
Latest reply on Oct 28, 2012 by Clive One
Dear STM-Experts,

i tried my first PWM with the STM32F4Discovery. It should create a 7 MHz PWM with 50 % duty-cycle. But i can only get a changing 8 bzw 6 Mhz Pwm like shown here:
channel5.png

Here is the code (Picked up and then changed from STM Std. Peripheral Libraries):

 //GPIOE Clocks enable
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE , ENABLE);

  //GPIOE settings
  GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure2.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure2.GPIO_PuPd = GPIO_PuPd_UP ;

  //GPIOE Configuration: Channel 2 as alternate function push-pull
  GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_11 ;
  GPIO_Init(GPIOE, &GPIO_InitStructure2);
  GPIO_PinAFConfig(GPIOE, GPIO_PinSource11, GPIO_AF_TIM1);

  //TIM1 clock enable
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);

  //Time Base configuration
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 23;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  //Channel 2 Configuration in PWM mode
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 11;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;

  TIM_OC2Init(TIM1, &TIM_OCInitStructure);

  //TIM1 counter enable
  TIM_Cmd(TIM1, ENABLE);

  //TIM1 Main Output Enable
  TIM_CtrlPWMOutputs(TIM1, ENABLE);

Thank you a lot for your help!
Florian

Outcomes