- UID
- 802489
|
请教各位,单片机是MC9S12XDP512,利用ECT进行转速测量。需2路输入捕捉同时工作。一路工作正常,另一路有时能采集到正确频率,但过段时间就进不了中断。有时只进一次中断就再也进不去了。有时采集到的计数值很乱。不知道原因出在哪里,请明白人指点下,谢谢。程序代码如下:
void ECT_Init (void) //输入捕捉初始化函数
{
TSCR1=0x90; //主定时器使能,快速清除标志
TSCR2=0x07; //分频因子为128
ICSYS = 0x02; //IC缓冲使能
TIOS_IOS0=0; //通道0为输入捕捉
TIOS_IOS1=0; //通道1为输入捕捉
TCTL4_EDG0A=1; //捕捉通道0上升沿
TCTL4_EDG0B=0;
TCTL4_EDG1A=0; //捕捉通道1上升沿
TCTL4_EDG1B=1;
TIE_C0I=1; //通道0中断使能
TIE_C1I=1; //通道1中断使能
TFLG1=0xFF; //清中断标志位
}
#pragma CODE_SEG NON_BANKED
void interrupt 8 Int_TimerCapture_C0(void)
{
DisableInterrupts;
TFLG1_C0F = 1; //中断标志清除
//CountOverFlowTimes();
SpeedCount1[1]=TC0; //通过读TC0寄存器来响应中断
//nn = TC0;
if(SpeedCount1[1]>=SpeedCount1[0])
{
SpeedCount1[2]=SpeedCount1[1]- SpeedCount1[0];
}
else
{
SpeedCount1[2]=65536- SpeedCount1[0];
SpeedCount1[2]+= SpeedCount1[1];
}
SpeedCount1[0]= SpeedCount1[1];
EnableInterrupts;
}
//#pragma CODE_SEG NON_BANKED
void interrupt 9 Int_TimerCapture_C1(void)
{
DisableInterrupts;
TFLG1_C1F = 1; //中断标志清除
//CountOverFlowTimes();
mm=TC1; //通过读TC1寄存器来响应中断
SpeedCount2[1]=mm;
if(SpeedCount2[1]>=SpeedCount2[0])
{
SpeedCount2[2]=SpeedCount2[1]- SpeedCount2[0];
}
else
{
SpeedCount2[2]=65536- SpeedCount2[0];
SpeedCount2[2]+= SpeedCount2[1];
}
SpeedCount2[0]= SpeedCount2[1];
EnableInterrupts;
}
#pragma CODE_SEG DEFAULT |
|