From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

QueryPerformanceCounter and QueryPerformanceFrequency in CVI/Realtime

Several threads here describe the use of these two high resolution counter for sub-milliseconds timing in Windows:

http://forums.ni.com/ni/board/message?board.id=180&message.id=15320&view=by_date_ascending&page=2

Anyone has any experiences of the deterministic nature of these two functions in CVI/Realtime (8.0.1) and the PXI-8196RT controller?
I could use hardware timing using the DAQmx functions but these two seem easier to implement if they are proven deterministic. Thanks.
0 Kudos
Message 1 of 4
(4,674 Views)

I know this is old, but I thought I'd chime in with my results.  Same set of questions, I need very accurate timing to count pulses in a certain arbitrary window.

 

These pages were helpful:

 

 

Attached is my sample CVI 2015 project to simply uses the Windows method as well as the CVI Timer() function  to measure time differential before and after a "Hello, world" write.

 

If you don't want to bother with the project, here are the results:


2015-11-24 13_09_58-Microsoft Excel - timing comparison.xlsx.png

 

Color code represents minimum seconds, but shouldn't be confused with "good" or "bad".  

 

As you can see, Timer() calls got very good results.  Also note that Timer by default attempts to get 1us timing, better even that the multimedia timers, which explains its performance!

Message 2 of 4
(3,437 Views)

To be honest, I don't understand the 'take-home' message... what do you consider 'very good' results? (I can see that the minimum time changes by a factor of 10 in both cases)

0 Kudos
Message 3 of 4
(3,429 Views)

Hi ElectroLund, I want to thank you for your sample project from a couple of months ago.

 

I also wanted to mention to you and to any other interested parties out there that your post made me curious on just how fast I could run your while-loop, while writing your small buffers to a modern, high performance SSD drive, using both the "WinAPI" and the "CVI" approach (which implies that I took out some of your self-imposed delays in your sample project).

 

The SSD is a Kingston RBU-SMS100S3256GA (it is an MSATA SSD that ships as the native boot drive with the Acer Aspire V3-772G-7616 Windows 8.1 x64 laptop). It is a stock laptop, with no BIOS tricks, and it has an Intel Core i7-4712MQ, and the stock 8 GB DDR3L RAM in it.

 

My edits to your while-loop look like this (note that I opened up the precision on the time-stamp to 18 decimal places):

 

while (go == 1)
{
//----------------
// WinAPI approach
//----------------
QueryPerformanceFrequency(&clockFrequency);
QueryPerformanceCounter(&startTime);

WriteLine(fileHandle, "Now is the time for all good men to come to the aid of their country.", -1);

QueryPerformanceCounter(&endTime);

delta.QuadPart = endTime.QuadPart - startTime.QuadPart;

secondsWIN = (double)delta.QuadPart / clockFrequency.QuadPart;

 

//----------------
// CVI approach
//----------------
secondsCVI = Timer();

WriteLine(fileHandle, "Now is the time for all good men to come to the aid of their country.", -1);

secondsCVI = Timer() - secondsCVI;

//----------------
// now write results to disk
//----------------
sprintf(buffer, "%20.18f\t\t%20.18f", secondsWIN, secondsCVI);
WriteLine(fileHandle, buffer, -1);

}

 

 

The output.txt file grows quickly after only a couple of seconds, but here is a tiny snippet from it:

 

Win API CVI
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005354974570565 0.000007000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005354974570565 0.000006000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005801222451445 0.000005000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005801222451445 0.000006000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005801222451445 0.000005000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005354974570565 0.000006000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005354974570565 0.000005000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005354974570565 0.000005000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005801222451445 0.000006000000000000
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
0.000005354974570565 0.000006000000000000

 

So one take-away from this is that CVI's "Timer ()" function rounds to the nearest microsecond, but it puts you in the ballpark for when you need time slices down in that range.

 

Thanks again...!

 

JB

 

 

 

 

--
To whom it may concern: My alias is also my nickname, I've had it since I was a (very) skinny basketball-playing teen. OK, so I've got a 38 inch waist now, but my hometown friends haven't shaken that appellation for me. I trust that you will someday be OK with that alias, as I have been with that nickname.
Message 4 of 4
(3,301 Views)