Skip to main content
Visitor II
June 28, 2025
Question

Configure stm32g474 HRTIM ?

  • June 28, 2025
  • 3 replies
  • 3986 views

tima 的pwm输出正确,但是timb的pwm一个周期出现无法reset的情况

1000063108.jpg

    This topic has been closed for replies.

    3 replies

    Technical Moderator
    June 30, 2025

    Hello @xcm 

    Please try to write in English to make sure you can get an answer, because most of the people on this community can speak English but not Chinois.
    If possible, to provide more details on your issue and share your code, TIM configuration, software version used.

    Did you check the known HRTIM limitations in the STM32G471xx/473xx/474xx/483xx/484xx device errata - Errata sheet?

    xcmAuthor
    Visitor II
    July 3, 2025

    ok,

    void HAL_HRTIM_RepetitionEventCallback(HRTIM_HandleTypeDef *hhrtim, uint32_t TimerIdx)//20kHz中断
    {
    if (TimerIdx == HRTIM_TIMERINDEX_TIMER_A)
    {
    HAL_HRTIM_WaveformOutputStart(&hhrtim1,HRTIM_OUTPUT_TA1 | HRTIM_OUTPUT_TA2 | HRTIM_OUTPUT_TB1 | HRTIM_OUTPUT_TB2 | HRTIM_OUTPUT_TC1 | HRTIM_OUTPUT_TC2);
    //HAL_HRTIM_WaveformOutputStart(&hhrtim1,HRTIM_OUTPUT_TB1 | HRTIM_OUTPUT_TB2);
    
    hhrtim1.Instance->sTimerxRegs[0].CMP1xR = SPWM_400[i];
    hhrtim1.Instance->sTimerxRegs[0].CMP3xR =SPWM_400[399-i];
    
    hhrtim1.Instance->sTimerxRegs[1].CMP1xR = SPWM_400[i];
    hhrtim1.Instance->sTimerxRegs[1].CMP3xR = SPWM_400[399-i];
    
    }
    }

    The two PWM is not the same as the picture shows.how to solve it.every period has a wrong pwm(50Hz).TA1(the red one) is correct while the TB1(the yellow one) is not the same as i set.


    Edited to apply source code formatting - please see How to insert source code for future reference.

    xcmAuthor
    Visitor II
    July 2, 2025

    ok,

    void HAL_HRTIM_RepetitionEventCallback(HRTIM_HandleTypeDef *hhrtim, uint32_t TimerIdx)//20kHz中断
    {
    if (TimerIdx == HRTIM_TIMERINDEX_TIMER_A)
    {
    HAL_HRTIM_WaveformOutputStart(&hhrtim1,HRTIM_OUTPUT_TA1 | HRTIM_OUTPUT_TA2 | HRTIM_OUTPUT_TB1 | HRTIM_OUTPUT_TB2 | HRTIM_OUTPUT_TC1 | HRTIM_OUTPUT_TC2);
    //HAL_HRTIM_WaveformOutputStart(&hhrtim1,HRTIM_OUTPUT_TB1 | HRTIM_OUTPUT_TB2);
    
    hhrtim1.Instance->sTimerxRegs[0].CMP1xR = SPWM_400[i];
    hhrtim1.Instance->sTimerxRegs[0].CMP3xR =SPWM_400[399-i];
    
    hhrtim1.Instance->sTimerxRegs[1].CMP1xR = SPWM_400[i];
    hhrtim1.Instance->sTimerxRegs[1].CMP3xR = SPWM_400[399-i];
    
    }
    }

    The two PWM is not the same as the picture shows.how to solve it.every period has a wrong pwm(50Hz).


    Edited to apply source code formatting - please see How to insert source code for future reference.

    Technical Moderator
    July 3, 2025

    What about CKPSC? Make sure to adjust the clock prescaler and timing parameters to ensure cycle accuracy.

    xcmAuthor
    Visitor II
    July 3, 2025

    xcm_0-1751533256936.png

    xcm_1-1751533268109.png

    which one?what can I do ?