Accurate method to measure time for an opeartion

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 What is the best method to measure time for an operation......I tried using a pin and toggling it within a for loop continuosly......But even time is taken for setting the pin and resetting it.....Any other ideas......

0 Likes
5 Replies
rotec_264361
Level 2
Level 2

Hi,

   

accuracy and resolution might struggling with each other here. I can recommend a reproducable method.

   

Use a timer with the maximum possible input frequency (max resolution). Reset the timer to zero before the operation starts. The first instruction of your operation is starting the timer. The first instruction after the operation is stoppong the timer. Now you read out the timer and display the value through a serial channel, on a LCD display, in the debugger, which ever method you'd like to use.

   

hth

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You may even count the calls of your function and add all the timer-values so you might calculate an average.

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

When you want to do some accurate measurement. you need to make multiple calls to the code in question. Otherwise the delays and the overhead of the time measurement code will lead to wrong results.

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Some usefull references, attached -

   

 

   

Regards, Dana

0 Likes
Anonymous
Not applicable

 Toggling pins is a good idea, if you run the code within the for loop......for any accurate measurement to be done please go to the "generated code " folder where the project is placed and in this folder look for "main.lst "file. Open this file and you can see how each line of code is being made of asembly instructions......Calculate the total cycles taken and multiply with the 1/Bus frequency this will be accurate way of measurement

0 Likes