2010-01-10 01:39 AM
PWM on TIM1
2011-05-17 04:35 AM
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.2011-05-17 04:35 AM
Hi Sompong,
You may start with one of the PWM examples available inhttp://www.st.com/stonline/products/support/micro/files/stm32f10x_stdperiph_lib.zip
;)2011-05-17 04:35 AM
2011-05-17 04:35 AM
Hi,
in your configuration the period = 99 < pulse = 500, to generate correctly a PWM signal the period should be > than pulse value. Cioa