如题,我按照教程配置了cap功能在仿真的过程中发现捕获寄存器的数值始终是0,请问是不是我的配置出现了问题,如下是我的代码:
void main(void)
{
InitSysCtrl();
InitECapGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
DELAY_US(1000L);
EALLOW;
SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1;
SysCtrlRegs.PCLKCR1.bit.ECAP2ENCLK = 1;
EDIS;
Init_ecap();
EALLOW;
PieVectTable.ECAP1_INT = &Cap_calculate;
EDIS;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
IER|= M_INT4;
PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
EINT;
ERTM;
time_1 = 0x0;
time_2 = 0x0;
time_3 = 0x0;
time_4 = 0x0;
final_t = 0x0;
while(1)
{
}
}
void Init_ecap()
{
ECap1Regs.ECCTL1.all = 0x0000;
ECap1Regs.ECCTL1.bit.CAPLDEN = 1;
ECap1Regs.ECCTL2.bit.CAP_APWM = 0; //工作在捕获模式
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; //工作在连续模式
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2; //禁止SYNC_OUT输出信号
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; //禁止同步功能
ECap2Regs.ECCTL1.all = 0x0000;
ECap2Regs.ECCTL1.bit.CAPLDEN = 1;
ECap2Regs.ECCTL2.bit.CAP_APWM = 0; //工作在捕获模式
ECap2Regs.ECCTL2.bit.CONT_ONESHT = 0; //工作在连续模式
ECap2Regs.ECCTL2.bit.SYNCO_SEL = 2; //禁止SYNC_OUT输出信号
ECap2Regs.ECCTL2.bit.SYNCI_EN = 0; //禁止同步功能
/*捕获事件中断使能*/
ECap1Regs.ECEINT.all = 0;
ECap1Regs.ECCLR.all &= 0xFF;
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; //启动cap1计时器
ECap1Regs.ECEINT.bit.CEVT1 = 1;
ECap1Regs.ECEINT.bit.CEVT2 = 1;
ECap1Regs.ECEINT.bit.CEVT3 = 1;
ECap1Regs.ECEINT.bit.CEVT4 = 1;
ECap2Regs.ECEINT.all = 0;
ECap2Regs.ECCLR.all &= 0xFF;
ECap2Regs.ECCTL2.bit.TSCTRSTOP = 1; //启动cap1计时器
ECap2Regs.ECEINT.bit.CEVT1 = 1;
ECap2Regs.ECEINT.bit.CEVT2 = 1;
ECap2Regs.ECEINT.bit.CEVT3 = 1;
ECap2Regs.ECEINT.bit.CEVT4 = 1;
}
interrupt void Cap_calculate()
{
ECap1Regs.ECCLR.all = 0x001E;
time_1 = ECap1Regs.CAP1;
time_2 = ECap1Regs.CAP2;
time_3 = ECap1Regs.CAP3;
time_4 = ECap1Regs.CAP4;
final_t = (time_3 + time_4 – time_2 – time_1)/2;
}
Seven Han:应该是您ECap配置的问题,请详细描述以下您的问题?
请您安装controlsuite,参考例程:
:\ti\controlSUITE\device_support\f2833x\v142\DSP2833x_examples_ccsv5\ecap_capture_pwm