Skip to main content
mehmet.karakaya
Associate III
July 4, 2011
Question

why cant I get PWM at TIM3 ?

  • July 4, 2011
  • 4 replies
  • 822 views
Posted on July 04, 2011 at 19:03

void TIM3init(void) {

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* Time base configuration */

  TIM_TimeBaseStructure.TIM_Period = 7200;

  TIM_TimeBaseStructure.TIM_Prescaler = 0;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = 2000;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC3Init(TIM3, &TIM_OCInitStructure);

  TIM_OC4Init(TIM3, &TIM_OCInitStructure);

  TIM_CCPreloadControl(TIM3, DISABLE);

  TIM_Cmd(TIM3, ENABLE);

  TIM_CtrlPWMOutputs(TIM3, ENABLE);

}

void run_motor(void){

    TIM_SelectOCxM(TIM3, TIM_Channel_3, TIM_OCMode_PWM1);

    TIM_CCxCmd(TIM3, TIM_Channel_3, TIM_CCx_Enable);

    TIM_SelectOCxM(TIM3, TIM_Channel_4, TIM_ForcedAction_Active);

    TIM_CCxCmd(TIM3, TIM_Channel_4, TIM_CCx_Disable);

}

with above code I get logic ''1'' at TIM3_CH3

instead of PWM

can anybody help ?
    This topic has been closed for replies.

    4 replies

    Nickname13136_O
    Visitor II
    July 5, 2011
    Posted on July 05, 2011 at 08:16

    Hello,

    I hope you have enabled tim3 and GPIOB peripheral clock?

    Rgds,

    mehmet.karakaya
    Associate III
    July 5, 2011
    Posted on July 05, 2011 at 09:29

    yes I have enabled them ;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    mehmet.karakaya
    Associate III
    July 5, 2011
    Posted on July 05, 2011 at 16:49

    I am sorry

    I found my coding error

    the problem is solved

    thank you

    Nickname13136_O
    Visitor II
    July 8, 2011
    Posted on July 08, 2011 at 10:33

    It is great!