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 is not generated and TBCTR is not incrementing

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hi everyone,
I am new to using this board. Currently trying to generate a PWM which shall be used in my project. I have attached the code below to turn on an LED. However, upon the execution, I found that the LED is not glowing. Despite putting the efforts to recheck the code, registers that have to be used etc. Also, the TBCTR register is not incrementing. I am not able to solve this issue. There is no compilation error either. I intend to use the up-down counter, and the clock frequency is 10 MHz Please help me solve this issue. Thanks in advance!

// Libraries
#include "F2837xD_device.h"
#include "math.h"

// Helper Function
void configure_clock()
{
    EALLOW; //to enable us to write into protected registers

    ClkCfgRegs.CLKSRCCTL1.bit.OSCCLKSRCSEL = 1; //
    ClkCfgRegs.SYSPLLCTL1.bit.PLLCLKEN = 0; //disable routing to PLL
    ClkCfgRegs.SYSCLKDIVSEL.all = 0; //division by 1
    ClkCfgRegs.SYSPLLMULT.all = 1; //this makes all the bits of MULT as 1 (decimal)
    while (ClkCfgRegs.SYSPLLSTS.bit.LOCKS != 1); //the semicolon ensures that the execution does not proceed until PLL locking occurs. This prevents errors
    ClkCfgRegs.SYSCLKDIVSEL.all = 1; //division by 2
    ClkCfgRegs.SYSPLLCTL1.bit.PLLCLKEN = 1; //enable routing to PLL
    ClkCfgRegs.SYSCLKDIVSEL.all = 0; //restore to division by 1

    EDIS; //to enable write-protection for registers

}

void configure_watchdog(void)
{
    EALLOW;
    WdRegs.WDCR.all = 0x28;  // Enable watchdog timer
    EDIS;
}

void configure_epwm()

{

    float duty_cycle = 0.4;

    EALLOW;

    // Enable ePWM1 clock

    CpuSysRegs.PCLKCR2.bit.EPWM1 = 1;

    // Configure ePWM1

    EPwm1Regs.TBCTL.bit.CTRMODE = 2;     // Up-down count mode

    EPwm1Regs.TBCTL.bit.FREE_SOFT = 0;   // Free-run mode without software control

    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;   // High-speed clock divider set to divide by 1

    EPwm1Regs.TBCTL.bit.CLKDIV = 0;      // Clock divider set to divide by 1

    EPwm1Regs.TBCTL.bit.PRDLD = 1;       // Immediate period load

    // Set period and compare values

    EPwm1Regs.TBPRD = 99;                // Set period

    EPwm1Regs.CMPB.bit.CMPB = (int)((1-duty_cycle)*EPwm1Regs.TBPRD); // 40% duty cycle

    // Action qualifier configuration

    EPwm1Regs.AQCTLB.bit.CAU = 2;        // Clear on CAU

    EPwm1Regs.AQCTLB.bit.CAD = 1;        // Set on CAD

    EPwm1Regs.AQCTLB.bit.PRD = 0;

    EPwm1Regs.AQCTLB.bit.ZRO = 0;

    // Enable ePWM1 counter

    EPwm1Regs.TBCTL.bit.CTRMODE = 2;     // Ensure up-down count mode

    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;   // Ensure high-speed clock divider is set

    // Start the counter

    EPwm1Regs.TBCTL.bit.CTRMODE = 2;     // Up-down count mode

    EPwm1Regs.TBCTL.bit.FREE_SOFT = 0;   // Free-run mode

    EDIS;

}


void main()

{

    // ... other configurations ...
    //disable WDT
    EALLOW;
    WdRegs.WDCR.all=0x68;

    //configure CPU clock
    configure_clock();
    configure_watchdog();
    configure_epwm();

    while(1)

    {

        EALLOW;

        WdRegs.WDKEY.all = 0x55;

        WdRegs.WDKEY.all = 0xAA;

        EDIS;

        // Read and print TBCTR

        Uint16 tbctrValue = EPwm1Regs.TBCTR;

        // Use a method to print or display tbctrValue

        // Add a small delay if needed

        // for (int i = 0; i < 10000; i++) {}

    }

}



P.S.: Kindly ignore some comments that might seem irrelevant with the corresponding code's functionality as they haven't been modified when the code was changed.