Recent

Author Topic: Precise Timer  (Read 5007 times)

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Precise Timer
« on: September 01, 2014, 12:07:28 am »
Okay, how to achieve really precise timing via Timer? I read that function GetTickTimer is also innacurate (+/- 15ms i think). So what can i do to have code runned exactly every 100 miliseconds? And not every 109 miliseconds (when i set Timer1.Interval := 100; it returns 109). Thanks for responses.
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

Rails

  • Guest
Re: Precise Timer
« Reply #1 on: September 01, 2014, 12:11:07 am »
Give Epik Timer a look. It's in the Wiki.

http://wiki.freepascal.org/EpikTimer

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Precise Timer
« Reply #2 on: September 01, 2014, 12:17:59 am »
Okay, how to achieve really precise timing via Timer? I read that function GetTickTimer is also innacurate (+/- 15ms i think). So what can i do to have code runned exactly every 100 miliseconds? And not every 109 miliseconds (when i set Timer1.Interval := 100; it returns 109). Thanks for responses.


use a real time OS and avoid windows, linux and the rest.
Try epic timer (as Rails says) which uses the most accurate API but you will have various differences in intervals.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Rails

  • Guest
Re: Precise Timer
« Reply #3 on: September 01, 2014, 12:46:56 am »
Some Linux RT version info here.

https://rt.wiki.kernel.org/index.php/Main_Page

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Precise Timer
« Reply #4 on: September 01, 2014, 07:14:37 am »
In windows you can't use realtime timer. But maybe you can use threads for your critical operations.
And if you need a real timing operations , you have got two options ; one of is rtos, like as embedded windows ce and second is plc devices for logging etc.






Okay, how to achieve really precise timing via Timer? I read that function GetTickTimer is also innacurate (+/- 15ms i think). So what can i do to have code runned exactly every 100 miliseconds? And not every 109 miliseconds (when i set Timer1.Interval := 100; it returns 109). Thanks for responses.

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: Precise Timer
« Reply #5 on: September 01, 2014, 08:29:05 am »
If some jitter is acceptable one can use MSEgui "ttimer". The "interval" value is in microseconds and the moment of next trigger is recalculated at every expire in order to produce the correct frequency.
On Linux with low load the precision of the individual triggers normally is better than a millisecond.
On Windows one can call "application.beginhighrestimer()", then the MSEgui timing system will use the multimedia timer with 1 millisecond granularity instead of the normal Windows system tick.

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Re: Precise Timer
« Reply #6 on: September 12, 2014, 11:31:41 am »
Give Epik Timer a look. It's in the Wiki.

http://wiki.freepascal.org/EpikTimer

This sounds interesting! :) Could you give me simple example of code how to change Form.Caption every 50ms?
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: Precise Timer
« Reply #7 on: September 12, 2014, 11:39:23 am »
Okay, how to achieve really precise timing via Timer? I read that function GetTickTimer is also innacurate (+/- 15ms i think). So what can i do to have code runned exactly every 100 miliseconds? And not every 109 miliseconds (when i set Timer1.Interval := 100; it returns 109). Thanks for responses.

(if you do that in the main thread that highly depends on various factors. Try to use a windows timer in a thread, it might be more precise)

 

TinyPortal © 2005-2018