cancel
Showing results for 
Search instead for 
Did you mean: 

PWM on TIM1

sompong1990
Associate II
Posted on January 10, 2010 at 10:39

PWM on TIM1

4 REPLIES 4
sompong1990
Associate II
Posted on May 17, 2011 at 13:35

Hi All,

I want to use PWM on TIM1 CH1 (PA8) with STM32F103RBT6.

But no any output signal.

I search on this forum, Many question like me, But not work.

Code:

/* Set Clock */

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_TIM1 |

RCC_APB2Periph_AFIO , ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 99;

TIM_TimeBaseStructure.TIM_Prescaler = 100;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

TIM_ARRPreloadConfig(TIM1, ENABLE);

/* PWM1 Mode configuration: Channel1 */

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse = 500;

TIM_OC1Init(TIM1, &TIM_OCInitStructure);

TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);

/* TIM1 enable counter */

TIM_CtrlPWMOutputs(TIM1, ENABLE);

TIM_Cmd(TIM1, ENABLE);

What is wrong ?.

Help me, please.

Sompong J.

kaouther
Associate II
Posted on May 17, 2011 at 13:35

Hi Sompong,

You may start with one of the PWM examples available in

http://www.st.com/stonline/products/support/micro/files/stm32f10x_stdperiph_lib.zip

;)

dwooller
Associate II
Posted on May 17, 2011 at 13:35

linda1
Associate
Posted on May 17, 2011 at 13:35

Hi,

in your configuration the period  = 99 < pulse = 500,

to generate correctly a PWM signal the period should be > than pulse value.

Cioa