2023-01-25 03:26 AM
I try to divide pwm like that TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
it is not working. I am using stm32f030
TIM_TimeBaseInitTypeDef TIM_InitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct; // OC: Output Channel
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); //TIM16 for stm32f030RST6
TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_InitStruct.TIM_Prescaler = 0 ;
TIM_InitStruct.TIM_Period = 249;//PWMparam.period ;
TIM_InitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(PingTIMER, &TIM_InitStruct);
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStruct.TIM_OCNPolarity = TIM_OCNPolarity_High ;
TIM_OCInitStruct.TIM_OutputNState = TIM_OutputNState_Enable ;
TIM_OCInitStruct.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Set ;
TIM_OCInitStruct.TIM_Pulse = PWMparam.pulse;
TIM_OC1PreloadConfig(TIM16,TIM_OCPreload_Enable);
TIM_CtrlPWMOutputs(TIM16,ENABLE);
TIM_OC1Init(TIM16, &TIM_OCInitStruct);
TIM_ITConfig(TIM16,TIM_IT_Update,ENABLE);
NVIC_EnableIRQ(TIM16_IRQn);
TIM_Cmd(PingTIMER,ENABLE);
}
2023-01-25 07:08 AM
> I try to divide pwm like that TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
That does not "divide PWM". CKD is a clock for input capture filter and for the deadtime setting.
I don't quite know what do you mean by "divide PWM", but maybe you want to try to change the Prescaler setting.
JW