最后代码修改如下:/**
*******************************************************************************
** \brief Configure Timera peripheral function
**
** \param [in] None
**
** \retval None
**
******************************************************************************/
static void Timera_Config(void)
{
stc_timera_base_init_t stcTimeraInit;
stc_timera_compare_init_t stcTimerCompareInit;
stc_irq_regi_conf_t stcIrqRegiConf;
stc_timera_hw_startup_config_t stcTimeraHwConfig;
stc_port_init_t stcPortInit;
/* configuration structure initialization */
MEM_ZERO_STRUCT(stcTimeraInit);
MEM_ZERO_STRUCT(stcIrqRegiConf);
MEM_ZERO_STRUCT(stcTimerCompareInit);
MEM_ZERO_STRUCT(stcTimeraHwConfig);
MEM_ZERO_STRUCT(stcPortInit);
/* Configuration peripheral clock */
PWC_Fcg2PeriphClockCmd(TIMERA_UNIT1_CLOCK, Enable);
/* Configuration TIMERA compare pin */
PORT_SetFunc(TIMERA_UNIT1_CH4_PORT, TIMERA_UNIT1_CH4_PIN, TIMERA_UNIT1_CH4_FUNC, Disable);
/* Configuration timera unit 1 base structure */
stcTimeraInit.enClkDiv = TimeraPclkDiv32;
stcTimeraInit.enCntMode = TimeraCountModeSawtoothWave;//TimeraCountModeTriangularWave;
stcTimeraInit.enCntDir = TimeraCountDirUp;
stcTimeraInit.enSyncStartupEn = Disable;
stcTimeraInit.u16PeriodVal = 0x20Cu; //freq:5kHz //0xCD0u; //freq: 100Hz
TIMERA_BaseInit(TIMERA_UNIT1, &stcTimeraInit);
/* Configuration timera unit 1 compare structure */
stcTimerCompareInit.u16CompareVal = stcTimeraInit.u16PeriodVal * 3u / 10u; //占空比70%
stcTimerCompareInit.enStartCountOutput = TimeraCountStartOutputLow;
stcTimerCompareInit.enStopCountOutput = TimeraCountStopOutputLow;
stcTimerCompareInit.enCompareMatchOutput = TimeraCompareMatchOutputHigh;//TimeraCompareMatchOutputReverse;
stcTimerCompareInit.enPeriodMatchOutput = TimeraCompareMatchOutputLow;//TimeraPeriodMatchOutputKeep;
stcTimerCompareInit.enSpecifyOutput = TimeraSpecifyOutputInvalid; //该寄存器可用于实现PWM输出占空比0%或100%
stcTimerCompareInit.enCacheEn = Enable;
stcTimerCompareInit.enTriangularTroughTransEn = Enable;
stcTimerCompareInit.enTriangularCrestTransEn = Disable;
stcTimerCompareInit.u16CompareCacheVal = stcTimerCompareInit.u16CompareVal;
/* Configure Channel 1 */
TIMERA_CompareInit(TIMERA_UNIT1, TIMERA_UNIT1_CH4, &stcTimerCompareInit);
TIMERA_CompareCmd(TIMERA_UNIT1, TIMERA_UNIT1_CH4, Disable);
TIMERA_Cmd(TIMERA_UNIT1, Disable);
}
|
———————————————— 版权声明:本文为CSDN博主「Top0_0lll」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_39597546/article/details/121661981