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 且 TBCTR 不递增

Guru**** 2463330 points
Other Parts Discussed in Thread: C2000WARE

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1497649/tms320f28379d-epwm-is-not-generated-and-tbctr-is-not-incrementing

部件号:TMS320F28379D
主题:C2000WARE 中讨论的其他器件

工具/软件:

大家好:
我不熟悉使用该板。 当前正在尝试生成应在我的工程中使用的 PWM。 我已附加以下代码、用于打开 LED。  然而,在执行时,我发现 LED 没有发光。 尽管我们努力重新检查代码、必须使用的寄存器等 此外、TBCTR 寄存器不递增。 我无法解决这个问题。 也没有编译错误。 我打算使用加/减计数器、时钟频率为10 MHz 请帮助我解决此问题。 提前感谢!

// 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.:请忽略一些可能与相应代码功能无关的注释、因为它们在代码更改时未被修改。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好:  

    我将及时查看和答复。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    当然、谢谢!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    你好 Sanjeev、

    请查看提供的 C2000Ware 软件示例。 这里有 LED 闪烁示例: c:\ti\c2000\C2000Ware_5_04_00_00\driverlib\f2837xd\examples\cpu1\led   、而 EPWM 示例: c:\ti\c2000\C2000Ware_5_04_00_00\driverlib\f2837xd\examples\cpu1\epwm

    这将帮助您查找配置中的问题。 如果您还有其他问题、敬请告知。

    此致、

    Stevan D.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    非常感谢、Stevan! 看看它、如果我有任何问题、我们会重新检视您的建议。