LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

API calculating time lapsed or recording clock ticks

Solved!
Go to solution

Is there an API available in LabWindows to memorise clock ticks or calculate time lapsed?

 

 

It is needed for use with a do while loop. I want to perform an action repeatedly for 260milliseconds in a while loop and then come out of the while loop once the 260 milliseconds is up. 

 

What is the best way to go about this?

0 Kudos
Message 1 of 3
(3,337 Views)
Solution
Accepted by topic author J001

Depending on the precision you expect from timing, you may go from the simplest Timer () solution to more complex SDI APIs calls.

 

The simplest solution (nedds anything but CVI):

 

double  tini;

 

tini = Timer ();

while (Timer () - tini < 0.26) {

   doSometing ();

}

 

Advanced solution are the use of QueryPerformanceCounter ()  and QueryPerformanceFrequency () SDK functions. Here you can find an interesting discussion about them.This solution implies the use of the Windows SDK available in CVI full versions.

This code should work fine:

 

#include <windows.h>
 

void yourFunction (LARGE_INTEGER t) {

    BOOLEAN    error;
    LARGE_INTEGER tini, tn, delta;

    error = QueryPerformanceCounter (&tini);
    if (!error) {
        // Hardware error to handle someway

        return;

    }
    do {
        error = QueryPerformanceCounter (&tn);
        delta.QuadPart = tn.QuadPart - told.QuadPart;
        if (delta.LowPart >= t.LowPart)
            break;

 

        doSomething ();

 

    } while (1);

    return;
}

Message Edited by Roberto Bozzolo on 10-22-2009 09:13 AM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,332 Views)

additionnally, if you are comfotable with asynchronous execution, you can use the asynchronous timer instrument provided with CVI (look for NewAsyncTimer() in the CVI documentation), or you can use the almost equivalent Windows SDK function CreateWaitableTimer().

 

i would recommend the use of an asynchronous API, because it does not lock the program flow in one single function, so the resulting software is more flexible if you need to add another feature later.

0 Kudos
Message 3 of 3
(3,328 Views)