void InitEv(void)
{
EvaRegs.ACTR.all = 0x0f3d; ///通过对比较方式控制寄存器的配置,P1输出PWM,P2强制高,P3强制高,P4强制低,P5、P6强制高
EvaRegs.DBTCONA.all = 0x0000;///使能死区定时器,
EvaRegs.COMCONA.all = 0xa600; ///比较器控制A
EvaRegs.T1CON.all = 0x0842; ///连续增/减模式,TPS系数(1)150M/2,T1使能
EvaRegs.GPTCONA.bit.T1PIN =0x01; //定时器T1比较输出低有效
EvaRegs.GPTCONA.bit.TCOMPOE=1; //比较输出使能
/*六路PWM占空比 20%*/
EvaRegs.T1PR =1500; ////定时器1周期值7.5M /300=25Khz
EvaRegs.T1CNT = 0; ///定时器1初值设为0
EvaRegs.CMPR1=1200;// 占空比越小,转得越快
EvaRegs.CMPR2=1200;
EvaRegs.CMPR3=1200;
EvaRegs.CAPCON.all=0x3654; //使能CAP1、2、3,采用T1,检测上升沿
EvaRegs.CAPFIFO.all=0x0000;
/*捕捉中断使能*/
EvaRegs.EVAIMRC.bit.CAP1INT=1; //三个捕捉中断都是使能
EvaRegs.EVAIMRC.bit.CAP2INT=1;
EvaRegs.EVAIMRC.bit.CAP3INT=1;
EvaRegs.EVAIFRC.bit.CAP1INT=1; //三个捕捉中断标志位清零
EvaRegs.EVAIFRC.bit.CAP2INT=1; //三个捕捉中断标志位清零
EvaRegs.EVAIFRC.bit.CAP3INT=1; //三个捕捉中断标志位清零
}
void InitGpio(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.bit.CAP1Q1_GPIOA8=1; //使用PWM1-6口和Cap专用口
GpioMuxRegs.GPAMUX.bit.CAP2Q2_GPIOA9=1;
GpioMuxRegs.GPAMUX.bit.CAP3QI1_GPIOA10=1;
GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0=1;
GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1=1;
GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2=1;
GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3=1;
GpioMuxRegs.GPAMUX.bit.PWM5_GPIOA4=1;
GpioMuxRegs.GPAMUX.bit.PWM6_GPIOA5=1;
//cap口定位输入
GpioMuxRegs.GPADIR.bit.GPIOA10=0;
GpioMuxRegs.GPADIR.bit.GPIOA9=0;
GpioMuxRegs.GPADIR.bit.GPIOA8=0;
EDIS;
}
Uint16 shunNum[6]={0x0f3d,0x03fd,0x03df,0x0fd3,0x0df3,0x0d3f}; //顺时针换向表
interrupt void T1_Cap_isr(void);
int count=0;
int mm=0;
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000; //
IFR = 0x0000; //清中断
// LedCount = 0;
/*初始化PIE*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化定时器0*/
InitCpuTimers();
/*初始化外设*/
InitPeripherals();
/* 初始化事件管理器,确定PWM*/
InitEv();
/*受EALLOW保护的捕捉中断矢量,重新映射捕捉中断入口*/
EALLOW; //允许访问EALLOW保护的寄存器
PieVectTable.CAPINT1 = &T1_Cap_isr; //指向中断服务寄存器捕捉1的地址
PieVectTable.CAPINT2 = &T1_Cap_isr;
PieVectTable.CAPINT3 = &T1_Cap_isr;
//重新EALLOW保护
/*使能中断捕捉,向量是查表得,INT3.5-INT3.7*/
PieCtrl.PIEIER3.bit.INTx7=1;
PieCtrl.PIEIER3.bit.INTx6=1;
PieCtrl.PIEIER3.bit.INTx5=1;
IER|= M_INT3; //使能INT3
EDIS;
EINT; // 开放全局中断,Enable Global interrupt INTM
ERTM; // 开放全局实时中断,Enable Global realtime interrupt DBGM
for(;;)
{
}
}
interrupt void T1_Cap_isr(void)
{
mm=1;
//换向,
if (count==5)
count=0;
else count++;
EvaRegs.ACTR.all=shunNum[count];
EvaRegs.EVAIFRC.all=0x0007; //三个捕捉中断标志位清零
//响应中断寄存器清除,写1清0,进而才能接收下一外围中断 不会写
PieCtrl.PIEACK.bit.ACK3=1;
PieCtrl.PIEIFR3.all = 0;
} |