大家好,关于CAP功能实现有关问题向你们请教,我想用CAP功能实现无刷直流电机的换相,用CAP1,CAP2,CAP3,分别捕获电机霍尔信号,CAP1,2,3单独测试,功能一切正常,当CAP1,2,3三路同时工作,捕获的数据是错误。也不知道是什么原因,以下是相关代码以及寄存器信息。搞了一个星期了。也没有搞定,特请教专家解答。非常感谢 CAP初始化 void SetCap1Mode(void)
{
ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap1Regs.ECEINT.all=0x0000;//stop all interrupt
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
// ECap1Regs.ECEINT.bit.CEVT1=1;// Enable cevt1 interrupt
// ECap1Regs.ECEINT.bit.CEVT2=1;// Enable cevt2 interrupt
// ECap1Regs.ECEINT.bit.CEVT3=1;// Enable cevt3 interrupt
// ECap1Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
} void SetCap2Mode(void)
{
ECap2Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap2Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap2Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap2Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
ECap2Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap2Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap2Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap2Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap2Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap2Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap2Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap2Regs.ECEINT.all=0x0000;//stop all interrupt
ECap2Regs.ECCLR.all=0xFFFF;//clare all flag
ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启
ECap2Regs.ECEINT.bit.CEVT1=1;// Enable cevt1 interrupt
ECap2Regs.ECEINT.bit.CEVT2=1;// Enable cevt2 interrupt
ECap2Regs.ECEINT.bit.CEVT3=1;// Enable cevt3 interrupt
ECap2Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
} void SetCap3Mode(void)
{
ECap3Regs.ECCTL1.bit.CAP1POL = EC_RISING;
ECap3Regs.ECCTL1.bit.CAP2POL = EC_FALLING;
ECap3Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap3Regs.ECCTL1.bit.CAP4POL = EC_FALLING;
ECap3Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap3Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap3Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap3Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap3Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
ECap3Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap3Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap3Regs.ECEINT.all = 0x0000;//stop all interrupt
ECap3Regs.ECCLR.all = 0xffff;//clare all flag
ECap3Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
// ECap3Regs.ECEINT.bit.CEVT1=1;// Enable cevt1 interrupt
// ECap3Regs.ECEINT.bit.CEVT2=1;// Enable cevt2 interrupt
// ECap3Regs.ECEINT.bit.CEVT3=1;// Enable cevt3 interrupt
// ECap3Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
} 以下为中断代码 interrupt void ISRCap1(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=0;//设定cap1~3为gpio
GpioCtrlRegs.GPAMUX2.bit.GPIO25=0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=0;
capstastus=(GpioDataRegs.GPADAT.all&0x07000000)>>24;
speed1[capdata1]=capstastus;
capdata1++;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=1;//设定cap1~3为cap
GpioCtrlRegs.GPAMUX2.bit.GPIO25=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=1; // Acknowledge this interrupt to receive more interrupts from group 1
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
EDIS;
} interrupt void ISRCap2(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=0;//设定cap1~3为gpio
GpioCtrlRegs.GPAMUX2.bit.GPIO25=0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=0;
capstastus=(GpioDataRegs.GPADAT.all&0x07000000)>>24;
speed2[capdata2]=capstastus;
capdata2++;
GpioCtrlRegs.GPAMUX2.bit.GPIO24=1;//设定cap1~3为cap
GpioCtrlRegs.GPAMUX2.bit.GPIO25=1;
GpioCtrlRegs.GPAMUX2.bit.GPIO26=1;
/*************************/ // Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
ECap2Regs.ECCLR.all=0xFFFF;
EDIS;
} 单路测试 工作正常 以下是寄存器信息 CAP1 2两路同时工作 出现错误。以下出错寄存器信息
|