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.

LAUNCHXL-TMS57004: Measure the time duration between the events

Part Number: LAUNCHXL-TMS57004

Dear All,

I want to measure the time duration between two events using TMS 57004.

I have enable the gio and rti drivers.

then in sys_maiin.c I have written the following code.

rtiInit();

rtiResetCounter(rtiCOUNTER_BLOCK0);

rtiStartCounter(rtiCOUNTER_BLOCK0);

delayms(x);

rtiStopCounter(rtiCOUNTER_BLOCK0);

uint32 t;

t=rtiGetPeriod(rtiCOMPARE0);

Even after changing x from 1000 to 500. I am getting the same value of t. 

Please help me resolving the issue.

Regards,

gunit

  • Hello Gunit,

    The return value of rtiGetPeriod(rtiCOMPARE0) is the Update compare 0 which is unchanged. This register holds a value that is added to the value in the compare 0 (RTICOMP0) register each time a compare matches. This function allows periodic interrupts to be generated without software intervention.

    Please use rtiGetCurrentTick(..) to get the value of free running counter.
  • Hi Wang,

    I have use rtiGetCurrentTick() function but since I am unable to perform timing analysis.

    When the function even if I am changing the delay value in delyms function my function after running 3 times set to value of -9985.

    Also, I have seen differences if I use counter block 0 and block 1. Why is it so?

    Please help me in resolving the issue.

    Regards,
    Gunit Singh

    Regards,
    Gunit
  • Hi Gunit,

    Both counter0 and counter1 use the same clock. If CPUC0 = CPUC1, the FRC0 should be equal to FRC1.

    Another way to measure the cycle is to use PMU (performance Monitor Unit).
  • Hi Wang,

    I am still not able to measure the time duration between two events.

    Actually I want to measure the time the code is taking to run how can I do that ? Please elaborate in detail

    Regards,
    Gunit
  • Hi Gunit,

    Try to use PMU, the functions are defined in sys_pmu.asm:

    _pmuEnableCountersGlobal_();
    _pmuResetCounters_();

    /* Start PMU counter */
    _pmuResetCounters_();
    _pmuStartCounters_(pmuCYCLE_COUNTER);

    your code....

    /* Stop PMU counter */
    _pmuStopCounters_(pmuCYCLE_COUNTER);

    /* Get CPU cycle count */
    pmuCount =_pmuGetCycleCount_();

    Where the pmuCount is the number of CPU clock cycles:

    For example, my test takes 17476 clock cycle (system clock is 180Mhz):
    int main(void)
    {
    /* USER CODE BEGIN (3) */
    unsigned int *cppiT, *cppiR;
    unsigned ind, pmuCount;

    _pmuEnableCountersGlobal_();
    _pmuResetCounters_();

    /* Start PMU counter */
    _pmuResetCounters_();
    _pmuStartCounters_(pmuCYCLE_COUNTER);

    cppiT = (unsigned int*)(0xFC520000);
    cppiR = (unsigned int*)(0xFC521000);
    for (ind=0; ind<0x100; ind++){
    *cppiT++ = 0x00000000;
    *cppiR++ = 0x00000000;
    }
    /* Stop PMU counter */
    _pmuStopCounters_(pmuCYCLE_COUNTER);
    /* Get CPU cycle count */
    pmuCount =_pmuGetCycleCount_();

    I will figure out why your RTI doesn't work well