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 counting question

Part Number: TMS320F2800137

Hi,
customer has question to our example code in 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);

Why was the value 0x1FFU be chosen for clearing the counter? Any special reason or can another value be used?

Regards, Holger

  • Hello Holger, Thanks for reaching out !

    This code is basically waiting for the external oscillator to completely power -up and check that external crystal is working as expected.
    If you see the X1CNT Register and X1CNT Bit it has 11 bits so for all 1's value corresponds to 0x7FF which is the value it saturates to after counting up on X1 clock so we basically wait for 3 loops of X1CNT saturation and after it completes we proceed further.

    The value 0x1FFU should be 0x7FFU instead thanks for pointing out, I will check with the software team and get back to you.

    Hope that makes sense !