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.

SW-EK-TM4C123GXL: Is there any millis() function in TivaWare_C_Series-2.1.4.178

Part Number: SW-EK-TM4C123GXL

Hello,

I need a function like "millis()" to get the time in ms since booted up the board.

Can you please help me on this ?

Regards,

Titus S.

  • No, there is not a millis function to measure the startup time.

    There are some problems with such kind of measurement, there are different stages as follows:

    1) a hardware time from power-on or reset button releasing, until internal circuitry starts up, internal clock signal stabilizes; this is several milliseconds and is published in the user manual.

    2) a software time: the ResetISR routine prepares an C language environment, to let the program to run. Mainly the RAM is filled up with zeros and initialized data sections are created, and initialized data is copied from flash to RAM. Also some other sections are created.

    3) another software time: the main function is started, and you configure the clock to work with PLL; until the PLL is started and stabilized, all software up to now is running from PIOSC; after that, at the exit from clock setting routine, you run your desired frequency. You may consider the startup time from the beginning up to the exit of setting clock frequency.

    From measurement point of view:

    You need to configure a timer and start it just at the beginning of ResetISR routine - and then to count up manually the time spent until timer start, which is not convenient.

    Another better solution is to use the on-chip debug register, start it up at the beginning of ResetISR, and read its value at the exit of clock setting. This can be done more easily than with a dedicated timer - the debug register just counts the number of clock cycles. An example of use of debug register can be found on this site if you search the keywords "execution time".

    You do not specify your tools - CCS or other(s) - some other tools may have a simulator, useful in such case up to the PLL setting routine, since the simulator cannot know the hardware. AFAIK the CCS does not have anymore such simulator.

  • You can use the System Tick to generate an interrupt every 1ms. In the interrupt routine increment a static unsigned long integer. Then the millis function simply returns the current value of the static unsigned long.