/******************************************************************** * Function: void ISR_CCP1(void) *******************************************************************/ void ISR_CCP3(void) // Interruption sur front montant sur RA2 { n_Mont = n_TMR1; if (!PulseOK) { n_TMR1 = 0; // On remet le compteur à zéro rise = n_Mont*65536 + ReadCapture3(); // Lit la valeur de CCP1 fall = n_Des*65536 + ReadCapture4(); // Lit la valeur de ECCP1 lowtime = rise - fall; // Largeur du front bas pulse_width = fall - lastrise; // Largeur du front haut => Presque inutile lastrise = ReadCapture3(); // Sauvegarde PulseOK = TRUE; // Indique qu'on a reçu un nouveu RF bit // printf("lowtime: %u us \r\n", lowtime); } }
void __ISR(_INPUT_CAPTURE_3_VECTOR) INT_IC3_Handler(void) { mIC3ClearIntFlag(); //Read captured timer values if(mIC3CaptureReady()) { IC3_CT_Rise = mIC3ReadCapture(); IC3_CT_Fall = mIC3ReadCapture(); } //Determine period if(IC3_CT_Rise > IC3_CT_Fall) period3 = (IC3_CT_Fall + PER_REG) - IC3_CT_Rise; else period3 = IC3_CT_Fall - IC3_CT_Rise; //Correct period if out of range if(period3 > PITCH_H - 3) period3 = PITCH_H; else if(period3 < PITCH_L + 3) period3 = PITCH_L; //Turn period into a percentage 0.0 thru 100.0% and //a Pitch angle -PITCH_LIMIT to PITCH_LIMIT degrees if(zero_mode == 0) { if(period3 > pm + 5) { pitch_pc = ((PITCH_H + period3 - (2.0 * pm)) / (PITCH_H - pm)) * 50.0; IC_PITCH = (-1.0 * PI * ((pitch_pc - 50.0) / 100.0))/(90.0/PITCH_LIMIT); } else if(period3 < pm - 5) { pitch_pc = ((period3 - PITCH_L) / (pm - PITCH_L)) * 50.0; IC_PITCH = (PI * ((50.0 - pitch_pc) / 100.0))/(90.0/PITCH_LIMIT); } else { pitch_pc = 50.0; IC_PITCH = 0.0; } } ReadCapture3(garbage); //clear any remaining capture values }