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.

RTOS/PROCESSOR-SDK-K2G: How to get accurate clock ticks?

Part Number: PROCESSOR-SDK-K2G
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

I tried to setup a clock with 10us period but I got the period of 8.2us.

pdk_k2g_1_0_7
bios : 6.46.5.55
xdctools_3_32_01_22_core


In my .cfg, I have the following settings

  var Clock = xdc.useModule('ti.sysbios.knl.Clock');
  Clock.tickPeriod = 10;  // 10us

In my .c code, I setup period to be 1.

    Error_init(&eb);
    Clock_Params_init(&clockParams);
    clockParams.period = 1;        /* 1 clock ticks */
    clockParams.startFlag = TRUE;  /* start immediately */
    hClock = Clock_create(clock_swi, 1, &clockParams, &eb);

clock_swi function toggles a GPIO pin so I can observe the period of clock_swi on scope.
I expect to get clock_swi every 10us but I measured its period as 8.2us.

I followed the tips in
processors.wiki.ti.com/.../Processor_SDK_RTOS:_TI_RTOS_Tips_And_Tricks
and set correct ARM CPU value
  BIOS.cpuFreq.lo = 600000000;
in my .cfg but still get period of 8.2us.

The Clock Module in RTOS Object View(ROV) shows
tickSource: ti.sysbios.knl.Clock.TickSource_TIMER
tickMode: ti.sysbios.knl.Clock.TickMode_PERIODIC
timerId: 0
swiPriority: 15
tickPeriod: 10
nSkip: 1

Q1: Do I miss any settings?
Q2: The timerId is 0 in ROV. Can you provide Timer Mapping Table for K2G processor to determine which timer corresponds to each Timer ID?

  • The team is notified. They will post their feedback directly here.

    BR
    Tsvetolin Shulev
  • Any update?
    The same settings in .cfg and .c files for K2G DSP generates the correct clock period but not ARM. Both DSP and ARM cores uses timerId 0 for Clock modules. They might not use the same Timer depending on the Timer mapping to Timer ID for each core.
  • Here is some code that we have used in the past to genrate a 10 ms clock tick :

    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    BIOS.cpuFreq.hi = 0;
    BIOS.cpuFreq.lo = 600000000; /* 600 MHz */
    
    /***********************************************
    * CLOCK Module Configuraion *
    ***********************************************/
    var Clock = xdc.useModule("ti.sysbios.knl.Clock");
    Clock.tickMode = Clock.TickMode_PERIODIC;
    Clock.tickSource = Clock.TickSource_USER;
    
    /***********************************************
    * Timer Module Configuraion *
    ***********************************************/
    /* Set to 1-ms Tick */
    var Timer = xdc.useModule('ti.sysbios.timers.timer64.Timer');
    var timerParams = new Timer.Params();
    timerParams.period = 1000 * 10;
    /* Timer ID = 1 for Timer1 and input clock runs at 24 MHz */
    Timer.intFreqs[1].hi = 0;
    Timer.intFreqs[1].lo = 24000000;
    Timer.create(1, '&mainTimerTick', timerParams);

    The timer mapping table is available here:

    bios_6_52_00_12/packages/ti/sysbios/timers/timer64/doc-files/TimerTables.html

    Hope this helps.

    Regards,

    Rahul

  • I copied your code into my .cfg. Only changed Timer.intFreqs[1].lo = 25000000 to match input clock;

    The mainTimerTick in c code toggles GPIO and observed on scope. It occurs 2.5ms instead of 10ms. Why is there a discrepancy by factor of 4?

  • Joshua,

    I accidentally provided the settings from AM57xx devices where the input to the timer is the CLK IN. On Keystone 2 device the input is CHIP_CLK1/6 which seems to be 100000000 and not 25000000. I beleive this should fix your issue.

    I also looked at the config file for the MCASP Audio loopback example  where the timer is configured as shown below:

    // Change Timer frequency
    // Set Timer64 freq to 100MHz
    var Timer = xdc.useModule('ti.sysbios.timers.timer64.Timer');
    for (var idx = 0; idx < 7; idx++) {
    Timer.intFreqs[idx].lo = 100000000;
    Timer.intFreqs[idx].hi = 0;
    }

    Regards,

    Rahul

  • Rahul,

    You recommend timer setting "Timer.intFreqs[idx].lo = 100000000;" is correct. I got the desired 10ms period.
    From the CCS -> ROV -> Timer and
    CCS - > debug perspective -> Registers -> Timer_1 -> Timer_TCR
    I can see Timer1 (ti.sysbios.timers.timer64) is used.

    But my original question is for Clock module instead of Timer module.
    The Clock module for K2G ARM uses "ti.sysbios.family.arm.systimer" based on CCS -> ROV -> Timer. I would like to know how to setup accurate clock tick with Clock module.

    Thanks.

  • It appears I had missing settings.
    I added the following settings and got the accurate Clock ticks. Thanks.
    In .cfg
    Timer.timerSettings[1].ownerCoreId = 0;

    In my .c code
    void mainTimerTick(UArg arg)
    {
    Clock_tick();
    ...
    }