2

I am trying to print out seconds and milliseconds resolution timing and i am using GetSystemTime().

This is my code:

GetSystemTime(&datetime);
RETAILMSG(1,(_T("Time After Data Sent to USB: %d:%d\r\n"), datetime.wSecond, datetime.wMilliseconds));  

I print to the platform builder debug output using RETAILMSG(), but i am only able to print up to seconds resolution, so i will see something like 48:0 where the milliseconds is blank.

I am not sure why this is happening as i receive no complaints. I figure it has something to do with the implementation of RETAILMSG().

Is there a fix for this or a substitute that i can use to achieve milliseconds resolution?

Thanks,

EDIT: I am developing in Windows Embedded Compact 7

Javia1492
  • 862
  • 11
  • 28
  • Seems odd that it would be blank and not zero. Suggests a problem with the printf-like function you're using rather than the milliseconds field as such. – Jonathan Potter Aug 11 '15 at 20:15
  • @JonathanPotter I typo'd. It is actually zero. I fixed it in my post. – Javia1492 Aug 11 '15 at 20:22
  • Does std::chrono::high_resolution_clock do any better on WEC7? – Robinson Aug 11 '15 at 20:30
  • You can use [`CUsAccurateTime::GetTime`](http://alax.info/trac/public/browser/trunk/Common/alax.info/roatlcom.h?rev=482#L3478) to get 64-bit integer compatible with `FILETIME` (you can convert it to `SYSTEMTIME` using standard API). The class combines live clock time alignment with `QueryPerformanceCounter` accuracy for intervals, and gets high accuracy estimations. You can find similar implementations on StackOverflow as well. This is similar to [`GetSystemTimePreciseAsFileTime`](https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895%28v=vs.85%29.aspx) API introduced with Win 8. – Roman R. Aug 11 '15 at 21:19

2 Answers2

5

the milliseconds is blank.

I am not sure why this is happening

The Embedded Compact documentation for GetSystemTime() states the following warning about that issue:

Millisecond granularity may not be supported by a hardware platform. The caller of this function should not rely on more than second granularity.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
2

Under windows, the clock resolution is around 15ms.

If you need millisecond resolution, there is a high performance clock that enables you to measure timebelow 10µs range (see here: Acquiring high-resolution time stamps on msdn).

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • 1
    Unfortunately, the link you provided does not show that QPC is supported in Windows Embedded Compact 7, so i do not think i have that api available. I edited my post to specify the platform. – Javia1492 Aug 11 '15 at 20:15
  • I don't know the Embedded Compact environment, but this [link](https://msdn.microsoft.com/en-us/library/ee488415%28v=winembedded.70%29.aspx) suggest that `QueryPerformanceCounter` should be available. (P.S: It might interest you also: The first link in the answer shows a microsoft document explaining that in embedded environments, a system clock below 15 ms would significantly impact energy consumption) – Christophe Aug 11 '15 at 20:31
  • 1
    Ah, the second link was very helpful. I will try this out and see if it works. Thanks! – Javia1492 Aug 11 '15 at 20:59