2016-12-26 03:02 AM
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);Solved! Go to Solution.
2016-12-26 06:39 AM
Hello
Mohamadi.Parisa
,I advise you to rearrange your code.
- configure the GPIO
- configure the TIMER
- Then enable the TIMER
Note: This condition should be respected: TIM_Period > TIM_Pulse
I think you are confusing between the prescaler and the period values.
There is a lot of examples using
or . They will help you to generate the PWM pulses correctly.If this solves your issue, please click on correct
:)
.Regards,
Khouloud
2016-12-26 06:39 AM
Hello
Mohamadi.Parisa
,I advise you to rearrange your code.
- configure the GPIO
- configure the TIMER
- Then enable the TIMER
Note: This condition should be respected: TIM_Period > TIM_Pulse
I think you are confusing between the prescaler and the period values.
There is a lot of examples using
or . They will help you to generate the PWM pulses correctly.If this solves your issue, please click on correct
:)
.Regards,
Khouloud