Other Parts Discussed in Thread: C2000WARE
Hi,
I'm using the eCAP to measure a pulse width.
Basically CAP1 reg is set to rising edge, with reset. CAP2 is set to falling edge, no reset.
attached is the init function.
I'm reading CAP2 to get the pulse width.
I have an issue that sometimes during a pulse train I read 0 (zero) in CAP2, although I see the pulse present on the GPIO with a scope (I'm using a 1000 Int16 vector, and use the graph of the CCS to see all captures).
I use async mode on the GPIO, so no qualification. Pull-up disabled.
pulses are around 400ns, so roughly 80 sysclks (200MHz sysclk).
My first question is - how is it even possible to have 0 in CAP2? I cannot find a situation that this can happen.
second - any ideas on solution/how to debug this?
third - is there any mechanism that will reset the CAP2 result register (e.g. reading it) ?
thanks a lot!
void Init_eCAP(volatile struct ECAP_REGS *eCAP) { EALLOW; eCAP->ECEINT.all = 0x0000; // Disable all capture interrupts eCAP->ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags eCAP->ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads eCAP->ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped eCAP->ECCLR.bit.INT = 1; // Clear Global interrupt flag // Configure peripheral registers eCAP->ECCTL1.bit.CAP1POL = 0; // Rising edge eCAP->ECCTL1.bit.CAP2POL = 1; // Falling edge eCAP->ECCTL1.bit.CTRRST1 = 1; // Reset counter eCAP->ECCTL1.bit.CTRRST2 = 0; // Don't reset eCAP->ECCTL2.bit.SYNCI_EN = 0; // Enable sync in eCAP->ECCTL2.bit.SYNCO_SEL = 0; // Pass through eCAP->ECCTL2.bit.CONT_ONESHT = 0; // Continous eCAP->ECCTL2.bit.STOP_WRAP = 1; // Stop at 2 events eCAP->ECCTL2.bit.CAP_APWM = 0; // Ecap module operates in capture mode. eCAP->ECCTL2.bit.REARM = 1; // arm one-shot eCAP->ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads eCAP->ECCTL2.bit.TSCTRSTOP = 1; // Start Counter EDIS; }