本帖最后由 w6016415 于 2014-3-19 21:43 编辑
各位大神,我是dsp入门级,现在想用dsp2808的ecap口对直流无刷电机的霍尔信号进行测速。我设置CEVT4时间后触发cap1中断(其中CAP1POL1与CAP1POL3为上升沿触发,CAP1POL2与CAP1POL4为下降沿触发)。问题是现在我给cap口一个pwm信号(2.5kHz)进行频率测试的时候,发现捕获寄存器cap1~cap4的值都是相等的,请问我是哪里出问题了呢?具体设置如下:
void InitECapture()
{
ECap1Regs.ECCTL2.bit.CAP_APWM=0;//工作于捕获模式
ECap1Regs.CAP1=0x00000000;
ECap1Regs.CAP2=0x00000000;
ECap1Regs.CAP3=0x00000000;
ECap1Regs.CAP4=0x00000000;
ECap1Regs.ECEINT.all=0x0000;//屏蔽eCAP1所有中断
// ECap1Regs.ECCTL1.all=0xFFFF;
ECap1Regs.ECCLR.all=0xFFFF;//清除所有中断标志位
ECap1Regs.ECCTL1.bit.CAPLDEN=0;//Disable CAP1~CAP4 register loads
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
//configure peripheral registers
ECap1Regs.ECCTL2.bit.CONT_ONESHT=0;//工作于连续捕获模式
ECap1Regs.ECCTL2.bit.STOP_WRAP=3; //Stop at 4 events
ECap1Regs.ECCTL1.bit.CAP1POL=0; //CEVT1:上升沿捕获
ECap1Regs.ECCTL1.bit.CAP2POL=1;
ECap1Regs.ECCTL1.bit.CAP3POL=0;
ECap1Regs.ECCTL1.bit.CAP4POL=1;
ECap1Regs.ECCTL1.bit.CTRRST1=1;// Difference operation
ECap1Regs.ECCTL1.bit.CTRRST2=1;// Difference operation
ECap1Regs.ECCTL1.bit.CTRRST3=1;// Difference operation
ECap1Regs.ECCTL1.bit.CTRRST4=1;// Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN=0;// Enable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL=2;// Pass through
ECap1Regs.ECCTL1.bit.PRESCALE=60;
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
ECap1Regs.ECCTL1.bit.CAPLDEN=1;//使能捕获事件发生时间装载到捕获寄存器CAP1~Cap4
ECap1Regs.ECEINT.bit.CEVT4 = 1;
}
中断执行函数如下
interrupt void cap_isr(void)
{
// ECap1Regs.ECCTL1.bit.CAPLDEN=1;
// ECap2Regs.ECCTL1.bit.CAPLDEN=1;
// ECap1Regs.EC标志寄存器.bit.CEVT1=0;
// ECap1Regs.EC标志寄存器.bit.CEVT2=0;
// ECap1Regs.EC标志寄存器.bit.CEVT3=0;
// ECap1Regs.EC标志寄存器.bit.CEVT4=0;
ECap1Regs.ECCLR.bit.CEVT4 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;//持续捕捉外部信号
// ECap1Regs.ECCLR.all=0xFFFF;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; // Acknowledge interrupt to PIE
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
// ECap1Regs.ECCTL1.bit.CAPLDEN=1;
TSt1_Up1=ECap1Regs.CAP1;
TSt1_Down1=ECap1Regs.CAP2;
TSt1_Up2=ECap1Regs.CAP3;
TSt1_Down2=ECap1Regs.CAP4;
return;
}
|