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.

CC1352R: TIRTOS usleep precision

Part Number: CC1352R

Hey all,

I'm having an issue with timing precisions. I've downloaded the TI Drivers GPIO standby example from SDK6.20, and made a few changes, so that I have a wave form on GPIO_0 with 265us ON and 938us OFF. 

void *mainThread(void *arg0)
{
    GPIO_setConfig(CONFIG_GPIO_0, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_LOW);

    while (1)
    {
        GPIO_write(CONFIG_GPIO_0,1);
        usleep(265); //265us ON
        GPIO_write(CONFIG_GPIO_0,0);
        usleep(938); //938us OFF
    }
}

I've changed the sleep function for a usleep function in order to have microsecond precision. However based of an analysis on the GPIO with a logic analyzer, it seems that this timing precision of the GPIO is very poor.

 

Where I should have 265us for the ON time I have 384us, and instead of 938us for OFF I have 1052us. This is a difference of 114 to 119us! Why are these so different that what was inserted in the usleep function? 

Next I tried adjusting the input value in the function to match the expected real value, and therefore I came up with the values of usleep(175) for ON and usleep(840) for OFF. Now the real signal is closer to the desired values:

   

However, it seems that from one pulse to the other, the timings change a little bit. For example, I can see values for the ON pulse from 284 to 299us, which is a 16us variation.. And the same thing happens for the OFF period.

Why does this happen? And how do I increase precision?