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.

CC2340R5: I want to process at 60Hz

Part Number: CC2340R5

Tool/software:

I am using FreeRTOS on CC2340R5.
I want to process at 60Hz as accurately as possible.
However, since the xTaskDelayUntil function can only be specified in milliseconds, there will be a slight deviation.
How can I process at 60Hz as accurately as possible?

#define WAIT_MS (16)

void *mainThread(void *arg0)
{
    MyInitialize();

    TickType_t previousWakeTime;
    previousWakeTime = xTaskGetTickCount();
    while (1)
    {
        if (xTaskDelayUntil(&previousWakeTime, WAIT_MS) != pdTRUE)
        {
        }

        MyProcess();
    }
}

  • Hi Manabu,

    I suggest using one of the CC240R5's timers, I think the LGPT timer suits best your use case. Take look at the API documentation for more information.

    You can also review the Timers section in the User's Guide for a detailed list of all available timers.

    Regards,
    Tanguy

  • Thank you for your reply.

    I forgot to mention it in the explanation, but I want to put it in standby mode while not processing.
    Sorry.

    According to the explanation in the Timers section, it looks like "Clock DPL (ClockP Module ?)" can be used.
    I don't know if it will work because there isn't much example code, but I'll give it a try.

    Best regards,

  • Created using ClockP and SemaphoreP.
    It has been confirmed that ClockP goes into standby mode.

    [Link1]

    However, I don't know if SemaphoreP will go into standby mode.
    Will registering Power_idleFunc() as a semaphore callback put the device into standby mode?

    [Link2] [Link3]

    // https://software-dl.ti.com/simplelink/esd/simplelink_lowpower_f3_sdk/8.10.01.02/exports/docs/drivers/doxygen/html/_semaphore_p_8h.html
    // https://software-dl.ti.com/simplelink/esd/simplelink_lowpower_f3_sdk/8.10.01.02/exports/docs/drivers/doxygen/html/_clock_p_8h.html
    
    SemaphoreP_Params g_PeriodicSemaphoreParams;
    SemaphoreP_Handle g_PeriodicSemaphoreHandle;
    ClockP_Params g_PeriodicParams;
    ClockP_Handle g_PeriodicHandle;
    
    void PeriodicCallback(uintptr_t arg)
    {
        SemaphoreP_post(g_PeriodicSemaphoreHandle);
    }
    
    bool PeriodicInitialize()
    {
        SemaphoreP_Params_init(&g_PeriodicSemaphoreParams);
        g_PeriodicSemaphoreParams.mode = SemaphoreP_Mode_BINARY;
        g_PeriodicSemaphoreParams.callback = Power_idleFunc;
        g_PeriodicSemaphoreHandle = SemaphoreP_create(0, &g_PeriodicSemaphoreParams);
        if (g_PeriodicSemaphoreHandle == NULL)
        {
            return false;
        }
    
        ClockP_Params_init(&g_PeriodicParams);
        g_PeriodicParams.period = 16666;
        g_PeriodicParams.startFlag = true;
        g_PeriodicParams.arg = (uintptr_t)NULL;
        g_PeriodicHandle = ClockP_create(PeriodicCallback, 0, &g_PeriodicParams);
        if (g_PeriodicHandle == NULL)
        {
            return false;
        }
    
        return true;
    }
    
    void *mainThread(void *arg0)
    {
        MyInitialize();
        PeriodicInitialize();
    
        while (1)
        {
            SemaphoreP_pend(g_PeriodicSemaphoreHandle, SemaphoreP_WAIT_FOREVER);
            MyProcess();
        }
    }
    

    Best regards,

  • Hi Manabu,

    The semaphore will give the hand back to the RTOS scheduler and you should go back into standby mode, you don't have to register a callback for that.

    Regards,
    Tanguy

  • Thank you for your reply.

    I don't have an energy trace compatible debugger so I can't measure the current, but I'll connect a battery and see what happens for a while.
    Thanks!

    Best regards,