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.

TMS320F28379D: F2837 ecap captures two channel PWM

Part Number: TMS320F28379D

dear support team:

     Capture the first rising edge of pwm1 with ecap1, capture the first rising edge of pwm2 with ecap2, and calculate the phase of two PWM. It is found that the value captured by ecap1 is always greater than that captured by ecap2, whether pwm1 is first or pwm2 first.

     Is it because of interrupt priority? Or some other reason?

  • Hi,

    I don't think there is any such priority between the two ECAP modules. Are you resetting the counters of both capture modules at same time stamp ? It would be easier to debug if you can share the software configuration that you are using.

    Regards

    Himanshu

  • thank you so much for your reply, my software configuration as bellow:


    void main(void)
    {
       InitSysCtrl();

       InitECap1Gpio(20);       //inc a
       GPIO_SetupPinOptions(20, GPIO_INPUT, GPIO_ASYNC);

       InitECap2Gpio(21);       //inc b
       GPIO_SetupPinOptions(21, GPIO_INPUT, GPIO_ASYNC);

       DINT;
       InitPieCtrl();
       IER = 0x0000;
       IFR = 0x0000;
       InitPieVectTable();

       EALLOW;
       PieVectTable.ECAP1_INT = &ecap1_isr;
       PieVectTable.ECAP2_INT = &ecap2_isr;
       EDIS;

       InitECapture();

       IER |= M_INT4;
       PieCtrlRegs.PIEIER4.bit.INTx1 = 1;
       PieCtrlRegs.PIEIER4.bit.INTx2 = 1;

       EINT;
       ERTM;

       for(;;)
       {
          asm("          NOP");
       }
    }


    void InitECapture()
    {
       ECap1Regs.ECCTL1.bit.CAP1POL = 0;      //rising
       ECap1Regs.ECCTL1.bit.CAP2POL = 1;      //fall
       ECap1Regs.ECCTL1.bit.CAP3POL = 0;      //rising
       ECap1Regs.ECCTL1.bit.CAP4POL = 1;      //fall

       ECap1Regs.ECCTL1.bit.CTRRST1 = 0;       // abs
       ECap1Regs.ECCTL1.bit.CTRRST2 = 0;       // abs
       ECap1Regs.ECCTL1.bit.CTRRST3 = 0;       // abs
       ECap1Regs.ECCTL1.bit.CTRRST4 = 0;       // abs

       ECap1Regs.ECCTL1.bit.CAPLDEN = 1;       // Enable capture units
       ECap1Regs.ECCTL1.bit.PRESCALE = 0;      // /1

       ECap1Regs.ECCTL2.bit.CAP_APWM = 0;      //capture mode
       ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0;   //continuous mode

       ECap1Regs.ECEINT.all = 0x0000;
       ECap1Regs.ECCLR.all = 0xFFFF;
       ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1;     // Start Counter
       ECap1Regs.ECEINT.bit.CEVT4 = 1;         // 4 events = __interrupt

       ECap2Regs.ECCTL1.bit.CAP1POL = 0;      //rising
       ECap2Regs.ECCTL1.bit.CAP2POL = 1;      //fall
       ECap2Regs.ECCTL1.bit.CAP3POL = 0;      //rising
       ECap2Regs.ECCTL1.bit.CAP4POL = 1;      //fall

       ECap2Regs.ECCTL1.bit.CTRRST1 = 0;       // abs
       ECap2Regs.ECCTL1.bit.CTRRST2 = 0;       // abs
       ECap2Regs.ECCTL1.bit.CTRRST3 = 0;       // abs
       ECap2Regs.ECCTL1.bit.CTRRST4 = 0;       // abs

       ECap2Regs.ECCTL1.bit.CAPLDEN = 1;       // Enable capture units
       ECap2Regs.ECCTL1.bit.PRESCALE = 0;      // /1

       ECap2Regs.ECCTL2.bit.CAP_APWM = 0;      //capture mode
       ECap2Regs.ECCTL2.bit.CONT_ONESHT = 0;   //continuous mode

       ECap1Regs.ECCTL2.bit.SYNCI_EN = 1;
       ECap1Regs.ECCTL2.bit.SYNCO_SEL =0;
       ECap2Regs.ECCTL2.bit.SYNCI_EN = 1;
       ECap2Regs.ECCTL2.bit.SYNCO_SEL =0;

       ECap1Regs.ECCTL2.bit.SWSYNC=1;
       ECap2Regs.ECCTL2.bit.SWSYNC=0;

       EALLOW;
       InputXbarRegs.INPUT5SELECT = 0x51;
       GpioDataRegs.GPBDAT.bit.GPIO51 = 0;
       SyncSocRegs.SYNCSELECT.bit.ECAP1SYNCIN = 0x5;
       EDIS;

       ECap2Regs.ECEINT.all = 0x0000;
       ECap2Regs.ECCLR.all = 0xFFFF;
       ECap2Regs.ECCTL2.bit.TSCTRSTOP = 1;     // Start Counter
       ECap2Regs.ECEINT.bit.CEVT4 = 1;         // 4 events = __interrupt
    }


    __interrupt void ecap1_isr(void)
    {
       a_rise_time1 = ECap1Regs.CAP1;
       a_fall_time1 = ECap1Regs.CAP2;
       a_rise_time2 = ECap1Regs.CAP3;
       a_fall_time2 = ECap1Regs.CAP4;

       ECap1Regs.ECCLR.all = 0xFFFF;
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
    }

    __interrupt void ecap2_isr(void)
    {
       b_rise_time1 = ECap2Regs.CAP1;
       b_fall_time1 = ECap2Regs.CAP2;
       b_rise_time2 = ECap2Regs.CAP3;
       b_fall_time2 = ECap2Regs.CAP4;


      phase_ab1 =   a_rise_time1 - b_rise_time1;
      phase_ab2 =   a_fall_time1 - b_fall_time1;

       ECap2Regs.ECCLR.all = 0xFFFF;
       PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
    }

  • Hi,

    If the incoming signal frequency is too high then it might be possible the counter for one of the ECAP module gets overflowed and which might be resulting the incorrect reading. Best way I see is to use the ECAP modules in One-shot mode and start the counters of both at the same time. And instead of measuring the difference between rising edges of both, measure the difference between the falling edges i.e. second events of ECAP. This will help in the case where the phase difference between the two signals if greater than 180 degree. You can ReArm the modules again at the end of ECAP2 interrupt.

    Let me know if the suggested configuration works for you.

    Regards

    Himanshu

  • hi,

       Are the time bases of ecap1 and ecap2 synchronized? How can I configure them to synchronize?



  • Hi,

    Yes the bases of ecap1 and ecap2 can be synchronized either using software or epwm sync events as shown in the below figure of TRM.

    Thanks

    Himanshu

  • hi,

          if i use software to synchronized ecap1 and ecap2, is this the right setting? if not , please tell me how to configure it.

          ECap1Regs.ECCTL2.bit.SWSYNC = 1;      

          ECap2Regs.ECCTL2.bit.SWSYNC = 1;        

  • Hi,

    Yes the synchronization setting seems okay but keep in mind that all the syncing does is load the value from the phase register into the counter. So you don't have to necessarily use this synchronization between ECAP to measure the phase difference between signals. If you are just using the One-shot capture mode, then resetting the counters for both ECAP modules and re-arming them together should work perfectly. As I suggested before, you can trigger the interrupt on capture event 3 on ECAP1 and calculate delta during interrupt.

    If my reply answers your question please click on "This resolved my issue" button located at the bottom of my post.

    Regards

    Himanshu