cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32F0 TIM16 PWM not continuous

hdemi.1
Associate III

0693W00000Y90r4QAB.pngPwm 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);

}

3 REPLIES 3
gbm
Lead III

How many times do you cal this function in your code? Should be called only once during init.

hdemi.1
Associate III

1 time

AScha.3
Chief II

try with lower pwm frequ. or check with a scope (to avoid sampling problem)

and show measurement.

If you feel a post has answered your question, please click "Accept as Solution".