1

I understand its principle is to use PWM comparison function when CRR = CNT is triggered interrupt and flip level. I set the ARR to 65535 to automatically add it up again. The CRR value is adjusted for each incoming interrupt, however the PWM waveform does not seem to be ideal

This is my cubemx setting

My TIM_IT code

void TIM3_IRQHandler(void)
{
/\* USER CODE BEGIN TIM3_IRQn 0 \*/

    if (__HAL_TIM_GET_FLAG(&htim3, TIM_FLAG_CC1) != RESET)
    {
        __HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_CC1);
        TIM3->CCR1+=10000;
        return;
    }
    if (__HAL_TIM_GET_FLAG(&htim3, TIM_FLAG_CC2) != RESET)
    {
        __HAL_TIM_CLEAR_FLAG(&htim3,TIM_FLAG_CC2);
        TIM3->CCR2+=5000;
        return;
    }

/\* USER CODE END TIM3_IRQn 0 */*
HAL_TIM_IRQHandler(&htim3);
/ USER CODE BEGIN TIM3_IRQn 1 \*/

/\* USER CODE END TIM3_IRQn 1 \*/
}\
haotian li
  • 11
  • 2

0 Answers0