yokel
Junior Member level 3
adpcfg
Dear All,
I am using the input capture of dsPIC30F3011 for calculating the pulse width of a square wave. I am using the following code:
But I am not getting any response from the ISR. Please help me to find out the problem in my code.
Thanks.
Dear All,
I am using the input capture of dsPIC30F3011 for calculating the pulse width of a square wave. I am using the following code:
Code:
unsigned int rotateCount=0;
unsigned int timePeriod= 0; current_value=0,previous_value=0;
void InitIC(void)
{
IC7CONbits.ICM=3; // Capture every rising edge
IC7CONbits.ICBNE=0; // Input capture buffer is empty
IC7CONbits.ICOV=0; // No input capture overflow occured
IC7CONbits.ICI=0; // Interrupt on every capture event
IC7CONbits.ICTMR=1; // TMR2 contents are captured on captured event
IC7CONbits.ICSIDL=0; // Input capture module will continue to operate in CPU Idle mode
IFS1bits.IC7IF = 0; // Interrupt bit is cleared
IPC4bits.IC7IP = 3; // Set Interrupt priority to 3
IEC1bits.IC7IE = 1; // Set the IC7 interrupt enable bit
}
void TMR2_setup(void)
{
TMR2 = 0x00; // Clear contents of the timer register
T2CONbits.TCS=1; // Timer uses the internal clock when TCS = 0. Using Internal Clock (Fosc/4)
T2CONbits.T32=0; // TMRx and TMRy form a 16-bit timer
T2CONbits.TCKPS=0; // Using 1:1 prescale value
T2CONbits.TGATE=0; // Timer Gate Accumulation Disabled
T2CONbits.TSIDL=0; // Continue in Idle Mode
T2CONbits.TON=1; // Start Timer1 with prescaler settings at 1:1 and
// clock source set to the internal instruction cycle
PR2 = 0xFFFF; //Load the Period register with the value 0xFFFF
return;
}
void __attribute__((interrupt, no_auto_psv)) _IC7Interrupt (void)
{
rotateCount=rotateCount + 1;
if (rotateCount==6)
{
previous_value=current_value;
current_value=IC7BUF;
if(current_value>previous_value)
{
timePeriod = current_value-previous_value;
}
else
{
timePeriod = (PR2 - previous_value) + current_value;
}
SendData(timePeriod); // sending the time period to the host PC
rotateCount=0;
}
IFS1bits.IC7IF = 0; //Interrupt bit is cleared
}
But I am not getting any response from the ISR. Please help me to find out the problem in my code.
Thanks.