picC24HJ128GP504单片机输入捕获,捕获的是PWM高电平时间,能够捕捉到,但是与实际值相差很大,有没有大佬帮我看看哪里有问题啊,非常感谢程序如下
uint timePeriod=0;
unsigned int t1=0,t2=0;
void CCP1INT(){
//内部晶振7.37MHz,t
// Enable Capture Interrupt And Timer3
IPC0bits.IC1IP = 1; // 设置输入捕获寄存器为第一优先级
IFS0bits.IC1IF = 0; // 清除 IC1 中断状态标志
IEC0bits.IC1IE = 1; // 使能IC1 中断
// Initialize Capture Module
IC1CONbits.ICM=0b00; // 输入捕捉1禁止
IC1CONbits.ICTMR= 0; // Select Timer3 as the IC1 Time base
IC1CONbits.ICI= 0b01; // 每 2 次捕捉事件产生一次中断
IC1CONbits.ICM= 0b001; // 在捕捉输入信号的上升沿和下降沿进行捕捉
IC1CONbits.ICBNE=0;
IC1CONbits.ICOV=0;
IC1CONbits.ICSIDL=0;
T3CON = 0x0000;
T3CONbits.TON = 1;
T3CONbits.TCS = 0;
T3CONbits.TGATE = 0;
T3CONbits.TCKPS = 0;
T3CONbits.TSIDL=0;
TMR3 = 0x0000;
PR3 = 0xFFFF;
;
TRISBbits.TRISB12=1;
RPINR7bits.IC1R=0b01100; //RB12给到输入捕捉1
// Capture Interrupt Service Routine
// return 60;
}
// Capture Interrupt Service Routine
void __attribute__((__interrupt__)) _IC1Interrupt(void)
{
t1=IC1BUF;
t2=IC1BUF;
IFS0bits.IC1IF=0;
if(t2>t1)
timePeriod = t2-t1;
else
timePeriod = (PR3- t1) + t2;
//Phase = timePeriod;
}
|