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.

TMS320F28027: EPWM2 used as general purpose timer, results are off with known interval

Part Number: TMS320F28027


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?

  • Hi Mark,

    Am I correct in stating that your EPWM signal output looks okay/as expected, but the TBCTR value you capture in the XINT ISR (using the xint1_capture variable) is not matching what you expect? What are your EPWM action qualifiers? There is some interrupt latency with the PIE as documented in the datasheet, but I'm uncertain that plays a role here.

    Have you instead tried using the event trigger submodule to trigger an interrupt ISR and compare the results from that method (you'd have to select the event trigger interrupt source to match the action qualifier event you are using to toggle the EPWM e.g. CMPA/B)? 

    Best Regards,

    Allison