Skip to main content
cpinkstone
Associate II
July 9, 2009
Question

PWM on PA8 STM32

  • July 9, 2009
  • 4 replies
  • 1231 views
Posted on July 09, 2009 at 11:02

PWM on PA8 STM32

    This topic has been closed for replies.

    4 replies

    jj_it
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:48

    Suggest that you first configure PA8 as GPIO and toggle. Armed with that success I suspect that you have missed the set-up/enable of some clock.

    Look carefully @ the newest TIM1 examples - most I've tried have worked.

    Check that you have newest version of Keil & that it ''plays'' nicely w/ your code library. Good luck.

    cpinkstone
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:48

    Dear All,

    I'm trying to get a 4KHz square wave out of PA8 using TIM1 in PWM mode.

    I've tried the various keil and st examples based on timer 3 but I having trouble gettting this working on TIM1.

    Is there something extra I've got to configure on timer 1?

    Could anyone post some source for this?

    Thanks

    ozenozkaya
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:48

    i am trying to use TIM3 Channel 1 as PWM from PC6 as AF; but the brigthness doesnt change. what am i doing wrong?? pls help...

    here is the code:

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM3 , ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

    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);

    /*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);

    TIM_Cmd(TIM3, DISABLE);

    TIM_ARRPreloadConfig(TIM3, ENABLE);

    /* 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);

    TIM_SetCompare1(TIM3,0x10);

    cpinkstone
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:48

    jj,

    It was the TIM1 clock enable I'd forgotten!

    Cheers. :)