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.

TM4C1294NCPDT: Measure time in TIVA C

Part Number: TM4C1294NCPDT

Hello,

I have to measure time in usec:

Hello,

In the following code, how should I translate clocks to usec ?

It seems the clock is not running. After=Before. 

Thank you,

Zvi Vered

int Diff;

ui32SysClock = SysCtlClockFreqSet (SYSCTL_XTAL_25MHZ | 
                                                          SYSCTL_OSC_MAIN | 
                                                          SYSCTL_PLL | 
                                                          SYSCTL_CFG_VCO_480), 120000000);
//ui32SysClock  = 120000000;

Before = SysCtlClockGet ();
SysCtlDelay (40);
After = SysCtlClockGet ();

Diff = After - Before;

 
  •  SysCtlClockGet() returns the system clock rate (in Hz), and so won't change for successive calls. [Also, Driverlib User Guide (SPMU298E) Sec 26.2.2.3 claims it can't be used on the TM4C1294.]

    You want a counter which ticks at the system clock rate. SysTick is probably a good candidate. [Ref UG Sec 28]. This is a 24-bit down-counter.

  • Hi Bruce,

    Thank you for your reply.

    Do you mean: ROM_SysTickValueGet ?

    What is the time of one tick ?

    ROM_SysTickPeriodGet returns 1200000

    I have to count up to 15 [sec]. 

    Best regards,

    Zvi 

  • SysTick ticks at the system clock rate (120MHz in your case). Since it's only 24 bits, that gives you about 140ms before it wraps, which is fine for your original example, but not for 15 seconds. [It is possible (CLK_SRC=0) to run it at PIOSC/4=4MHz, but Driverlib doesn't seem to provide that option, and that's still only 4 seconds.]

    You probably need to use one of the General Purpose Timers in 32-bit mode. [Ref datasheet (SPMS433B) Sec 13 and Driverlib User Guide (SPMU298E) Sec 29.] Setting the Load value to 0xFFFFFFFF provides what amounts to a free-running counter. Even without pre-scaling, that will give you a span of about 35 seconds.

  • Hi Bruce,

    Thank you very much !