2020-05-18 08:16 AM
I have new application used stm8l051, The MCU using timer2(GPIOB2) to generator 125khz PWM, duty cycle from 0% to 100% every 500ms with 16Mhz clock source.
void Timer2_PWM_Init(void)
{
GPIO_Init(GPIOB, GPIO_Pin_2, GPIO_Mode_Out_PP_High_Fast);
CLK_PeripheralClockConfig(CLK_Peripheral_TIM2,ENABLE);
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_Prescaler_1, TIM2_CounterMode_Up, 127); // 16MHz clock source, 125kHz
TIM2_OC1Init(TIM2_OCMode_PWM2, TIM2_OutputState_Enable, 0, TIM2_OCPolarity_Low, TIM2_OCIdleState_Set);
TIM2_Cmd(ENABLE);
}
void Timer2_PWM_SetDutyCycle(U8 Timer2_PWM_DutyCycle)
{
TIM2_SetCompare1(127*Timer2_PWM_DutyCycle/100);
}
This code is not working when generator 125Khz, but I did change output to 10khz it is work well, I attached the picture.I don't know reason of MCU. I have try with stm32f070 result is same.