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.

Program Execution Time

Other Parts Discussed in Thread: MSP430F5438A

Hi,

I would like to be able to measure the execution time of my program. One idea I have is to use one of the MSP430's built-in timers to count up as the program is running and then view the value stored in the register corresponding to the timer at the end of the program. Can you please let me know which of the MSP430's timers would be best for this purpose and also give me some sample code to implement the idea? Other ideas are welcome as well.

I am working with an MSP430F5438A in IAR. Your help is greatly appreciated.

Thanks,

Nav

  • You can use any one of the Timers that you do not need to use otherwise. You probably need to extend the range of the hardware counter with software counters as the hardware counters in the Timers are only 16-bit wide.

    Another way is to log the beginning and the end with a Time-Stamp from the RTC.

  • Thanks for the reply.

    I still don't quite understand how the processor can be in a loop running a timer / RTC and also execute another program. Can you please show me how to implement the timer / RTC and have it run simultaneously with another program?

    Sorry for my ignorance. I have not worked with the MSP430 much before.

    Thanks,

    Nav

  • HI Ravi,

    Not sure if this is useful for you. Go through if you haven't.

    http://www.ti.com/lit/ml/slap113/slap113.pdf

    Regards

    Radhesh

  • The timer/RTC is a peripheral; this means that by writing to certain memory mapped registers (showing up as pre-existing variables, eg: TACTL) you can influence the behaviour of the timer.

    By setting the timer to run at SMCLK/1 = MCLK (read: sub-master clock, divider set to 1, master clock equal to sub-master clock) the timer will increment it's counter by 1 every processor cycle. When clearing the timer counter (TAR) at the start of your program block results in the timer containing the number of used processos cycles at the end of the program block.

    Bear in mind these two things: first, you will be off by a few cycles because clearing and reading the timer counter register takes a few cycles of itself (about 6). Second, the timer counter register (as most other peripheral registers) is a 16-bit value, so if your program takes more than 2^16 -1 = 65,535 cycles, the timer will wrap around. This means that strictly your program block took TAR + N * 65536 cycles, where N is a whole number (may be 0).

    You can count the before mentioned N by incrementing a software counter with each wrap around of the timer, but then again you should compensate for the cycles it took to increment this counter (about 20 to 30 cycles per increment).

    To see how you must exactly set your timer registers, refer to the family guide related to your specific MSP430 microcontroller.

**Attention** This is a public forum