Hello,
I am trying to use EPWM2 as a general purpose timer to provide a timestamp to measure intervals between XINT1 interrupts.
CPU is at 60 MHz on the LaunchpadXL, EPWM2 prescalars are set to /1.
XINT1 ISR is configured for both rising and falling edges (POLARITY=3)
In each XINT1 ISR, I capture the value of EPWM2.TBCTR, and then set EPWM2.TBCTR=0;
With a 50% duty, 10khz input to GPIO6/XINT1, my expectation is that I should see TBCTR=3000 counts. Instead, I am seeing ~3250 counts when a rising edge is detected, and ~2700 counts when a falling edge is detected.
I confirmed on a scope that the signal being input is a PWM with 50us high time, 50us low time.
If I set the PWM to 25% duty, 10khz input, I expect to see TBCTR = 1500 counts (25us) for the falling edge and 4500 (75us) for the rising edge. I instead see ~1210 counts for falling edge and ~4760 counts for rising edge. Again I confirmed that the input to GPIO6/XINT1 is correct.
Xint ISR is
__interrupt void xint1_isr(){
xint1_capture = EPwm2Regs.TBCTR;
EPwm2Regs.TBCTR = 0x0000; // Reset the counter for timestamp
if (next_edge_is_rising == true){
xint1_low_time = xint1_capture;
next_edge_is_rising = false;
}
else{
xint1_high_time = xint1_capture;
next_edge_is_rising = true;
}
PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}
Any suggestions on why I'm seeing these different measurements?