NIH奥 发表于 2020-7-4 12:13

HC32F460 如何动态调节PWM占空比

我正在使用HC32F460 ,但是在示列程序中修改输出占空比,但是没有效果
stc_timer4_cnt_init_t stcCntInit;
    stc_timer4_oco_init_t stcOcoInit;
    stc_timer4_pwm_init_t stcPwmInit;
    stc_oco_low_ch_compare_mode_t stcLowChCmpMode;
    stc_oco_high_ch_compare_mode_t stcHighChCmpMode;
    uint16_t u8OcoOccrVal = TIMER4_CNT_CYCLE_VAL/2u;
    en_timer4_oco_ch_t enOcoLowCh = (en_timer4_oco_ch_t)(TIMER4_OCO_HIGH_CH + 1);

    /* Clear structures */
    MEM_ZERO_STRUCT(stcCntInit);
    MEM_ZERO_STRUCT(stcOcoInit);
    MEM_ZERO_STRUCT(stcLowChCmpMode);
    MEM_ZERO_STRUCT(stcHighChCmpMode);
    MEM_ZERO_STRUCT(stcPwmInit);

    /* Enable peripheral clock */
    PWC_Fcg2PeriphClockCmd(PWC_FCG2_PERIPH_TIM41 | PWC_FCG2_PERIPH_TIM42 | PWC_FCG2_PERIPH_TIM43, Enable);

    /* Timer4 CNT : Initialize CNT configuration structure */
    stcCntInit.enBufferCmd = Enable;//Disable;
    stcCntInit.enClk = Timer4CntPclk;
    stcCntInit.enClkDiv = Timer4CntPclkDiv16;/* CNT clock divide */
    stcCntInit.u16Cycle = TIMER4_CNT_CYCLE_VAL;
    stcCntInit.enCntMode = Timer4CntSawtoothWave;
    stcCntInit.enZeroIntCmd = Disable;
    stcCntInit.enPeakIntCmd = Disable;
    stcCntInit.enZeroIntMsk = Timer4CntIntMask0;
    stcCntInit.enPeakIntMsk = Timer4CntIntMask0;
    TIMER4_CNT_Init(TIMER4_UNIT, &stcCntInit); /* Initialize CNT */

    /* Timer4 OCO : Initialize OCO configuration structure */
    stcOcoInit.enOccrBufMode = OccrBufTrsfByCntZeroOrCntPeak;//OccrBufDisable;
    stcOcoInit.enOcmrBufMode = OcmrBufTrsfByCntZeroOrCntPeak;//OcmrBufDisable;
    stcOcoInit.enPortLevel = OcPortLevelLow;
    stcOcoInit.enOcoIntCmd = Disable;
    TIMER4_OCO_Init(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, &stcOcoInit); /* Initialize OCO high channel */
    TIMER4_OCO_Init(TIMER4_UNIT, enOcoLowCh, &stcOcoInit);         /* Initialize OCO low channel */

    if (!(TIMER4_OCO_HIGH_CH % 2))
    {
      /* ocmr = 0x0FFF */
      stcHighChCmpMode.enCntZeroMatchOpState = OcoOpOutputReverse;
      stcHighChCmpMode.enCntZeroNotMatchOpState = OcoOpOutputHold;
      stcHighChCmpMode.enCntUpCntMatchOpState = OcoOpOutputReverse;
      stcHighChCmpMode.enCntPeakMatchOpState = OcoOpOutputReverse;
      stcHighChCmpMode.enCntPeakNotMatchOpState = OcoOpOutputHold;
      stcHighChCmpMode.enCntDownCntMatchOpState = OcoOpOutputReverse;

      stcHighChCmpMode.enCntZeroMatchOcfState = OcoOcfSet;
      stcHighChCmpMode.enCntUpCntMatchOcfState = OcoOcfSet;
      stcHighChCmpMode.enCntPeakMatchOcfState = OcoOcfSet;
      stcHighChCmpMode.enCntDownCntMatchOcfState = OcoOcfSet;

      stcHighChCmpMode.enMatchConditionExtendCmd = Disable;

      TIMER4_OCO_SetHighChCompareMode(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, &stcHighChCmpMode);/* Set OCO high channel compare mode */
    }

    /*************Timer4 OCO ocmr1 = 0x0FF0 0FFF*****************************/
    if (enOcoLowCh % 2)
    {
      /* OCMR Ox 0FF0 0FFF    0000 1111 1111 0000   0000 1111 1111 1111 */
      stcLowChCmpMode.enCntZeroLowMatchHighMatchLowChOpState = OcoOpOutputReverse;         /* bit11 */
      stcLowChCmpMode.enCntZeroLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse;      /* bit11 */
      stcLowChCmpMode.enCntZeroLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;         /* bit00 */
      stcLowChCmpMode.enCntZeroLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold;      /* bit00 */

      stcLowChCmpMode.enCntUpCntLowMatchHighMatchLowChOpState = OcoOpOutputReverse;      /* bit11 */
      stcLowChCmpMode.enCntUpCntLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse;   /* bit    11 */
      stcLowChCmpMode.enCntUpCntLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;      /* bit00 */

      stcLowChCmpMode.enCntPeakLowMatchHighMatchLowChOpState = OcoOpOutputReverse;         /* bit11 */
      stcLowChCmpMode.enCntPeakLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse;      /* bit    11 */
      stcLowChCmpMode.enCntPeakLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;         /* bit00 */
      stcLowChCmpMode.enCntPeakLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold;      /* bit00 */

      stcLowChCmpMode.enCntDownLowMatchHighMatchLowChOpState = OcoOpOutputReverse;         /* bit11 */
      stcLowChCmpMode.enCntDownLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse;      /* bit    11 */
      stcLowChCmpMode.enCntDownLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;         /* bit00 */

      stcLowChCmpMode.enCntZeroMatchOcfState = OcoOcfSet;    /* bit 1 */
      stcLowChCmpMode.enCntUpCntMatchOcfState = OcoOcfSet;   /* bit 1 */
      stcLowChCmpMode.enCntPeakMatchOcfState = OcoOcfSet;    /* bit 1 */
      stcLowChCmpMode.enCntDownCntMatchOcfState = OcoOcfSet; /* bit 1 */

      TIMER4_OCO_SetLowChCompareMode(TIMER4_UNIT, enOcoLowCh, &stcLowChCmpMode);/* Set OCO low channel compare mode */
    }

    /* Set OCO compare value */
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, u8OcoOccrVal/2);
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, enOcoLowCh, u8OcoOccrVal);

    /* Enable OCO */
    TIMER4_OCO_OutputCompareCmd(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, Enable);
    TIMER4_OCO_OutputCompareCmd(TIMER4_UNIT, enOcoLowCh, Enable);

    /* Initialize PWM I/O */
    PORT_SetFunc(TIMER4_PWM_H_PORT, TIMER4_PWM_H_PIN, Func_Tim4, Disable);
    PORT_SetFunc(TIMER4_PWM_L_PORT, TIMER4_PWM_L_PIN, Func_Tim4, Disable);

    /* Timer4 PWM: Initialize PWM configuration structure */
    stcPwmInit.enRtIntMaskCmd = Enable;
    stcPwmInit.enClkDiv = PwmPlckDiv1;
    stcPwmInit.enOutputState = PwmHHoldPwmLReverse;
    stcPwmInit.enMode = PwmThroughMode;
    TIMER4_PWM_Init(TIMER4_UNIT, TIMER4_PWM_CH, &stcPwmInit); /* Initialize timer4 pwm */

    /* Clear && Start CNT */
    TIMER4_CNT_ClearCountVal(TIMER4_UNIT);
    TIMER4_CNT_Start(TIMER4_UNIT);
               
                TIMER4_OCO_WriteOccr(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, u8OcoOccrVal/2);
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, enOcoLowCh, u8OcoOccrVal/2);
               
                TIMER4_OCO_WriteOccr(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, u8OcoOccrVal/4);
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, enOcoLowCh, u8OcoOccrVal/4);

hh电子爱好者 发表于 2022-1-24 16:24

Timer4改变不了占空比,用timera就可以,你这里设置的只是相位的偏移,不是占空比的改变。
/* Set OCO compare value */
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, u8OcoOccrVal/2);
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, enOcoLowCh, u8OcoOccrVal);

martinhu 发表于 2022-1-25 14:40

hh电子爱好者 发表于 2022-1-24 16:24
Timer4改变不了占空比,用timera就可以,你这里设置的只是相位的偏移,不是占空比的改变。
/* Set OCO co ...

谁说timer4改变不了占空比的,这个本来就是给电机控制用的,当然,普通PWM的控制也可以。

martinhu 发表于 2022-1-25 17:14

本帖最后由 martinhu 于 2022-1-25 17:58 编辑

这个是锯齿波的OCMR的调制,仅供参考,楼主如果要用,估计得添加修改很多地方

/**
*******************************************************************************
** \briefMain function of project
**
** \paramNone
**
** \retval int32_t return value, if needed
**
******************************************************************************/
int32_t main(void)
{
    stc_timer4_cnt_init_t stcCntInit;
    stc_timer4_oco_init_t stcOcoInit;
    stc_timer4_pwm_init_t stcPwmInit;
    stc_irq_regi_conf_t stcIrqRegiCfg;
    stc_oco_low_ch_compare_mode_t stcLowChCmpMode;
    stc_oco_high_ch_compare_mode_t stcHighChCmpMode;
    uint16_t u8OcoOccrVal = TIMER4_CNT_CYCLE_VAL/2u;
    en_timer4_oco_ch_t enOcoLowCh = (en_timer4_oco_ch_t)(TIMER4_OCO_HIGH_CH + 1);

    /* Clear structures */
    MEM_ZERO_STRUCT(stcCntInit);
    MEM_ZERO_STRUCT(stcOcoInit);
    MEM_ZERO_STRUCT(stcLowChCmpMode);
    MEM_ZERO_STRUCT(stcHighChCmpMode);
    MEM_ZERO_STRUCT(stcPwmInit);
    MEM_ZERO_STRUCT(stcIrqRegiCfg);
   
    BSP_CLK_Init();
   
    /* Initialize LED */
    BSP_LED_Init();
   
    M4_DBGC->MCUSTPCTL_f.TMR41STP = 1;
   
    /* Initialize PWM I/O */
    PORT_SetFunc(TIMER4_PWM_H_PORT, TIMER4_PWM_H_PIN, Func_Tim4, Disable);
    PORT_SetFunc(TIMER4_PWM_L_PORT, TIMER4_PWM_L_PIN, Func_Tim4, Disable);

    M4_PORT->PORRB_f.POR05 = 1;
    M4_PORT->POERB_f.POUTE05 = 1;

    /* Enable peripheral clock */
    PWC_Fcg2PeriphClockCmd(PWC_FCG2_PERIPH_TIM41 | PWC_FCG2_PERIPH_TIM42 | PWC_FCG2_PERIPH_TIM43, Enable);

    /* Timer4 CNT : Initialize CNT configuration structure */
    stcCntInit.enBufferCmd = Enable;//Disable;
    stcCntInit.enClk = Timer4CntPclk;
    stcCntInit.enClkDiv = Timer4CntPclkDiv16;/* CNT clock divide */
    stcCntInit.u16Cycle = TIMER4_CNT_CYCLE_VAL;
    stcCntInit.enCntMode = Timer4CntSawtoothWave;
    stcCntInit.enZeroIntCmd = Enable;//Disable;
    stcCntInit.enPeakIntCmd = Disable;
    stcCntInit.enZeroIntMsk = Timer4CntIntMask0;//Timer4CntIntMask15;//
    stcCntInit.enPeakIntMsk = Timer4CntIntMask0;
    TIMER4_CNT_Init(TIMER4_UNIT, &stcCntInit); /* Initialize CNT */

    /* Timer4 OCO : Initialize OCO configuration structure */
    stcOcoInit.enOccrBufMode = OccrBufTrsfByCntZeroZicZero;//OccrBufDisable;
    stcOcoInit.enOcmrBufMode = OcmrBufDisable;
    stcOcoInit.enPortLevel = OcPortLevelLow;
    stcOcoInit.enOcoIntCmd = Disable;
    TIMER4_OCO_Init(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, &stcOcoInit); /* Initialize OCO high channel */
    TIMER4_OCO_Init(TIMER4_UNIT, enOcoLowCh, &stcOcoInit);         /* Initialize OCO low channel */

    if (!(TIMER4_OCO_HIGH_CH % 2))
    {
      /* ocmr = 0x4A4F */      
      
      stcHighChCmpMode.enCntUpCntMatchOpState = OcoOpOutputLow;         //bit    //向上计数&匹配
      
      stcHighChCmpMode.enCntPeakNotMatchOpState = OcoOpOutputHold;      //bit//上溢&不匹配
      stcHighChCmpMode.enCntPeakMatchOpState = OcoOpOutputHigh; //OcoOpOutputLow;//      //bit    //上溢&匹配
      
      stcHighChCmpMode.enCntDownCntMatchOpState = OcoOpOutputHold;      //bit    //向下计数&匹配
      
      stcHighChCmpMode.enCntZeroNotMatchOpState = OcoOpOutputHigh;      //bit//下溢&不匹配
      stcHighChCmpMode.enCntZeroMatchOpState = OcoOpOutputLow;          //bit//下溢&匹配
      
      stcHighChCmpMode.enCntZeroMatchOcfState = OcoOcfSet;            //bit
      stcHighChCmpMode.enCntUpCntMatchOcfState = OcoOcfSet;             //bit
      stcHighChCmpMode.enCntPeakMatchOcfState = OcoOcfSet;            //bit
      stcHighChCmpMode.enCntDownCntMatchOcfState = OcoOcfSet;         //bit

      stcHighChCmpMode.enMatchConditionExtendCmd = Disable;

      TIMER4_OCO_SetHighChCompareMode(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, &stcHighChCmpMode);/* Set OCO high channel compare mode */
    }

    #if 0
    /*************Timer4 OCO ocmr1 = 0x4A40 4A4F   Only control by OCMERnL*****************************/
    if (enOcoLowCh % 2)
    {
      /* OCMR Ox 0FF0 0FFF    0000 1111 1111 0000   0000 1111 1111 1111 */
      stcLowChCmpMode.enCntZeroLowNotMatchHighMatchLowChOpState = OcoOpOutputHigh;    /* bit   */ //计数下溢 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntZeroLowMatchHighMatchLowChOpState = OcoOpOutputLow;      /* bit   */ //计数器下溢 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntZeroLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHigh; /* bit   */ //计数器下溢 & OCCRnL不匹配 & OCCRnH不匹配
      stcLowChCmpMode.enCntZeroLowMatchHighNotMatchLowChOpState = OcoOpOutputLow;   /* bit   */ //计数器下溢 & OCCRnL匹配 & OCCRnH不匹配

      stcLowChCmpMode.enCntUpCntLowMatchHighMatchLowChOpState = OcoOpOutputLow;       /* bit   */ //向上计数 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntUpCntLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;   /* bit   */ //向上计数 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntUpCntLowMatchHighNotMatchLowChOpState = OcoOpOutputLow;    /* bit   */ //向上计数 & OCCRnL匹配 & OCCRnH不匹配

      stcLowChCmpMode.enCntPeakLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //计数器上溢 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntPeakLowMatchHighMatchLowChOpState = OcoOpOutputHigh;       /* bit   */ //计数器上溢 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntPeakLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold; /* bit   */ //计数器上溢 & OCCRnL不匹配 & OCCRnH不匹配
      stcLowChCmpMode.enCntPeakLowMatchHighNotMatchLowChOpState = OcoOpOutputHigh;    /* bit   */ //计数器上溢 & OCCRnL匹配 & OCCRnH不匹配

      stcLowChCmpMode.enCntDownLowMatchHighMatchLowChOpState = OcoOpOutputHold;       /* bit   */ //向下计数 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntDownLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //向下计数 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntDownLowMatchHighNotMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //向下计数 & OCCRnL匹配 & OCCRnH不匹配
      
      stcLowChCmpMode.enCntZeroMatchOcfState = OcoOcfSet;    /* bit 1 */
      stcLowChCmpMode.enCntUpCntMatchOcfState = OcoOcfSet;   /* bit 1 */
      stcLowChCmpMode.enCntPeakMatchOcfState = OcoOcfSet;    /* bit 1 */
      stcLowChCmpMode.enCntDownCntMatchOcfState = OcoOcfSet; /* bit 1 */

      TIMER4_OCO_SetLowChCompareMode(TIMER4_UNIT, enOcoLowCh, &stcLowChCmpMode);/* Set OCO low channel compare mode */
    }
   
    #else
   
    /*************Timer4 OCO ocmr1 = 0x4484 028F   Control by OCMERnL and OCMERnH*********************/
    if (enOcoLowCh % 2)
    {
      /* OCMR Ox 0FF0 0FFF    0000 1111 1111 0000   0000 1111 1111 1111 */
      stcLowChCmpMode.enCntZeroLowNotMatchHighMatchLowChOpState = OcoOpOutputHigh;    /* bit   */ //计数下溢 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntZeroLowMatchHighMatchLowChOpState = OcoOpOutputHigh;       /* bit   */ //计数器下溢 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntZeroLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold; /* bit   */ //计数器下溢 & OCCRnL不匹配 & OCCRnH不匹配
      stcLowChCmpMode.enCntZeroLowMatchHighNotMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //计数器下溢 & OCCRnL匹配 & OCCRnH不匹配

      stcLowChCmpMode.enCntUpCntLowMatchHighMatchLowChOpState = OcoOpOutputHold;      /* bit   */ //向上计数 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntUpCntLowNotMatchHighMatchLowChOpState = OcoOpOutputHigh;   /* bit   */ //向上计数 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntUpCntLowMatchHighNotMatchLowChOpState = OcoOpOutputLow;    /* bit   */ //向上计数 & OCCRnL匹配 & OCCRnH不匹配

      stcLowChCmpMode.enCntPeakLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //计数器上溢 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntPeakLowMatchHighMatchLowChOpState = OcoOpOutputLow;      /* bit   */ //计数器上溢 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntPeakLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold; /* bit   */ //计数器上溢 & OCCRnL不匹配 & OCCRnH不匹配
      stcLowChCmpMode.enCntPeakLowMatchHighNotMatchLowChOpState = OcoOpOutputLow;   /* bit   */ //计数器上溢 & OCCRnL匹配 & OCCRnH不匹配

      stcLowChCmpMode.enCntDownLowMatchHighMatchLowChOpState = OcoOpOutputHold;       /* bit   */ //向下计数 & OCCRnL匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntDownLowNotMatchHighMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //向下计数 & OCCRnL不匹配 & OCCRnH匹配
      stcLowChCmpMode.enCntDownLowMatchHighNotMatchLowChOpState = OcoOpOutputHold;    /* bit   */ //向下计数 & OCCRnL匹配 & OCCRnH不匹配
      
      stcLowChCmpMode.enCntZeroMatchOcfState = OcoOcfSet;    /* bit 1 */
      stcLowChCmpMode.enCntUpCntMatchOcfState = OcoOcfSet;   /* bit 1 */
      stcLowChCmpMode.enCntPeakMatchOcfState = OcoOcfSet;    /* bit 1 */
      stcLowChCmpMode.enCntDownCntMatchOcfState = OcoOcfSet; /* bit 1 */

      TIMER4_OCO_SetLowChCompareMode(TIMER4_UNIT, enOcoLowCh, &stcLowChCmpMode);/* Set OCO low channel compare mode */
    }
   
    #endif
   

    /* Set OCO compare value */
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, u8OcoOccrVal);
    TIMER4_OCO_WriteOccr(TIMER4_UNIT, enOcoLowCh, u8OcoOccrVal);
   
//    M4_TMR41->OCSRU_f.OCPH = 1;
//    M4_TMR41->OCSRU_f.OCPL = 1;
   
    //M4_TMR41->OCERU_f.MCECH = 1;

    /* Enable OCO */
    TIMER4_OCO_OutputCompareCmd(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, Enable);
    TIMER4_OCO_OutputCompareCmd(TIMER4_UNIT, enOcoLowCh, Enable);


    /* Timer4 PWM: Initialize PWM configuration structure */
    stcPwmInit.enRtIntMaskCmd = Disable;//Enable;
    stcPwmInit.enClkDiv = PwmPlckDiv1;
    stcPwmInit.enOutputState = PwmHPwmLHold;
    stcPwmInit.enMode = PwmThroughMode;
    TIMER4_PWM_Init(TIMER4_UNIT, TIMER4_PWM_CH, &stcPwmInit); /* Initialize timer4 pwm */
   
   
//    TIMER4_OCO_IrqCmd(TIMER4_UNIT, TIMER4_OCO_HIGH_CH, Enable);
//    /* Set Timer4-CNT IRQ */
//    stcIrqRegiCfg.enIRQn = Int000_IRQn;
//    stcIrqRegiCfg.pfnCallback = &CmpUhMatchIrqCb;
//    stcIrqRegiCfg.enIntSrc = INT_TMR41_GCMUH;
//    enIrqRegistration(&stcIrqRegiCfg);
//    NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
//    NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn);
//    NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn);


    /* Set Timer4-CNT IRQ */
    stcIrqRegiCfg.enIRQn = Int001_IRQn;
    stcIrqRegiCfg.pfnCallback = &CmpZeroMatchIrqCb;
    stcIrqRegiCfg.enIntSrc = INT_TMR41_GUDF;
    enIrqRegistration(&stcIrqRegiCfg);
    NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
    NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn);
    NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn);

    M4_PORT->POSRB_f.POS05 = 1;
   

    /* Clear && Start CNT */
    TIMER4_CNT_ClearCountVal(TIMER4_UNIT);
    TIMER4_CNT_Start(TIMER4_UNIT);

woai32lala 发表于 2022-1-26 08:05

直接修改输出占空比不就好了?

hilahope 发表于 2022-2-13 14:08

这个没有用过,应该跟stm32一样的,能修改。

sesefadou 发表于 2022-2-13 17:05

HC32F460还有这个bug吗      

myiclife 发表于 2022-2-13 17:15

把代码重新初始化呢?   

touser 发表于 2022-2-13 17:24

直接修改寄存器不行吗

fengm 发表于 2022-2-13 17:33

是初始化的就有问题吗?

maudlu 发表于 2022-2-13 17:42

可以动态修正吧,尝试关闭定时器,修改,再打开呢

海滨消消 发表于 2022-2-15 15:51

这个是在哪个过程中出现的问题了

tail066 发表于 2022-2-18 13:37

我一般是通过反馈量来改占空比的,
pwm就是脉宽调制,你能输出波形,就能改占空比
页: [1]
查看完整版本: HC32F460 如何动态调节PWM占空比