Bonjour,
Je débute dans les dsPIC, j'ai fait un programme pour mesurer les périodes générés par un GBF, mais j'ai trois soucis très basiques:
1. Je ne sais pas si mon programme vraiment et fait pour cela.
2. Comment je dois brancher le GBF a mon dspic? est-ce-que simplement je branche en IC1 et pas plus?
3. Comment lire se qui a mesuré mon dsPIC?
merci d'avanceCode:#include "p30f4013.h" /*************Global Variables and Constants*************/ /*Variables used for period calculation*/ unsigned int timePeriod= 0; unsigned int current_value=0,previous_value=0; unsigned int new_value=0; void __attribute__((__interrupt__)) _IC1Interrupt(void); void __attribute__((__interrupt__, __shadow__)) _T2Interrupt(void); /****FUNCTION PROTOTYPES****/ void IC1_SETUP(void); void TIMER2_SETUP (void); /******MAIN BODY******/ int main (void) { TRISD=0x0100; /*Setting PortB as input*/ ADPCFG=0xffff; /*Setting the analogue pin as digital input*/ TIMER2_SETUP(); /*Calling the Timer Setup Function*/ IC1_SETUP(); /*Calling the Input Setup Function*/ while(1) { } return (0); } /***SETUP_IC****/ void IC1_SETUP (void) { IC1CONbits.ICM=0b011; /*Capture every rising edge*/ IC1CONbits.ICBNE=0; /*Input capture buffer is empty*/ IC1CONbits.ICOV=0; /*No input capture overflow occured*/ IC1CONbits.ICI=0b00; /*Interrupt on every capture event*/ IC1CONbits.ICTMR=1; /*TMR2 contents are captured on captured event*/ IC1CONbits.ICSIDL=0; /*Input capture module will continue to operate in CPU Idle mode*/ //IP0bits.IC1IP = 1; /*Setup IC1 interrupt priority level*/ IFS0bits.IC1IF = 0; /*Interrupt bit is cleared*/ IEC0bits.IC1IE = 1; /*Set the IC1 interrupt enable bit */ } /****INTERRUPT FOR IC7****/ // Capture Interrupt Service Routine //unsigned int timePeriod= 0; void __attribute__((__interrupt__)) _IC1Interrupt(void) { previous_value=current_value; current_value=IC1BUF; if(current_value>previous_value) { timePeriod = current_value-previous_value; } else { timePeriod = (PR2 - previous_value) + current_value ; } } /***TIMER_SETUP***/ void TIMER2_SETUP (void) { //T2CON = 0x00; //Stops the Timer2 and reset control reg. T2CONbits.TCS=1; /*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*/ T2CON = 0x00; //Stops the Timer2 and reset control reg. TMR2 = 0x00; //Clear contents of the timer register PR2 = 0xFFFF; //Load the Period register with the value 0xFFFF //IPC0bits.IC1IP = 0x01; //Setup Timer2 interrupt for desired priority leve // (This example assigns level 1 priority) IFS0bits.T2IF = 0; //Clear the Timer1 interrupt status flag IEC0bits.T2IE = 1; //Enable Timer1 interrupts T2CONbits.TON = 1; //Start Timer1 with prescaler settings at 1:1 and //clock source set to the internal instruction cycle }
-----