angeline
Newbie level 5
dspic input capture
I am a new user using DSPIC30F3010. I am trying to use the input capture module to capture the period of squarewave using the MPLAB IDE to do my programming. I am using the ICD2 to view the result of my register which is IC7BUF. I am not getting any changes in the buffer , however I put an LED to make sure my code enter the input capture interrupt and it shows me yes. Hope can get some advice .
I am a new user using DSPIC30F3010. I am trying to use the input capture module to capture the period of squarewave using the MPLAB IDE to do my programming. I am using the ICD2 to view the result of my register which is IC7BUF. I am not getting any changes in the buffer , however I put an LED to make sure my code enter the input capture interrupt and it shows me yes. Hope can get some advice .
Code:
# include <p30f3010.h>
# include <math.h>
# include <stdio.h>
#define LED LATDbits.LATD0
/*************Global Variables and Constants*************/
unsigned int period= 0, captureresult1 = 0 , captureresult2= 0; /*Variables used for period calculation*/
void __attribute__((__interrupt__)) _IC7Interrupt(void);
/****FUNCTION PROTOTYPES****/
void IC_SETUP(void);
void TIMER2_SETUP (void);
/******MAIN BODY******/
int main (void)
{
TRISD=0; /*Setting Port D as output*/
PORTD=0; /*Reset The LED*/
PORTD=0xff; /*Light The LED, to test the PIC is working*/
TRISB=0x003f; /*Setting PortB as input*/
ADPCFG=0xffff; /*Setting the analogue pin as digital input*/
TIMER2_SETUP(); /*Calling the Timer Setup Function*/
IC_SETUP(); /*Calling the Input Capture Setup Function*/
while(1)
{
}
return (0);
}
/***SETUP_IC****/
void IC_SETUP (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*/
IEC1bits.IC7IE = 1; /*Set the IC7 interrupt enable bit */
}
/****INTERRUPT FOR IC7****/
void __attribute__((__interrupt__)) _IC7Interrupt(void)
{
volatile unsigned int *ptr;
ptr =&IC7BUF; /*Initialise IC7BUF pointer*/
captureresult1= *ptr;
captureresult2= *ptr++;
LED =~ LED;
captureresult1 = IC7BUF;
period = captureresult2-captureresult1;
/*IFS1bits.IC7IF = 0; /*Interrupt bit is cleared*/
}
/***TIMER_SETUP***/
void TIMER2_SETUP (void)
{
T2CONbits.TCS=1; /*Using Internal Clock (Fosc/4)*/
T2CONbits.T32=1; /*TMRx and TMRy form a 32-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; /*Starts Timer*/
}
}
Thank you