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_setCounterCompareShadowLoadMode() driverlib not setting properly

Part Number: TMS320F28379D

Tool/software:

Hello Experts,

Looking at the EPWM_setCounterCompareShadowLoadMode() function in epwm.h, part of the driverlib package, this function does not enable shadow load mode?

I think it is hardwired to only use Immediate mode only?

Is this a bug in the epwm driver , could you please check this.

Here is the function:

//*****************************************************************************
//
//! Sets up the Counter Compare shadow load mode
//!
//! \param base is the base address of the EPWM module.
//! \param compModule is the counter compare module.
//! \param loadMode is the shadow to active load mode.
//!
//! This function enables and sets up the counter compare shadow load mode.
//! Valid values for the variables are:
//!  - compModule
//!      - EPWM_COUNTER_COMPARE_A - counter compare A.
//!      - EPWM_COUNTER_COMPARE_B - counter compare B.
//!      - EPWM_COUNTER_COMPARE_C - counter compare C.
//!      - EPWM_COUNTER_COMPARE_D - counter compare D.
//!  - loadMode
//!      - EPWM_COMP_LOAD_ON_CNTR_ZERO - load when counter equals zero
//!      - EPWM_COMP_LOAD_ON_CNTR_PERIOD - load when counter equals period
//!      - EPWM_COMP_LOAD_ON_CNTR_ZERO_PERIOD - load when counter equals
//!                                             zero or period
//!      - EPWM_COMP_LOAD_FREEZE  - Freeze shadow to active load
//!      - EPWM_COMP_LOAD_ON_SYNC_CNTR_ZERO - load when counter equals zero
//!      - EPWM_COMP_LOAD_ON_SYNC_CNTR_PERIOD -load when counter equals period
//!      - EPWM_COMP_LOAD_ON_SYNC_CNTR_ZERO_PERIOD - load when counter equals
//!                                                  zero or period
//!      - EPWM_COMP_LOAD_ON_SYNC_ONLY - load on sync only
//!
//! \return None.
//
//*****************************************************************************
static inline void
EPWM_setCounterCompareShadowLoadMode(uint32_t base,
                                     EPWM_CounterCompareModule compModule,
                                     EPWM_CounterCompareLoadMode loadMode)
{
    uint16_t syncModeOffset;
    uint16_t loadModeOffset;
    uint16_t shadowModeOffset;
    uint32_t registerOffset;

    //
    // Check the arguments
    //
    ASSERT(EPWM_isBaseValid(base));

    if((compModule == EPWM_COUNTER_COMPARE_A) ||
       (compModule == EPWM_COUNTER_COMPARE_C))
    {
        syncModeOffset = 10U;
        loadModeOffset = 0U;
        shadowModeOffset = 4U;
    }
    else
    {
        syncModeOffset = 12U;
        loadModeOffset = 2U;
        shadowModeOffset = 6U;
    }

    //
    // Get the register offset.  EPWM_O_CMPCTL for A&B or
    // EPWM_O_CMPCTL2 for C&D
    //
    registerOffset = base + EPWM_O_CMPCTL + ((uint32_t)compModule & 0x1U);

    //
    // Set the appropriate sync and load mode bits and also enable shadow
    // load mode. Shadow to active load can also be frozen.
    //
    HWREGH(registerOffset) = ((HWREGH(registerOffset) &
                         ~((0x3U << syncModeOffset) | // Clear sync mode
                           (0x3U << loadModeOffset) | // Clear load mode
                           (0x1U << shadowModeOffset))) | // shadow mode
                         ((((uint16_t)loadMode >> 2U) << syncModeOffset) |
                         (((uint16_t)loadMode & 0x3U) << loadModeOffset)));
}

I tried using it like this:

        EPWM_setCounterCompareShadowLoadMode(EPWM3_BASE,
                                             EPWM_COUNTER_COMPARE_A,
                                             EPWM_COMP_LOAD_ON_CNTR_ZERO);

But the CMPCTL(SHDWAMODE bit) is still 1, i.e Immediate load mode!!

As per the TRM manual if SHDWAMODE is 1 , it is still in Immediate load mode!

  • Hello,

    Shadow load mode is used by default for counter compare values as seen in the reset values listed for this register description:

    To disable the default shadow load mode and enable immediate mode, you would use the disable function: 

    EPWM_disableCounterCompareShadowLoadMode()
     
    To debug your code, I would suggest stepping over your code - step over this function and refresh the register window to see if the correct settings have been enabled in regard to shadow loading on counter = 0. You can also check the values before programming the PWM to ensure that registers are at their reset state. 

    Best Regards,

    Allison

  • Hi Allison, I cleared the cusfusion,

    Although EPWM_setCounterCompareShadowLoadMode does indeed set the pwm in shadow load mode, i am also using the Fast current loop library function FCL_initPWM() which sets the pwm back to immediate load mode using the EPWM_disableCounterCompareShadowLoadMode() function. I had overlooked this !

    You can close this thread.

    Thankyou!

  • Glad to see it was resolved! I will close this thread Slight smile