This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ISR for SPRU807B, p 29

There is a "Code Snippet for CAP mode Absolute Time, Rising Edge Trigger" on page 29 of SPRU807B.  Assuming the following is added to the code snippet:

//-----------------------------------------------------------------------------
  EALLOW;
  GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 3;
  PieVectTable.ECAP1_INT = &IsrECap1;
  EDIS;
  IER |= M_INT4;
  PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
//-----------------------------------------------------------------------------

and the following code is in the ISR:

//-----------------------------------------------------------------------------
interrupt void IsrECap1(void)
{
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}//IsrECap1
//-----------------------------------------------------------------------------

what additional code is needed to ensure the ISR is handled correctly and the device is set to run again automatically?

  • You would still need to clear the flag of the source of the interrupt in the eCAP module.  Section 4.6 of the SPRU807 document suggests this.

  • I have read that doc.  Exactly what code should be added / changed?

  • Hi Clyde,

    You can use the ECCLR register to clear the flags (see table 11 in that doc). Note that you have to write a 1 in the bit corresponding to the flag you are trying to clear (whichever event triggered the interrupt). For example, in the code snippet you mentioned the comments say " Run Time (e.g. CEVT4 triggered ISR call) " so I'll use that as an example - the code to clear CEVT4 flag would be " ECap1Regs.ECCLR.bit.CEVT4 = 1; " That can easily be modified to clear whatever event flag you need to.

    You can find good examples of how to do this if you look in the ISRs of the eCAP examples in C280x, C2801x, C/C++ Header Files and Peripheral Examples.

    Regards,

    Katie

  • Let's try again.  The intent is to count the pulses and measure the time between pulses on GPIO7.  Using the code snippet from the example "Code Snippet for CAP mode Absolute Time, Rising Edge Trigger" on page 29 of SPRU807B … leads to this code:

    //-----------------------------------------------------------------------------
    void gInitECap(void)
    {
      EALLOW;
      GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 3;
      PieVectTable.ECAP2_INT = &IsrECap2;
      EDIS;
      IER |= M_INT4;
      PieCtrlRegs.PIEIER4.bit.INTx2 = 1;

      ECap2Regs.ECCTL1.bit.CAP1POL = EC_RISING;
      ECap2Regs.ECCTL1.bit.CAP2POL = EC_RISING;
      ECap2Regs.ECCTL1.bit.CAP3POL = EC_RISING;
      ECap2Regs.ECCTL1.bit.CAP4POL = EC_RISING;
      ECap2Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
      ECap2Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE;
      ECap2Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
      ECap2Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE;
      ECap2Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
      ECap2Regs.ECCTL1.bit.PRESCALE = EC_DIV1;

      ECap2Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
      ECap2Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
      ECap2Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
      ECap2Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
      ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;

      uiEcapCounts = 0;
    }
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    interrupt void IsrECap2(void)
    {
      uiEcapCounts++;

      ECap2Regs.ECCTL1.bit.CAPLDEN = ENABLE_CAP_REGS_LOADS;

      ui32T1 = ECap2Regs.CAP1;
      ui32T2 = ECap2Regs.CAP2;
      ui32T3 = ECap2Regs.CAP3;
      ui32T4 = ECap2Regs.CAP4;

      ECap2Regs.ECCLR.bit.CEVT1 = CLEAR_CAPTURE_EVENT_FLAG;
      ECap2Regs.ECCLR.bit.CEVT2 = CLEAR_CAPTURE_EVENT_FLAG;
      ECap2Regs.ECCLR.bit.CEVT3 = CLEAR_CAPTURE_EVENT_FLAG;
      ECap2Regs.ECCLR.bit.CEVT4 = CLEAR_CAPTURE_EVENT_FLAG;

      PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
    }
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    Uint16 gRetrieveEcapCounts(void)
    {
      return uiEcapCounts;
    }
    //-----------------------------------------------------------------------------

    What additional code is needed to ensure the ISR counts the pulses on a continuous basis?