• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTimer: serious drift in Time (in milliseconds)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer: serious drift in Time (in milliseconds)


  • Subject: Re: NSTimer: serious drift in Time (in milliseconds)
  • From: Andreas Tell <email@hidden>
  • Date: Sat, 11 Nov 2006 00:03:44 +0100

Hi Gilles,

what you like to achieve is absolutely possible using the timer. You just have to resync it to the realtime clock during each call to the event handler. This won't remove the jitter, but the drift will disappear. So in detail what this means is: Let your timer only fire once, and in the event handler set it up to fire again at a precalculated absolute point in time 5 seconds ahead. If you start at 10:00:30,000 you would set a new timer to go off at 10:00:35,000 from within the handler and so on. You do the accumulation of the time manually.

Cheers,


Andreas


Am 10.11.2006 um 16:43 schrieb Gilles Celli:

Hello,

My app which acquires data every 5 seconds from a Multimeter (via USB port) seems to work fine.
However I remarked that there is a drift (milliseconds) in time when using NSTimer.


The app starts at a given time say 10:00:30,000 (hh:min:sec, millisec) and after 1 hour it loses about >500 millisec, and
finishes with 10:59:59,412.


What can be done to have an exact 5 second time interval ? Is this even possible with NSTimer ?

Maybe a time check with corrections should be done...but this gets complicated
compared to our UNIX based program which acquires exactly at the given time, by using gettimeofday();


Code used:
// This will start the acquisition at 'startDate' (send timed message to self)
timer = [ [[NSTimer alloc] initWithFireDate:startDate
interval:5.0
target:self
selector:@selector (receiveData:)
userInfo:nil
repeats:YES] retain];

[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];



Any infos / suggestions greatly appreciated.

Thanks in advance,

Gilles
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40brainstream-audio.de


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Re: NSTimer: serious drift in Time (in milliseconds)
      • From: "Shawn Erickson" <email@hidden>
References: 
 >NSTimer: serious drift in Time (in milliseconds) (From: Gilles Celli <email@hidden>)

  • Prev by Date: Re: Rotation problem
  • Next by Date: Re: [moderator] Re: Authorization code fails in Leopard
  • Previous by thread: Re: NSTimer: serious drift in Time (in milliseconds)
  • Next by thread: Re: Re: NSTimer: serious drift in Time (in milliseconds)
  • Index(es):
    • Date
    • Thread