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.

Using timers to determine when function was last called

Other Parts Discussed in Thread: TM4C129DNCPDT, TM4C1294NCPDT

Hi, I've never used timers before so I have a few questions regarding them. I'm working with the TM4C1294XL launchpad.

My problem is to keep track of when a function was last called, and I was planning to use a timer to clock the current time into a global variable, transfer it to a prev_time variable after done using it, and then clock the current time again during the next call of this function and finds out how long it's been since it was last called. Would using the RTC mode be the right thing to do in this situation? Also, does putting the launchpad into hibernate mode still allows the RTC clock to keep running?

Sorry for the newbie question. And thanks in advance for any help I can get.

  • Hello Thomas

    I would suggest Trace via ETM and/or Instrumentation via ITM as a better tool than using timers....
  • Hi Amit,

    Is it more complex to use ETM vs timers? I tried looking inside the TM4C129DNCPDT microcontroller datasheet, but didn't see any instructions on how to use ETM, or the ETM pins that I've seen some other posts mentioned. Would be great if you could help point me towards some examples or description of what it is and how to use it.

    Thomas
  • The ETM (embedded trace macrocell) is Cortex M, i.e. ARM, and not TI specific. Check infocenter.arm.com, or try searching for generic ETM examples.

  • Thomas Phan said:
    My problem is to keep track of when a function was last called

    Can you provide more context about the problem, to help suggest a suitable solution:

    1) Do you only need to keep track of the time of the function call when the debugger is attached, or is keeping track of the time required when the device is running without the debugger attached?

    The previous suggestion to use Trace via ETM and/or Instrumentation via ITM would require a debugger to collect the information. Also, the Stellaris In-Circuit Debug Interface doesn't support Trace via ETM so a different debug probe would be required.

    2) For the timestamps what resolution do you require, and what is the maximum time duration you need to measure?

    3) Do you require the timer to be kept running when the device is placed into hibernate mode?

    4) If the program is halted in the debugger, is it important if the time measurement is stalled or kept running?

  • HI Chester,

    1) I do need to keep track of the time as if there is no debugger attached, so when the device is running and powered using OTG.

    2) I'm not sure where to find the info regarding the resolution of the timestamps, but I know that the RTC timer on the TM4C1294XL launchpad is using the 32.675 kHz oscillator. Was this what you were asking for? The maximum time duration I need is about 60 seconds, but this is just a very rough guesstimate and will most likely change later. Probably shorter instead of longer.

    3) I do need the timer to keep running when the device is in hibernate mode.

    4) Since I'm not looking to keep track of the time using the debugger, I would say to halt it along with the program.

    Thomas
  • Thomas Phan said:
    1) I do need to keep track of the time as if there is no debugger attached, so when the device is running and powered using OTG.

    Thanks for clarifying.

    Thomas Phan said:
    2) I'm not sure where to find the info regarding the resolution of the timestamps

    That was a question what timestamp accuracy was sufficient for your application. There is a trade-off between the timestamp accuracy vs. the maximum duration that a hardware timer can measure without having to extend the time duration by the software keeping track of the number of timer overflows.

    The General-Purpose Timers allow different clock sources, where the highest resolution is for a timer to increment at every CPU clock.

    Whereas the RTC in the hibernation module is fixed at using a fixed 32768 Hz clock.

    Thomas Phan said:
    3) I do need the timer to keep running when the device is in hibernate mode.

    In that case, I think the only available timer is the Real Time Clock (RTC) in the hibernation module. The resolution of the RTC sub-second timestamp is 1/32768 of a second or 30.5 microseconds.

    Thomas Phan said:
    4) Since I'm not looking to keep track of the time using the debugger, I would say to halt it along with the program.

    From reading the TM4C1294NCPDT datasheet, there is no hardware option to make the hibernation module RTC stall when the program is halted in the debugger.

    Whereas with the General-Purpose Timers there is an option to make the timers stall when the program is halted in the debugger.

    Therefore, you have to a make trade-off between the different options.

  • Thank you for the informative answer Chester. I will do some testing with the RTC and GP timers and come back to verify your answer.

    Just one quick question on another alternative, is it possible to use the library <time.h> on embedded system?