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.

CCS/TM4C123GH6PM: Measuring time, in milliseconds or microseconds on the TM4C

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello,

I am writing a ros_embedded program using github.com/.../rosserial_tivac

I need to measure time, in order to make a loop execute a routine each 100ms.

Usually this is done with something like:

while(1) {

    current_time = micros();

    if(current_time - last_time >= 100000) {

// execute routine

    }

}

In tiva-c there is the SysCtlClockGet() - which returns 80000000 - when the TM4C123 is running at 80Mhz.

Is there any way we can get the sysclock ticks? Basically, I would like to do a blink without delay in the TM4C.

Are there anyways to accomplish this other than the use of measuring the time / clock timers? (maybe the systick interrupt)

Either way, how do I measure time in the TM4C? Sometimes I just need to temporarily measure how long a routine takes for debugging purposes.

Best regards,

Can

  • I would configure either the ARM core's SysTick timer or one of the TM4C's peripheral timers to generate an interrupt at the desired frequency.

    Depending on what routine you wish to execute, how long it takes to execute, and what resources the routine uses, you can either execute it in the interrupt service routine (ISR), or limit code in the ISR to just set a "time to execute the routine" flag, which the main loop can check against.

    I recommend executing directly in the ISR only if:

    (1) The code to execute is short and will be finished very quickly (e.g., it does not contain any while(1) loops or delays, it does not block waiting for some external thing outside your control like communication from another device or an input, and it does not contain any or other statements that may "block" execution for an extended period of time)

    (2) There are no concurrency issues -- e.g., code in the ISR and code in main context sharing any resources -- or you have some type or another of context synchronization in place

    If the above conditions are not met, you could split the routine to two pieces: the quickly-executing "time critical" portion that executes in the interrupt, and the slowly-executing not-so-time-critical portion that executes in the main loop.

    To configure SysTick timer see the TivaWare functions: SysTickEnable(), SysTickDisable(), SysTickIntRegister(), SysTickIntUnregister(), SysTickIntEnable(), SysTickIntDisable(), SysTickPeriodSet(), SysTickPeriodGet(), SysTickValueGet(), defined in C:\ti\TivaWare_C_Series-2.1.4.178\driverlib\systick.h (if TivaWare installed to default location).

    To configure timer peripherals, see C:\ti\TivaWare_C_Series-2.1.4.178\driverlib\timer.h.