You are here

Accurate method to measure time for an opeartion | Cypress Semiconductor

Accurate method to measure time for an opeartion

Summary: 5 Replies, Latest post by Avagadro on 09 Sep 2012 11:41 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
user_228878049's picture
152 posts

 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......

user_66897694's picture
19 posts


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.


user_1377889's picture
9301 posts

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



user_78878863's picture
2553 posts

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.

user_14586677's picture
7646 posts

Some usefull references, attached -


Regards, Dana



Avagadro's picture
Cypress Employee
71 posts

 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

Log in to post new comments.