在论坛找了一个eCAP程序,改了一下,结果进不了中断,而且GPIO19脚还是高电平,求解决,代码如下:
void InitECapture()
{
ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
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.CAP_APWM = 0; //CAP mode
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // continuous mode
ECap1Regs.ECCTL2.bit.STOP_WRAP = 1; // Stop at 2 events
ECap1Regs.ECCTL1.bit.PRESCALE = 0; // Divide by 1
ECap1Regs.ECCTL1.bit.CAP1POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CAP2POL = 0; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST2 = 0; // Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; // Enable sync in
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 3; // Disable sync out signal
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter
ECap1Regs.ECEINT.bit.CEVT2 = 1; // 2 events = interrupt
}
void main(void)
{
InitSysCtrl();
EALLOW; //允许访问受保护的空间
GpioCtrlRegs.GPADIR.bit.GPIO1=1;
GpioDataRegs.GPADAT.bit.GPIO1=1;
EDIS;
InitECap1Gpio();
InitECapture();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.ECAP1_INT = &ecap1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers // Enable CPU INT4 which is connected to ECAP1-4 INT:
IER |= M_INT4;
PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
// Enable eCAP INTn in the PIE: Group 3 interrupt 1-6
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
while(1);
}
interrupt void ecap1_isr(void)
{
//ECap1Count = ECap1Regs.CAP1;
ECap2Count = ECap1Regs.CAP2;
GpioDataRegs.GPADAT.bit.GPIO1=0;
//ECap1Regs.ECCLR.all = 0xFFFF;
ECap1Regs.ECCLR.bit.CEVT2 = 1;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
看一下你的InitECap1Gpio初始化 : InitECap1Gpio()
我感觉你可能InitECap1Gpio初始化有问题
[ 本帖最后由 ltbytyn 于 2013-6-7 11:43 编辑 ]
回复 沙发 ltbytyn 的帖子
那个初始化程序用的是本身自带的,和你发的那个帖子是一样的,
void InitECap1Gpio(void)
{
EALLOW;
// GpioCtrlRegs.GPAPUD.bit.GPIO5=0; //Enable pull-up on GPIO5 (CAP1)
GpioCtrlRegs.GPAPUD.bit.GPIO19=0; // Enable pull-up on GPIO19 (CAP1)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO5=0; // Synch to SYSCLKOUT GPIO5 (CAP1)
GpioCtrlRegs.GPAQSEL2.bit.GPIO19=0;//Synch to SYSCLKOUT GPIO19(CAP1)
// GpioCtrlRegs.GPAMUX1.bit.GPIO5=3; // Configure GPIO5 as CAP1
GpioCtrlRegs.GPAMUX2.bit.GPIO19=3; // Configure GPIO19 as CAP1
EDIS;
}
程序里面的GPIO1我是用它来判断是否进入中断的啊,没有写错,就是GPIO19(捕获口)为高电压,进不了中断啊,求帮助,急求!!!!,非常感谢
InitSysCtrl();
EALLOW; //允许访问受保护的空间
GpioCtrlRegs.GPADIR.bit.GPIO1=1;
GpioDataRegs.GPADAT.bit.GPIO1=1;
EDIS;
InitECap1Gpio();
InitECapture();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.ECAP1_INT = &ecap1_isr;
EDIS; // This is needed to disable write to EALLOW protected registers // Enable CPU INT4 which is connected to ECAP1-4 INT:
IER |= M_INT4;
PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
// Enable eCAP INTn in the PIE: Group 3 interrupt 1-6
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
while(1);
}
IER、IFR、PIE初始化。调试时观察相应寄存器(PIE、ECAP等)的值是否正常。
你把GPIO19的上拉去掉,不要使能上拉即:
GpioCtrlRegs.GPAPUD.bit.GPIO19=1; //Disable pull-up on GPIO19 (CAP1)
这样做试试。