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.
Hi,
I want to calculate the execution time in milliseconds of a code. what I wrote needs time.h, is there another way to do it without time.h:
clock_t start, end;
start=clock();
{
end=clock();
printf("execution time in milliseconds:%f\n", (end-start)/(double)clocks_PERS_SEC);
}
thanks a lot
Hi Mir,
there is an other way: just start your timer/counter, execute code and stop it again. That's it, that's all. I give you an example for the MSP430FRAM, using Timer_B registers.
/* ********* Timer_B Init (can also be done by Grace tool) *********************** */
TB0EX0 = 0x7;
TB0CTL = CNTL_0 + TBSSEL_1 + ID_3 + MC_2 + TBIE;
/* *********** in your main ***************** */
TB0CTL &= ~(0x0030); //stop counter
TB0R = 0; //set counter 0
TB0CTL |= MC_2; //start counter
/* ************ your code to be measured **************** */
{}
TB0CTL &= ~(0x0030); //stop counter
Counter_B0_value = *(unsigned int *)0x03D0; //write counter value to variable
/* ******** end example ********* */
Do the Math:
time = Counter_B0_value * 1/(frequency) * prescaler
Be sure that you mind ALL prescaler! e.g. ACLK, Timer Input divider, TB0EX0, etc...
Hi,
You can turn on a digital output when your code start and turn it off at the end. The time can be measured with an oscilloscope.
Best regards,
AES
Well, one really shuldn't start developing on a microcontroller without a scope. That's almost as programming a PC wihtout having a screen. Almost. :)Mir Dali said:actually and don't have an oscilloscope
The problem is: teh MSP doesn't know about time. It only know clock cycles. You can count clock cycles, but you don't know how long a clock cycle is.
YOu ma yuse a quartz crystal and derive the MCU clockcycles from it, then you know how long a clock cycle is and can multiply it with the amount of clock cycles passed.
For counting clock cycles (up to 65535) you can use a timer, as suggested.
For a microcontroller, time really is relative.
Well, Saw and drill are there, but the carpenter's rule is missing.Andy Neil said:It's like taking up carpentry without a saw!
Well, I like this picture. Fits better than mine with the PC.
**Attention** This is a public forum