• TI Thinks Resolved

RTOS/CC1310: NoRTOS Clock module without jitter

Intellectual 345 points

Replies: 1

Views: 34

Part Number: CC1310

Tool/software: TI-RTOS

Hello.

There is a simple example of using clock in NoRTOS mode using a semaphore. I need to get accurate time interruptions. As a result, I get jitter 34 mks, and sometimes 174 mks, both in a positive and in a negative direction. 
For me it is very critical. How do I make stable low-power clock interruptions without jitter?
/*
 *  ======== main_nortos.c ========
 */
#include <stdint.h>
#include <stddef.h>
#include <NoRTOS.h>
#include <ti/drivers/Board.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/dpl/ClockP.h>
#include <ti/drivers/dpl/SemaphoreP.h>
#include "Board.h"

uint32_t Clock_tickPeriod = 1; // 1 mks
ClockP_Struct clkStruct;
ClockP_Handle clkHandle;
SemaphoreP_Handle mainSemaphore;

/*
 *  Clock callback fnx
 */
void MainClockFxn(uintptr_t arg)
{
    SemaphoreP_post(mainSemaphore);
}

/*
 *  ======== main ========
 */
int main(void)
{
    NoRTOS_Config cfg;

    NoRTOS_getConfig(&cfg);
    cfg.clockTickPeriod = Clock_tickPeriod;
    cfg.idleCallback = Power_idleFunc;
    NoRTOS_setConfig(&cfg);

    /* Call driver init functions */
    Board_init();

    /* Start NoRTOS */
    NoRTOS_start();

    GPIO_init();
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    // Init Semaphore
    SemaphoreP_Params params;
    SemaphoreP_Params_init(&params);
    params.mode = SemaphoreP_Mode_BINARY;
    mainSemaphore = SemaphoreP_create(0, &params);
    if(mainSemaphore == NULL) {
        while(1); // stop program
    }

    // Init Clock
    ClockP_Params clkParams;
    ClockP_Params_init(&clkParams);
    uint32_t period = 10000/Clock_tickPeriod; // period = 10 ms
    clkParams.period = period;
    clkParams.startFlag = false;
    ClockP_construct(&clkStruct, (ClockP_Fxn)MainClockFxn, period, &clkParams);
    clkHandle = ClockP_handle(&clkStruct);
    ClockP_start(clkHandle);

    //
    while (1) {
        GPIO_toggle(Board_GPIO_LED0);
        SemaphoreP_pend(mainSemaphore, SemaphoreP_WAIT_FOREVER );
    };

    return 0;
}