我正在使用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[15:0] = 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[31:0] = 0x0FF0 0FFF*****************************/
if (enOcoLowCh % 2)
{
/* OCMR[31:0] Ox 0FF0 0FFF 0000 1111 1111 0000 0000 1111 1111 1111 */
stcLowChCmpMode.enCntZeroLowMatchHighMatchLowChOpState = OcoOpOutputReverse; /* bit[27:26] 11 */
stcLowChCmpMode.enCntZeroLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse; /* bit[11:10] 11 */
stcLowChCmpMode.enCntZeroLowNotMatchHighMatchLowChOpState = OcoOpOutputHold; /* bit[31:30] 00 */
stcLowChCmpMode.enCntZeroLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold; /* bit[15:14] 00 */
stcLowChCmpMode.enCntUpCntLowMatchHighMatchLowChOpState = OcoOpOutputReverse; /* bit[25:24] 11 */
stcLowChCmpMode.enCntUpCntLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse; /* bit[9:8] 11 */
stcLowChCmpMode.enCntUpCntLowNotMatchHighMatchLowChOpState = OcoOpOutputHold; /* bit[19:18] 00 */
stcLowChCmpMode.enCntPeakLowMatchHighMatchLowChOpState = OcoOpOutputReverse; /* bit[23:22] 11 */
stcLowChCmpMode.enCntPeakLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse; /* bit[7:6] 11 */
stcLowChCmpMode.enCntPeakLowNotMatchHighMatchLowChOpState = OcoOpOutputHold; /* bit[29:28] 00 */
stcLowChCmpMode.enCntPeakLowNotMatchHighNotMatchLowChOpState = OcoOpOutputHold; /* bit[13:12] 00 */
stcLowChCmpMode.enCntDownLowMatchHighMatchLowChOpState = OcoOpOutputReverse; /* bit[21:20] 11 */
stcLowChCmpMode.enCntDownLowMatchHighNotMatchLowChOpState = OcoOpOutputReverse; /* bit[5:4] 11 */
stcLowChCmpMode.enCntDownLowNotMatchHighMatchLowChOpState = OcoOpOutputHold; /* bit[17:16] 00 */
stcLowChCmpMode.enCntZeroMatchOcfState = OcoOcfSet; /* bit[3] 1 */
stcLowChCmpMode.enCntUpCntMatchOcfState = OcoOcfSet; /* bit[2] 1 */
stcLowChCmpMode.enCntPeakMatchOcfState = OcoOcfSet; /* bit[1] 1 */
stcLowChCmpMode.enCntDownCntMatchOcfState = OcoOcfSet; /* bit[0] 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); |