2023-01-24 02:37 AM
Pwm is not continuous My clock freq 20mhz
Where am i doing wrong ?
void PWMparamc(uint32_t PWM_freq, uint8_t duty){
PWMparam.period = (SystemCoreClock / PWM_freq) - 1;
//PWMparam.prescaler = (SystemCoreClock / TimerTickFreq ) ;
temp_duty = ((float)duty)/100 ;
PWMparam.newDuty = ((PWMparam.period+1)*(temp_duty)) -1 ;
PWMparam.pulse = PWMparam.newDuty ;
}
void PWM_TIMER_Config(){
PWMparamc(250000,50);
TIM_TimeBaseInitTypeDef TIM_InitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct; // OC: Output Channel
NVIC_InitTypeDef NVIC_InitStructure ;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);
PWM_GPIO_Config();
TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_InitStruct.TIM_Prescaler = 0 ;
TIM_InitStruct.TIM_Period = PWMparam.period ;
TIM_InitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(PingTIMER, &TIM_InitStruct);
// Timer PWM Konfigurasyonu
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_Cmd(TIM16,ENABLE);
}
2023-01-24 02:44 AM
How many times do you cal this function in your code? Should be called only once during init.
2023-01-24 11:05 PM
1 time
2023-01-25 12:46 AM
try with lower pwm frequ. or check with a scope (to avoid sampling problem)
and show measurement.