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.

TMS320F28374S: Execution time for setting ePWM counter compare

Part Number: TMS320F28374S

Hi,

I am trying to control 10 ePWM channels in a high speed control loop and I am blowing my execution window. While trying to improve performance I noticed that the calls to set the counter compare for the ePWMs are taking a while.

Time taken for the setting each PWM channel is ~160 nano seconds by executing the following:

timebaseperiod = EPWM_getTimeBasePeriod(pwmId);

comparatorCount = timebaseperiod - (timebaseperiod * dutyCycle);

EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, comparatorCount);


Is this an expected execution time for reading and writing to the PWM registers or is there something I can do to speed it up?

Thank you.

  • Hi,

    This seems like a lot of cycles (assuming you are running the device at 200MHz) for setting registers.
    Are you running the code from SRAM or FLASH?
    Did you take a look at cycle count for each of the 3 code statements above?
    For debug, if you are suspecting the function call,  you can directly read/write to registers using HWREG function and check the cycle time.

  • Hi Subrahmanya,

    Thank you for the quick response. Yes, device is running at 200MHz and the code is running from RAM. Is there a way for me to measure the cycle count for statements using code composer? Right now I am toggling a GPIO and measuring time on scope. I measured time for a read and a write to the PWM registers using the HWREG function and it comes to 25 clock cycles:

    HWREGH(base + EPWM_O_TBPRD)
    
    HWREGH(base + registerOffset + 0x1U) = compCount;

  • Hi,

    You can simply place a breakpoint in the code (before and after your code being profiled) and refer to the TBCTR value change inside EPWM itself.
    You need to configure the Time base counter to be halted, make sure TBCTL[FREE_SOFT] bit is zero.
    25 cycles is definitely not correct. You can step through the code and root cause where the number is going high.

  • Hi,

    I used the above method to count the clock cycles. Given below result. The driverlib functions have additional overhead, maybe I should use the hardware registers directly? But even if I use the HW registers, is 5 and 9 clocks for a read/write respectively correct or is it still slow?

    EPWM_getTimeBasePeriod(base) 16 HWREGH(base + EPWM_O_TBPRD) 5
    EPWM_setCounterCompareValue(base, compModule, compCount) 29 HWREGH(base + registerOffset + 0x1U) = compCount; 9
  • Hi,

    Optimization level 0 or above needs to be used in the application project to inline the driverlib static inline functions. The large cycle count is due to the function call overhead. Also the Debug build would do an additional ASSERT check which would take additional cycles.

    Thanks

    Vasudha