class="markdown_views prism-atom-one-light">
这个代码的功能
是在ePWMA 即GPIO0口输出一个周期为100us,占空比为50%的PWM波。
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#if (CPU_FRQ_150MHZ)
#define CPU_CLK 150e6
#endif
#if (CPU_FRQ_100MHZ)
#define CPU_CLK 100e6
#endif
#define PWM_CLK 10e3
#define SP CPU_CLK/(2*PWM_CLK)
#define TBCTLVAL 0x200A
void EPwmSetup()
{
InitEPwm1Gpio();
EPwm1Regs.TBSTS.all=0;
EPwm1Regs.TBPHS.half.TBPHS=0;
EPwm1Regs.TBCTR=0;
EPwm1Regs.TBCTL.bit.CTRMODE=TB_UP_DOWN;
EPwm1Regs.TBCTL.bit.PHSEN=TB_DISABLE;
EPwm1Regs.TBCTL.bit.PRDLD=TB_IMMEDIATE;
EPwm1Regs.TBCTL.bit.SYNCOSEL=TB_SYNC_DISABLE;
EPwm1Regs.TBCTL.bit.SWFSYNC=0;
EPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV=TB_DIV1;
EPwm1Regs.TBCTL.bit.PHSDIR=0;
EPwm1Regs.TBCTL.bit.FREE_SOFT=0;
EPwm1Regs.TBPRD=SP;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_LD_DISABLE;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_LD_DISABLE;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_IMMEDIATE;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_IMMEDIATE;
EPwm1Regs.CMPA.half.CMPA =SP/2;
EPwm1Regs.CMPB=0;
EPwm1Regs.AQCTLA.bit.CAU= AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD= AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CBU= AQ_SET;
EPwm1Regs.AQCTLB.bit.CBD= AQ_CLEAR;
EPwm1Regs.AQSFRC.all=0;
EPwm1Regs.AQCSFRC.all=0;
EPwm1Regs.DBCTL.bit.OUT_MODE=0X03;
EPwm1Regs.DBRED=0;
EPwm1Regs.DBFED=0;
EPwm1Regs.TZSEL.all=0;
EPwm1Regs.TZCTL.all=0;
EPwm1Regs.TZEINT.all=0;
EPwm1Regs.TZFLG.all=0;
EPwm1Regs.TZCLR.all=0;
EPwm1Regs.TZFRC.all=0;
EPwm1Regs.ETSEL.all=0;
EPwm1Regs.ETFLG.all=0;
EPwm1Regs.ETCLR.all=0;
EPwm1Regs.ETFRC.all=0;
EPwm1Regs.PCCTL.all=0;
}