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.

TMS320F28379D: epwm module counter does not wrap at PRD when initialized with non-zero CNTR value

Part Number: TMS320F28379D

I've encountered some strange behavior in tms320f28379d (or more precisely type4 epwm unit).

A pwm module is configured for up-down mode, with non-zero initial value written in CNTR register. When the pwm module is started by writing 1 to 'TBCLKSYNC', it initially counts up all the way to 65535 (running over PRD) , wraps to zero, after which the normal operation continues (counts up to PRD and down to zero). The expected behavior would be to count up until PRD and than start counting down from PRD value to zero.

If CNTR starts with zero initial value it operates normally (counts up reaching PRD after which it starts counting down to zero).

I tested only in up-down mode.

A workaround is to configure pwm modules to use sync signal, write a proper phase value to the phase registers and issue the software sync command.

 Edit

Even when I trigger software sync before the counter first runs over, it still does not count to the PRD but runs over the full value again. So essentially,one must not write directly to CNTR register.

I'm using LaunchPad TM320F28379D, if that matters at all.

  • This is not a device issue. By default, the PRD is in shadow mode and will not update until CNT=ZERO. When you write to the TBPRD value, and start from a non-zero CTR value, the PERIOD SHADOW REGISTER IS NOT UPDATED. Therefore, you get the behavior that you get. Same thing will happen if action qualifiers and CMPx registers are in shadow mode and set to update at CTR=0.

    Couple of options,

    Change the PRD load mode to be on SYNC then apply your sync,

    EPWM_selectPeriodLoadEvent(epwm_base, EPWM_SHADOW_LOAD_MODE_SYNC);
    

    Or disable the shadow mode for Period. 

    EPWM_setPeriodLoadMode(epwm_base, EPWM_PERIOD_DIRECT_LOAD);

    Or other options as you design your system.

    Anyway, this is expected behavior and follows the internal logic of the device.