electronicsman
Full Member level 5
I have completely messed up the input capture calculations. This is my program and really do not know how to proceed, this is the code
i have completely lost the sync of timer3overflowcounter. When should i start the Timer3 timer and stop? The period calculations is wrong. The controller is dspic33ev256gm106. Please help.
Code:
int main(void)
{
Init_Timer3();
inputcapture_init();
while(1);
}
void Init_Timer3(void)
{
IFS0bits.T3IF = 0;
IEC0bits.T3IE = 1;
T3CONbits.TON = 1;
T3CONbits.TCKPS = 1;
}
void inputcapture_init(void)
{
ANSELCbits.ANSC0=0;
_TRISC0=1;
RPINR7 = 0x30; // MAP_TO_RP48;
IC1CON1bits.ICM = 3; /* every rising edge */
IC1CON1bits.ICI = 0; /* every capture event */
IC1CON1bits.ICTSEL = 0; /*TIMER3_IC1;*/
IFS0bits.IC1IF = 0; //RESET_IC1_STATUS_FLAG; // Clear Input Capture1 Flag request
IEC0bits.IC1IE = 1;//ENABLE_IC1_INTERRUPT; // Enable Input Capture1 Interrupt request
}
void __attribute__((__interrupt__,__no_auto_psv__)) _IC1Interrupt(void)
{
previous_capturedata= present_capturedata; /*copy the present value to previous value */
present_capturedata = IC1BUF; /*Load the register value */
if(timer3overflowcounter > 0)
{
period = (65535 - previous_capturedata) + present_capturedata + (timer3overflowcounter -1)*65535;
}
else
{
if(present_capturedata > previous_capturedata)
{
period = present_capturedata - previous_capturedata;
}
else if(present_capturedata < previous_capturedata)
{
period = 65535 - previous_capturedata + present_capturedata;
}
}
timer3overflowcounter=0;
IFS0bits.IC1IF=0;
}
void __attribute__ ((__interrupt__, no_auto_psv)) _T3Interrupt(void)
{
timer3overflowcounter++;
IFS0bits.T3IF = 0;
}