Skip to main content
jbsnyder
Associate
July 10, 2009
Question

Trouble with using TIM8 for PWM

  • July 10, 2009
  • 16 replies
  • 3019 views
Posted on July 10, 2009 at 05:30

Trouble with using TIM8 for PWM

    This topic has been closed for replies.

    16 replies

    ozenozkaya
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:16

    i forgot writing it:

    i had already included it:

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM3 , ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

    e-design
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:16

    Hi ozenozkaya,

    in your previous post you wrote:

    ''RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM3 , ENABLE);''

    But TIM3 is attached to APB1 and not to APB2.

    To enable the clock for TIM3 you must write:

    ''RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);''

    Hope that helps.

    Regards, Florian

    ozenozkaya
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:16

    yep, they all work since i can get counter values from both TIM1 and TIM2 but not TIM3.... TIM2 and TIM3 are actually very similar what is the problem with TIM3; couldnt understand...

    swhite
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:16

    Quote:

    you are right! tim3 is not running;

    Are the system clocks running?

    Code:

    <BR> // Set the AHB clock (HCLK) equal to the system clock (SYSCLK). <BR> <BR> RCC_HCLKConfig(RCC_SYSCLK_Div1); <BR> <BR> // Set the (high speed) APB2 clock (PCLK2) to the system clock. <BR> // APB2 can run up to 72MHz. <BR> <BR> RCC_PCLK2Config(RCC_HCLK_Div1); <BR> <BR> // Set the (low speed) APB1 clock (PCLK1) to the system clock/2. <BR> // APB1 can only run up to 36MHz. <BR> <BR> RCC_PCLK1Config(RCC_HCLK_Div2); <BR>

    [ This message was edited by: swhite on 09-07-2009 16:58 ]

    ozenozkaya
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:16

    hey guys;

    all the problem was about TIM_OCInitStructure.TIM_OCPolarity...

    it works fine with = TIM_OCPolarity_Low;

    thanks all:)

    ozenozkaya
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:16

    this works! in the configuration like: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE);

    gets the TIM3 value.

    but; still pwm doesnt work with:

    GPIO_InitTypeDef GPIO_InitStructure;

    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

    TIM_OCInitTypeDef TIM_OCInitStructure;

    //this pin functions as AF; when remapping

    GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);

    //GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE);

    /*GPIOC Configuration: TIM3 channel 1 */

    /* make sure that C port is opened in RCC*/

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOC, &GPIO_InitStructure);

    /* Time base configuration */

    TIM_TimeBaseStructure.TIM_Period = 999;

    TIM_TimeBaseStructure.TIM_Prescaler = 0;

    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_Channel = TIM_Channel_1;

    TIM_OCInitStructure.TIM_Pulse = 500;

    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OCInit(TIM3, &TIM_OCInitStructure);

    TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

    TIM_ARRPreloadConfig(TIM3, ENABLE);

    /* TIM3 enable counter */

    TIM_Cmd(TIM3, ENABLE);

    thanks in advance