AnsweredAssumed Answered

STM32F4 PWM

Question asked by koleff.lucas on Dec 5, 2014
Latest reply on Dec 10, 2014 by Amel N
Hello,

I'm trying to change the  duty cycle of TIM1 in PWM Mode, but somehow my code is not working.

void TIM1_CC_IRQHandler(void)
{
  HAL_NVIC_ClearPendingIRQ(TIM1_CC_IRQn);
  HAL_TIM_IRQHandler(&htim1);
    cx++;
    if (cx>450)
    {
        cx=0;
    }


    TIM1->CCR1=cx;
    TIM1->CCR2=cx;
    TIM1->CCR3=cx;

}

If I remove the lines


    TIM1->CCR1=cx;
    TIM1->CCR2=cx;
    TIM1->CCR3=cx;

the code works fine, but without changing the duty cycle of course.

How can I change the duty cycle on the fly?

Thanks

Outcomes