各位朋友好!
我的DSP2812的板子,原来我做了一路CAP中断来测量脉冲的频率,能实现频率测量。因为有几路脉冲信号需要测量频率,我修改程序后,只有原来的cap1能实现中断测量频率,增加的cap3不能测量频率,连中断都不进入。我附上程序,请各位朋友帮我查查,谢谢!!
void main(void)
{
/*初始化系统*/
InitSysCtrl();// 090717看门狗、PLL、时钟设置
/*关中断*/
// 090717 清除所有CPU中断
DINT;
IER = 0x0000; //Interrupt enable register
IFR = 0x0000; //Interrupt flag register
/*初始化PIE*/
InitPieCtrl(); //090717 PIE:外设中断
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化外设*/
InitPeripherals();
/*初始化GPIO*/
InitGpio(); //Set GPIO F port
InitXIntrupt();
// InitEv();//090721
flag_capint1=0;
flag_capint3=0;
EALLOW; // This is needed to write to EALLOW protected registers
// PieVectTable.T1PINT = &eva_timer1_isr;//090717 中断服务程序入口地址放入中断向量表,如下interrupt void eva_timer1_isr(void)
// PieVectTable.T2PINT = &eva_timer2_isr;
// PieVectTable.T3PINT = &evb_timer3_isr;
// PieVectTable.T4PINT = &evb_timer4_isr;
PieVectTable.CAPINT1= &CAPINT1_ISR;
PieVectTable.CAPINT3= &CAPINT3_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
/*
// Enable PIE group 2 interrupt 4 for T1PINT
PieCtrl.PIEIER2.all = M_INT4;
// Enable PIE group 3 interrupt 1 for T2PINT
PieCtrl.PIEIER3.all = M_INT1;
// Enable PIE group 4 interrupt 4 for T3PINT
PieCtrl.PIEIER4.all = M_INT4;
// Enable PIE group 5 interrupt 1 for T4PINT
PieCtrl.PIEIER5.all = M_INT1;
*/
PieCtrl.PIEIER3.bit.INTx5=1;//20090721 Enable PIE group 3 interrupt x for CAPINT1
PieCtrl.PIEIER3.bit.INTx7=1;//20100107 Enable PIE group 3 interrupt x for CAPINT3 ?
// Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT
// and INT5 for T4PINT:
// IER |= (M_INT2 | M_INT3 | M_INT4 | M_INT5);//090717 #define M_INT2 0x0002(即IER的第2位、第3位、第4位、第5位都被置1)
IER |= M_INT3;// capture enable
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM (090717 Enable interrupts by clearing the INTM status bit.)
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE(空闲) loop. Just sit and loop forever:
// Freq_Adjust(1000,0x00,0x40);
for(;;)
{
if(flag_capint1)//光电
{
flag_capint1=0;
temp=(pinlvf[0]+pinlvf[1]+pinlvf[2]+pinlvf[3]+pinlvf[4])/5;
// pinlv= 234375.0/(float)temp;//f= 15M/64/temp SysCtrlRegs.PLLCR = 0x00;///锁相环直通方式,15M
pinlv= 234375.0*6/(float)temp;//f= 90M/64/temp SysCtrlRegs.PLLCR = 0x00;///锁相环直通方式,15*6M
// pinlv=f;
FQUD=0;
// Freq_Adjust(pinlv,0x00,0x40);
}
if(flag_capint3)//雷达
{
flag_capint3=0;
temp=(pinlvf3[0]+pinlvf3[1]+pinlvf3[2]+pinlvf3[3]+pinlvf3[4])/5;
// pinlv= 234375.0/(float)temp;//f= 15M/64/temp SysCtrlRegs.PLLCR = 0x00;///锁相环直通方式,15M
pinlv= 234375.0*6/(float)temp;//f= 90M/64/temp SysCtrlRegs.PLLCR = 0x00;///锁相环直通方式,15*6M
// pinlv=f;
FQUD=0;
Freq_Adjust(pinlv,0x00,0x40);
}
interrupt void CAPINT3_ISR(void) // EV-A
{
// Insert ISR Code here
//090718 到下090718处,为增加捕获方式测频程序
unsigned int temp;
EvaRegs.EVAIFRC.bit.CAP3INT=1;// 清捕获中断1标志位
cap3num1=EvaRegs.CAP3FIFO; //所有FIFO堆栈的顶层堆栈寄存器是只读寄存器,当读取FIFO堆栈的顶层寄存器的计数值时,
cap3num2=EvaRegs.CAP3FIFO; //堆栈底层寄存器的新计数值(如果有)将被压入顶层寄存器。090721
if(cap3num2 > cap3num1)
temp = cap3num2-cap3num1;
else
temp = cap3num2+(0xFFFF-cap3num1);
pinlvf3[fnum++] =temp;
if(fnum>4)
{
fnum=0;//取5个数值后回零
flag_capint3=1;
}
// f= 234375.0/(float)temp;//f= 15M/64/temp SysCtrlRegs.PLLCR = 0x00;///锁相环直通方式,15M
PieCtrl.PIEACK.bit.ACK3 = 1;//开外设中断应答
// flag_capint1=1;
//090718====
// To recieve more interrupts from this PIE group, acknowledge this interrupt
// PieCtrl.PIEACK.all = PIEACK_GROUP3;
// Next two lines for debug only - remove after inserting
// ISR Code
//asm (" ESTOP0");
//for(;;);
// Uncomment this line after adding ISR Code
return;
} |