AnsweredAssumed Answered

Pulse Width Modulation in stm32f10x

Question asked by mohamadi.parisa on Dec 26, 2016
Latest reply on Dec 26, 2016 by Khouloud G

Hello

Here is my Pulse Width Modulation function that doesn't work properly.what is my mistake?

Input Freq:72Mhz

Chip: f107

output pin:PA.0

TIM_TimeBaseInitTypeDef TStructure;
TIM_OCInitTypeDef OCStructure;
GPIO_InitTypeDef GPStruc;    
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);

 

TStructure.TIM_Prescaler=7199;
TStructure.TIM_CounterMode=TIM_CounterMode_Up;
TStructure.TIM_Period=9;
TStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM5, &TStructure);
TIM_Cmd(TIM5, ENABLE);    

OCStructure.TIM_OCMode=TIM_OCMode_PWM2;
OCStructure.TIM_OutputState=TIM_OutputState_Enable;
OCStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
OCStructure.TIM_Pulse=3599;
TIM_OC1Init(TIM5, &OCStructure);
TIM_OC1PreloadConfig(TIM5, TIM_OCPreload_Enable);    

GPStructure.GPIO_Mode=GPIO_Mode_AF_PP ;
GPStructure.GPIO_Speed=GPIO_Speed_2MHz;
GPStructure.GPIO_Pin=GPIO_Pin_0;
GP_Init(GPIOA,&GPStructure);

Outcomes