views:

481

answers:

4

Is it possible to sleep for an amount of time that will be accurate to less than 100 microseconds on Windows CE? The less jitter the better - ideally we'd like single digit microsecond response times.

What we really want is a 5ms timer with very low jitter - although the Windows CE WaitFor[Single|Multiple]Objects and Sleep APIs work in units of milliseconds, we can't then correct for the sub-ms time our code may take to run, so the cycle would gradually drift.

If this is not possible, that information would be very helpful too.

+1  A: 

It's not possible. It's not even possible on desktops. Typical operating systems simply don't function in this manner.

If what you need is something to fire precisely every 4 milliseconds or whatever you're out of luck. If what you really need is something to fire precisely 250 times every second that may be more doable. If you're in need of the latter I can suggest an approach.

Spencer Ruport
This doesn't seem correct. Standard spacing between VoIP audio packets is 20ms (u/a-law) and no desktop software has problems with handling that; or servers generating hundreds of audio streams that way. (with jitter at <1ms) Yes - "precisely" 4ms is not doable. But with a sensible jitter of up to 0.5ms it should a fairly normal setup - especially if only one such stream is needed.
viraptor
I'm not sure what VoIP audio packets have to do with precise timing. A network card doesn't poll for data coming across the wire it takes it as it comes and shoves it into a buffer until the CPU polls the data.
Spencer Ruport
+1  A: 

This MSDN article has some code to set up a 500us timer interrupt in WinCE, so it's absolutely possible.

If you aren't locked into your version of WinCE, you might want to look into Tenasys, who claims to offer an RTOS running side-by-side with Windows on standard hardware.

I've also heard good things about QNX, but I haven't used their products either. I do not believe it is Windows compatible in any way, however.

Mark Rushakoff
We're not really locked into any specific OS as long as we can interface with a certain vendor library in a non-real-time fashion (which has a CE version, and a regular-windows version which works on wine). Licensing costs are a concern, though, so putting a third-party RTOS on top of Windows licensing costs is undesirable. Is there anything easier than hacking the timer interrupt like that, or is that the best we'll get?
bdonlan
That link was just the result of some cursory Googling. I'm not familiar enough with Windows CE to give you a confident answer on the difficulty of setting up high-resolution timers in any other fashion.
Mark Rushakoff
A: 

To correct the jitter you need access to a high resolution timer. The CPU you have may have one. If not, the interrupt controller may.

The Easiest way is to use a Linux with realtime and WINE your way into that library. you want a Periodic Thread.

Take a look at this report from NIST.

Tim Williscroft
+1  A: 

If your need to sleep is not a battery/thread-yield issue and just a matter of accurate timing, you can use the "performancecounter" in Windows CE devices. On XScale and Qualcomm CPUs, this is the internal chip timer and has sub 1-ms granularity. On older OMAP and Samsung processors, the performancecounter API is passing through the 1ms system tick and has lots of jitter.

L.B.

BitBank