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.

[参考译文] TMS320F2800137:X1CNT 计数问题

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1273127/tms320f2800137-x1cnt-counting-question

器件型号:TMS320F2800137

您好!
客户对 SYSCTL.c 中的示例代码有疑问:

do
    {
        //
        // Keep clearing the counter until it is no longer saturated
        //
        while(HWREG(CLKCFG_BASE + SYSCTL_O_X1CNT) > 0x1FFU)
        {
            HWREG(CLKCFG_BASE + SYSCTL_O_X1CNT) |= SYSCTL_X1CNT_CLR;
        }

        //
        // Wait for the X1 clock to saturate
        //
        while(HWREGH(CLKCFG_BASE + SYSCTL_O_X1CNT) != SYSCTL_X1CNT_X1CNT_M)
        {
            //
            // If your application is stuck in this loop, please check if the
            // input clock source is valid.
            //
            localCounter++;
            if(localCounter>2500000)
            {
                if(loopCount == 3U)
                    status = false;
                break;
            }
        }

        if(loopCount == 3U &&
           (HWREGH(CLKCFG_BASE + SYSCTL_O_X1CNT) == SYSCTL_X1CNT_X1CNT_M))
        {
            status = true;
        }
        //
        // Increment the counter
        //
        loopCount++;
        localCounter = 0U;
    }while(loopCount < 4U);

为什么选择值0x1FFU 来清除计数器? 是否有任何特殊原因、或者是否可以使用其他值?

此致、Holger

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

    您好、Holger、感谢您与我们取得联系!

    此代码主要是等待外部振荡器完全上电、并检查外部晶体是否按预期工作。
    如果您看到 X1CNT 寄存器和 X1CNT 位、它有11位、所以全1的值对应于0x7FF、这是在 X1时钟上递增计数后它饱和到的值、所以我们基本上等待3个 X1CNT 饱和循环、完成后我们继续 进一步展开。

    而0x1FFU 的值应该是0x7FFU、感谢您指出、我将向软件团队核实并返回给您。

    希望这是有意义的!