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 Modules not working right when used together

I'm trying to make an application that uses the Ecap0 to generate an output signal in APWM mode and the Ecap1 to capture the frecuency of an input signal. When I use them separatly they work fine, but when I use them together, the capture times revealed by the Ecap1 are not right.

Here are the configurations I use:

void ecap_0_init() {
// Counter Phase Control Register
Ecap0Regs->CTRPHS = 0;

// Control Register 1
Ecap0Regs->ECCTL1 = 0;
Ecap0Regs->ECCTL1 |= (0 << 0); // CAP1POL
Ecap0Regs->ECCTL1 |= (0 << 1); // CTRRST1
Ecap0Regs->ECCTL1 |= (0 << 2); // CAP2POL
Ecap0Regs->ECCTL1 |= (0 << 3); // CTRRST2
Ecap0Regs->ECCTL1 |= (0 << 4); // CAP3POL
Ecap0Regs->ECCTL1 |= (0 << 5); // CTRRST3
Ecap0Regs->ECCTL1 |= (0 << 6); // CAP4POL
Ecap0Regs->ECCTL1 |= (0 << 7); // CTRRST4
Ecap0Regs->ECCTL1 |= (0 << 8); // CAPLDEN
Ecap0Regs->ECCTL1 |= (0 << 9); // PRESCALE
Ecap0Regs->ECCTL1 |= (0 << 14); // FREE/SOFT

// Control Register 2
Ecap0Regs->ECCTL2 = 0;
Ecap0Regs->ECCTL2 |= (0 << 0); // CONT/ONESHT
Ecap0Regs->ECCTL2 |= (0 << 1); // STOP/WRAP
Ecap0Regs->ECCTL2 |= (0 << 3); // RE-ARM
Ecap0Regs->ECCTL2 |= (1 << 4); // TSCCTRSTOP
Ecap0Regs->ECCTL2 |= (0 << 5); // SYNCI_EN
Ecap0Regs->ECCTL2 |= (2 << 6); // SYNCO_SEL
Ecap0Regs->ECCTL2 |= (0 << 8); // SWSYNC
Ecap0Regs->ECCTL2 |= (1 << 9); // CAPT/APWM Mode
Ecap0Regs->ECCTL2 |= (0 << 10); // APWM Polarity

// CAP1 (TBPRD in APWM)
Ecap0Regs->CAP1 = ecap_calc_prd(1 << 3);

// CAP2 (CMPA in APWM)
Ecap0Regs->CAP2 = ecap_calc_amp(1 << 3);
}

void ecap_1_init() {
// Set ECAP1 pin as input
SysRegs->CFGCHIP1 &= ~(0x1F << 22);

// Disable all capture events
Ecap1Regs->ECEINT = 0x0;

// Clear all CAP interrupt flags
Ecap1Regs->ECCLR = 0xFFFF;

// Disable CAP1-CAP4 register loads
Ecap1Regs->ECCTL1 &= ~(1 << 8);

// Make sure the counter is stopped
Ecap1Regs->ECCTL2 &= ~(1 << 4);

// Counter Phase Control Register
Ecap1Regs->CTRPHS = 0;

// Control Register 1
Ecap1Regs->ECCTL1 = 0;
Ecap1Regs->ECCTL1 |= (0 << 0); // CAP1POL
Ecap1Regs->ECCTL1 |= (1 << 1); // CTRRST1
Ecap1Regs->ECCTL1 |= (0 << 2); // CAP2POL
Ecap1Regs->ECCTL1 |= (1 << 3); // CTRRST2
Ecap1Regs->ECCTL1 |= (0 << 4); // CAP3POL
Ecap1Regs->ECCTL1 |= (1 << 5); // CTRRST3
Ecap1Regs->ECCTL1 |= (0 << 6); // CAP4POL
Ecap1Regs->ECCTL1 |= (1 << 7); // CTRRST4
Ecap1Regs->ECCTL1 |= (0 << 9); // PRESCALE
Ecap1Regs->ECCTL1 |= (0 << 14); // FREE/SOFT

// Control Register 2
Ecap1Regs->ECCTL2 = 0;
Ecap1Regs->ECCTL2 |= (0 << 0); // CONT/ONESHT
Ecap1Regs->ECCTL2 |= (3 << 1); // STOP/WRAP
Ecap1Regs->ECCTL2 |= (0 << 5); // SYNCI_EN
Ecap1Regs->ECCTL2 |= (2 << 6); // SYNCO_SEL
Ecap1Regs->ECCTL2 |= (0 << 8); // SWSYNC
Ecap1Regs->ECCTL2 |= (0 << 9); // CAPT/APWM Mode
Ecap1Regs->ECCTL2 |= (0 << 10); // APWM Polarity

// Enable Captures
Ecap1Regs->ECCTL1 |= (1 << 8);

// Start Counter
Ecap1Regs->ECCTL2 |= (1 << 4);

// Re-arm
Ecap1Regs->ECCTL2 |= (1 << 3);

// Interrupt Enable Register
Ecap1Regs->ECEINT = 0;
Ecap1Regs->ECEINT |= (0 << 1); // CEVT1
Ecap1Regs->ECEINT |= (0 << 2); // CEVT2
Ecap1Regs->ECEINT |= (0 << 3); // CEVT3
Ecap1Regs->ECEINT |= (1 << 4); // CEVT4
Ecap1Regs->ECEINT |= (0 << 5); // CTROVF
Ecap1Regs->ECEINT |= (0 << 6); // CTR=PRD
Ecap1Regs->ECEINT |= (0 << 7); // CTR=CMP
}

void ecap_1_isr() {
static int i = 0;
_disable_interrupts();
valores[i++] = Ecap1Regs->CAP1;
valores[i++] = Ecap1Regs->CAP2;
valores[i++] = Ecap1Regs->CAP3;
valores[i++] = Ecap1Regs->CAP4;
if (i == 1024) i = 0;
ecap_1_init();
IER |= (1 << 4);
_enable_interrupts();
}

The HWI_INT4 is set to act on the ECAP1 pin. As I said before, If I use the Ecap1 by its own it gives me the results I'm looking for in the valores array, but If I initialize the Ecap0 as well, the results are not correct, giving me captures well below (capture ~ 10-250) the result I'm looking for (capture ~ 2,500,000). It gives me the result I want in some captures but many are this bogus times that I don't understand what are they for.

Please let me know if I'm doing something wrong in my configuration.

Thanks in advance,

~ Aquiles Lacruz