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.

eCAP Sync

Hi everybody!

I´m trying to use the eCAP2 and eCAP3 to measure the phase shift of two squared signals. I read on the SPRUFG4a page 21 that the eCAPs can be syncronized with software by writing a 1 on ECap2.Regs.ECCTL2.bit.SWSYNC. I´ve trying to see any synchocronization on ECap3.Regs.CTRPHS but no value is copied on the register.

 below you can find the Configuration of my eCAPs:

    ECap2Regs.ECEINT.all = 0;                    // Disable all eCAP interrupts
    ECap2Regs.ECCTL1.bit.CAPLDEN = 0;            // Disabled loading of capture results
    ECap2Regs.ECCTL2.bit.TSCTRSTOP = 0;            // Stop the counter
    ECap2Regs.TSCTR = 0;                        // Clear the counter
    ECap2Regs.CTRPHS = 0;                        // Clear the counter phase register
    ECap2Regs.ECCTL2.all = 0x0096;                // ECAP control register 2
    ECap2Regs.ECCTL1.all = 0x01C4;                // ECAP control register 1
    ECap2Regs.ECEINT.all = 0x0004;                // Enable desired eCAP interrupts
    ECap2Regs.ECCTL2.bit.SYNCO_SEL = 0;
    ECap2Regs.ECCTL2.bit.SYNCI_EN = 1;

    ECap3Regs.ECEINT.all = 0;                    // Disable all eCAP interrupts
    ECap3Regs.ECCTL1.bit.CAPLDEN = 0;            // Disabled loading of capture results
    ECap3Regs.ECCTL2.bit.TSCTRSTOP = 0;            // Stop the counter
    ECap3Regs.TSCTR = 0;                        // Clear the counter
    ECap3Regs.CTRPHS = 0;                        // Clear the counter phase register
    ECap3Regs.ECCTL2.all = 0x0096;                // ECAP control register 2
    ECap3Regs.ECCTL1.all = 0x01C4;                // ECAP control register 1
    ECap3Regs.ECEINT.all = 0x0004;                // Enable desired eCAP interrupts
    ECap3Regs.ECCTL2.bit.SYNCO_SEL = 0;
    ECap3Regs.ECCTL2.bit.SYNCI_EN = 1;

And here you can find my interrupt service routines:

interrupt void eCAP2_isr(void)
{
    ECap2Regs.ECCTL2.bit.SWSYNC = 1; 

    ECap2Regs.ECCLR.bit.INT = 1;                // Clear the ECAP1 interrupt flag
    ECap2Regs.ECCLR.bit.CEVT2 = 1;                // Clear the CEVT1 flag
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;    // Must acknowledge the PIE group 4
}

interrupt void eCAP3_isr(void)
{
    PhaseUI = ECap3Regs.CTRPHS;
    ECap3Regs.ECCLR.bit.INT = 1;                // Clear the ECAP1 interrupt flag
    ECap3Regs.ECCLR.bit.CEVT2 = 1;                // Clear the CEVT1 flag

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;    // Must acknowledge the PIE group 4
}

  • Abraham,

    I am not certain, but I think you've misunderstand how the eCAP is supposed to work.

    The SWSYNC bit can synchronize the timers of eCap2 and eCap3, but it will not capture the phase difference in CTRPHS.  To be more clear, when a 1 is written to the SWSYNC bit, eCAP2's counter will be loaded with ECap2Regs.CTRPHS.  Since in your configuration eCap3 is also configured to receive eCap2's synch event, eCap3 will be loaded with ECap3Regs.CTRPHS at the eCAP2.SWSYNC write as well.  Both counters will then continue counting.

    Once synchronized, you can then capture an edge on each eCAP module and subtract them to figure out the delay (phase difference) between the edges.  To make things simple, I would recommend making the CTRPHS of both eCAPs 0 unless you have a reason not to.

    Hopefully this makes things more clear.


    Thank you,
    Brett