File Exchange

image thumbnail

High Accuracy Timer

version 1.2.0.0 (2.13 KB) by Ivo Houtzager
High-resolution performance counter

11 Downloads

Updated 11 Jul 2015

View Version History

View License

Uses the high-resolution performance counter to get the time which exceeds one microsecond accuracy.
time = hat;
% do some calculations
diff = hat - time;

Cite As

Ivo Houtzager (2021). High Accuracy Timer (https://www.mathworks.com/matlabcentral/fileexchange/16534-high-accuracy-timer), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (18)

Adil Sbai

Nice function.

Andy Zelenak

Matt Tourtelot

DZ

It gives the "Output argument "time" (and maybe others) not assigned during call to "hat"." error on my end. What do I need to do in order to make it work?

Ahmed Zidan

Alia Gh

Faezeh Shafiei

Abdullah Al-Azzawi

How can I use this mex file to make in interrupt timer please ? something similar to timer() class
I'm trying to read my sensor measurement at a constant rate of 2000 sps with high microsecond accuracy as much as possible

the timer() class has an error of about 10 milliseconds, this is so huge comparing to 2000 sps

Thanks

Muhammad Kalili

Samy Amin

The m file has no body!!
the function is not working cuz there is no assignment for time as there is no body.

Francis Bolduc

Thank you very much.

Your code was very helpful in the creation of my own high-accuracy real-time S-Function rate limiter.

Cheers!

Yuelong

I'm working on video recording, but with pause(n) I can hardly get right frame rate. This really helps me out!

Maya

hey, this timer really helped me out, so, since inline syntax is kind of being done away with, could you provide another syntax for compiling the C file? tnx!

Holger Amort

I think the counter has to be calibrated, although the difference is usually very small.

Quentin

Quentin

I need help getting this code to work. I have Visual Basic 2008 Express Edition installed on my PC but I'm not sure how I initiate all of this with matlab.

Thanks for any help.

M Fridman

It appears that the timer call has significant overhead itself, so realize that by using it you may add to your execution time and skew some measurements.

Haiwei Qiu

nice C program. Solved Matlab unaccurate timing problems.

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Simulink Block for Real Time Execution

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!