File: C:\Mariano\Temp\SLUG_Autopilot\Stable\controlMCUSlugsMKII_dspic\sources\dsPIC_InputCapture_Interrupt.c

    1   #include "p33fxxxx.h"
    2   #include "controlMCUSlugsMKII.h"
    3   #include "controlMCUSlugsMKII_private.h"
    4   
    5   volatile uint16_T ic2up;
    6   volatile uint16_T ic3up;
    7   volatile uint16_T ic4up;
    8   volatile uint16_T ic5up;
    9   volatile uint16_T ic8up;
   10   void __attribute__((__interrupt__)) _IC2Interrupt(void)
   11   {
   12     static uint16_T IC2TMR;
   13     uint16_T tmp;
   14     uint16_T calcul;                     /* intermediate value */
   15     while (IC2CONbits.ICBNE == 1)
   16       tmp = IC2BUF;                      /* take the last value */
   17     if ((IC2CON & 1)==1)                 /* rising edge */
   18     {
   19       IC2CON = (IC2CON & 0xfffe);        /* detect next falling edge */
   20     } else                               /* falling edge */
   21     {
   22       IC2CON = (IC2CON | 0x0001);        /* detect next rising edge */
   23       calcul = tmp - IC2TMR;
   24       ic2up = calcul;
   25     }
   26   
   27     IC2TMR = tmp;
   28     _IC2IF = 0;
   29   }
   30   
   31   void __attribute__((__interrupt__)) _IC3Interrupt(void)
   32   {
   33     static uint16_T IC3TMR;
   34     uint16_T tmp;
   35     uint16_T calcul;                     /* intermediate value */
   36     while (IC3CONbits.ICBNE == 1)
   37       tmp = IC3BUF;                      /* take the last value */
   38     if ((IC3CON & 1)==1)                 /* rising edge */
   39     {
   40       IC3CON = (IC3CON & 0xfffe);        /* detect next falling edge */
   41     } else                               /* falling edge */
   42     {
   43       IC3CON = (IC3CON | 0x0001);        /* detect next rising edge */
   44       calcul = tmp - IC3TMR;
   45       ic3up = calcul;
   46     }
   47   
   48     IC3TMR = tmp;
   49     _IC3IF = 0;
   50   }
   51   
   52   void __attribute__((__interrupt__)) _IC4Interrupt(void)
   53   {
   54     static uint16_T IC4TMR;
   55     uint16_T tmp;
   56     uint16_T calcul;                     /* intermediate value */
   57     while (IC4CONbits.ICBNE == 1)
   58       tmp = IC4BUF;                      /* take the last value */
   59     if ((IC4CON & 1)==1)                 /* rising edge */
   60     {
   61       IC4CON = (IC4CON & 0xfffe);        /* detect next falling edge */
   62     } else                               /* falling edge */
   63     {
   64       IC4CON = (IC4CON | 0x0001);        /* detect next rising edge */
   65       calcul = tmp - IC4TMR;
   66       ic4up = calcul;
   67     }
   68   
   69     IC4TMR = tmp;
   70     _IC4IF = 0;
   71   }
   72   
   73   void __attribute__((__interrupt__)) _IC5Interrupt(void)
   74   {
   75     static uint16_T IC5TMR;
   76     uint16_T tmp;
   77     uint16_T calcul;                     /* intermediate value */
   78     while (IC5CONbits.ICBNE == 1)
   79       tmp = IC5BUF;                      /* take the last value */
   80     if ((IC5CON & 1)==1)                 /* rising edge */
   81     {
   82       IC5CON = (IC5CON & 0xfffe);        /* detect next falling edge */
   83     } else                               /* falling edge */
   84     {
   85       IC5CON = (IC5CON | 0x0001);        /* detect next rising edge */
   86       calcul = tmp - IC5TMR;
   87       ic5up = calcul;
   88     }
   89   
   90     IC5TMR = tmp;
   91     _IC5IF = 0;
   92   }
   93   
   94   void __attribute__((__interrupt__)) _IC8Interrupt(void)
   95   {
   96     static uint16_T IC8TMR;
   97     uint16_T tmp;
   98     uint16_T calcul;                     /* intermediate value */
   99     while (IC8CONbits.ICBNE == 1)
  100       tmp = IC8BUF;                      /* take the last value */
  101     if ((IC8CON & 1)==1)                 /* rising edge */
  102     {
  103       IC8CON = (IC8CON & 0xfffe);        /* detect next falling edge */
  104     } else                               /* falling edge */
  105     {
  106       IC8CON = (IC8CON | 0x0001);        /* detect next rising edge */
  107       calcul = tmp - IC8TMR;
  108       ic8up = calcul;
  109     }
  110   
  111     IC8TMR = tmp;
  112     _IC8IF = 0;
  113   }