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/MSP430G2452: Time measurement

Part Number: MSP430G2452

Tool/software: Code Composer Studio

Hi,

I'd like to measure time taken to perform some function. Function clock() from "tiime.h" makes program doesn't fill in microcontroller memory. Are the any other methods? I've found some methods to measure time in Code Composer Studio but that's not what I mean. I'd like results of measurements to be displayed later on.

Best regards,

toann

  • Hi toann,

    an alternate way of measuring the time it takes to performa a function would be using a timer.
    You would configure your timer, start it before performing the functions you want to measure, then stop the timer and store the timer counts. After that you can do the math to get to the time by multiplying the timer counts, 1/(clock frequency) and clock prescaler. Keep in mind that the number of clock cycles you can count with your timer is limited to 2^16-1 = 65535 as it's a 16 Bit timer.

    Let me know if this solution works for you and click "Verify ansmwer" to close this thread. Please feel free to ask additional questions as well.

    Best regards,
    Britta
  • " I'd like results of measurements to be displayed later on."

    easy. start a timer, and keep it free running. and you time-stamp your activities using that timer.

    an example is here: github.com/.../MSP430G_F2

    pay attention to the systick.c/h files: they utilize a timer (TA0 in this particular example) to provide a time stamp. you can easily change out the timer based on your application.
  • Hi,
    I've looked into systick.c/h and the other files you send. Is this correct if I start counter by calling systick_init() before my function calling and then calling systicks() after it's done?
    I've done that and then I've multiplied results using equation Britta proposed and I've received results like: 0.01095, 0.00096, 0.00157, aren't those numbers too little?
  • you call systick_init() first and only once. and then call systicks() to time stamp activities.

    for example, if you want to measure how long it takes to run func1():

    t0=systicks(); //start the time stamp
    func1(); //do something
    t0 = systicks() - t0; //calculate time elapsed

    systicks() is your timestamp. so you can simply use it as is for your particular application.

    two points:
    1) you will need to enable interrupts;
    2) the timer counter may overflow. we are using 32-bit timers here. so pick your prescaler (in systick_init()) accordingly.
  • Hi,

    as we didn't hear from you anymore, I suppose the several posts and suggestions in this therad helped you moving forward on measuring the function execution time. I will close this thread but please go ahead and re-open it by posting new replies in case you have further questions on this topic.
    Also, please click "Verify answer" for the solution(s) which helped you moving forward with your application.

    Thanks and best regards,
    Britta
  • Is this possible to achieve bigger prescaller than 8x? I tried to add TMRA_PS16x analogously to TMRA_PS1/2/4/8x but it didn't work. I'm using 16MHz clock and I need to be able to make measurements up to 200ms. When I use 8x prescaller, I'm getting overflow.
  • Hi toann,
    the Timer_A only allows prescaler (input divider) values of 1,2,4 and 8 (See the User's Guide, Section 12.3.1: Timer_A Control Register).
    If you need your timer to run with a lower frequency you can also reduce the clock frequency by setting the according clock divider in the Basic Clock Module+ (i.e. if you use the SMCLK for Timer_A it allows divider values 1,2,4 and 8). Please note that this affects all modules which use the same clock as Timer_A . You'll find the register settings in the User's Guide, Section 5.3 and subsections).

    Does this help you?

    Best regards,
    Britta
  • The timer supports only up to 8x in Prescaler.

    The counter is 32bit so it overflows in 2^32. Even at 1x Prescaler, it will overflows over a period much greater than 200ms.

**Attention** This is a public forum