//20221211
App_ClockInit(); //时钟初始化//这一块是时钟的初始化//number1
//
App_AdvTimerInit(0xC000, 0x4000, 0x8000); //AdvTimer4初始化//number2
//配置为锯齿波模式: 周期0xC000, CHA占空比设置0x4000,CHB占空比设置0x8000
//对于锯齿波的理解
App_AdvTimerPortInit(); //AdvTimer端口初始化//number3
Adt_StartCount(M0P_ADTIM4); //AdvTimer4运行
while(1);
//number1 时钟初始化
//number2 App_AdvTimerInit 的分析
Sysctrl_SetPeripheralGate(SysctrlPeripheralAdvTim, TRUE); //ADT外设时钟使能
stcAdtBaseCntCfg.enCntMode = AdtSawtoothMode; //锯齿波模式
stcAdtBaseCntCfg.enCntDir = AdtCntUp; //向上计数
stcAdtBaseCntCfg.enCntClkDiv = AdtClkPClk0; //CLK的零分配
Adt_Init(M0P_ADTIM4, &stcAdtBaseCntCfg); //ADT载波、计数模式、时钟配置
Adt_SetPeriod(M0P_ADTIM4, u16Period); //周期设置
enAdtCompareA = AdtCompareA;
Adt_SetCompareValue(M0P_ADTIM4, enAdtCompareA, u16CHA_PWMDuty); //通用比较基准值寄存器A设置
enAdtCompareB = AdtCompareB;
Adt_SetCompareValue(M0P_ADTIM4, enAdtCompareB, u16CHB_PWMDuty); //通用比较基准值寄存器B设置
stcAdtTIM4ACfg.enCap = AdtCHxCompareOutput; //比较输出
stcAdtTIM4ACfg.bOutEn = TRUE; //CHA输出使能
stcAdtTIM4ACfg.enPerc = AdtCHxPeriodLow; //计数值与周期匹配时CHA电平保持不变
stcAdtTIM4ACfg.enCmpc = AdtCHxCompareHigh; //计数值与比较值A匹配时,CHA电平翻转
stcAdtTIM4ACfg.enStaStp = AdtCHxStateSelSS; //CHA起始结束电平由STACA与STPCA控制
stcAdtTIM4ACfg.enStaOut = AdtCHxPortOutLow; //CHA起始电平为低
stcAdtTIM4ACfg.enStpOut = AdtCHxPortOutLow; //CHA结束电平为低
Adt_CHxXPortCfg(M0P_ADTIM4, AdtCHxA, &stcAdtTIM4ACfg); //端口CHA配置
stcAdtTIM4BCfg.enCap = AdtCHxCompareOutput;
stcAdtTIM4BCfg.bOutEn = TRUE;
stcAdtTIM4BCfg.enPerc = AdtCHxPeriodInv;
stcAdtTIM4BCfg.enCmpc = AdtCHxCompareInv;
stcAdtTIM4BCfg.enStaStp = AdtCHxStateSelSS;
stcAdtTIM4BCfg.enStaOut = AdtCHxPortOutLow;
stcAdtTIM4BCfg.enStpOut = AdtCHxPortOutLow;
Adt_CHxXPortCfg(M0P_ADTIM4, AdtCHxB, &stcAdtTIM4BCfg); //端口CHB配置
//number3 ///< AdvTimer端口初始化
void App_AdvTimerPortInit(void)
{
stc_gpio_cfg_t stcTIM4Port;
DDL_ZERO_STRUCT(stcTIM4Port);
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE); //端口外设时钟使能
stcTIM4Port.enDir = GpioDirOut;//配置成输出
//PA08设置为TIM4_CHA
Gpio_Init(GpioPortA, GpioPin8, &stcTIM4Port);
Gpio_SetAfMode(GpioPortA,GpioPin8,GpioAf6);
//PA11设置为TIM4_CHB
Gpio_Init(GpioPortA, GpioPin11, &stcTIM4Port);
Gpio_SetAfMode(GpioPortA,GpioPin11,GpioAf7);
}
|