hoseinagha
Newbie level 1
I am using DSPIC33FJ256GP710 and using code below for setting input capture 1.
But the result is wrong. It seems that Input capture is not using input frequency and result is much higher frequency.
unsigned int ic1_prev_buf ;
void __attribute__((__interrupt__)) _IC1Interrupt( void )
{
unsigned int tmp,icvalue;
tmp = IC1BUF;
if(ic1_prev_buf>tmp)
icvalue = tmp + 65535 - ic1_prev_buf;
else
icvalue = tmp - ic1_prev_buf;
ic1_prev_buf = tmp;
IFS0bits.IC1IF = 0;
}
void timer2init(void)
{
//cpu clock 46080000
//timer 2 prescallar : 64
T2CON = 0;
T2CONbits.TCKPS=2;
T2CONbits.TON=1;
PR2=0xffff;
}
void ic1_init(void)
{
//TRISDbits.TRISD8=1;
//IC1CON=0;
IC1CONbits.ICM=3;
IC1CONbits.ICTMR=1;
IC1CONbits.ICI=0;
IFS0bits.IC1IF = 0;
IPC0bits.IC1IP = 7;
IEC0bits.IC1IE=1;
}
Any help is appreciated.
But the result is wrong. It seems that Input capture is not using input frequency and result is much higher frequency.
unsigned int ic1_prev_buf ;
void __attribute__((__interrupt__)) _IC1Interrupt( void )
{
unsigned int tmp,icvalue;
tmp = IC1BUF;
if(ic1_prev_buf>tmp)
icvalue = tmp + 65535 - ic1_prev_buf;
else
icvalue = tmp - ic1_prev_buf;
ic1_prev_buf = tmp;
IFS0bits.IC1IF = 0;
}
void timer2init(void)
{
//cpu clock 46080000
//timer 2 prescallar : 64
T2CON = 0;
T2CONbits.TCKPS=2;
T2CONbits.TON=1;
PR2=0xffff;
}
void ic1_init(void)
{
//TRISDbits.TRISD8=1;
//IC1CON=0;
IC1CONbits.ICM=3;
IC1CONbits.ICTMR=1;
IC1CONbits.ICI=0;
IFS0bits.IC1IF = 0;
IPC0bits.IC1IP = 7;
IEC0bits.IC1IE=1;
}
Any help is appreciated.