LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can two different Timer() instances be called in one CVI project?

I want to run two different timers in the same code

1. to track the amount of time elapsed since the software was run

2. to track the duration of sub-sequences running for specified durations

 

I tried calling Timer() in two different threads; but they take the same value.

I want the Timer in thread2 to start from zero while the timer in thread two will keep running with some nonzero value.
Does this problem have any other solutoin?

 

 

0 Kudos
Message 1 of 3
(3,574 Views)

When I user TImer() I never expect it to return 0 at any time.

I allways use something like

starttime = Timer(); 

...

time =Timer() - starttime;

If you are running really parallel threads with the same code , you have to make sure that starttime is not shared  between the threads.

0 Kudos
Message 2 of 3
(3,565 Views)

Taken from the help (e.g. NI LabWindows/CVI 9.0 Help😞

 

double Timer (void);

Purpose

Returns the number of seconds elapsed since the first call to Timer, Delay, or SyncWait, or the first operation on a timer control.

The value is never reset to zero except when you restart the program.

The resolution is normally 1 microsecond. However, if you set the useDefaultTimer configuration option to True, the resolution is 55 milliseconds.

 

 

So you have to save the start time and calculate the duration yourself.

This is also the case if you intend to use some different timing method like GetTickCount, GetCurrentCVIAbsoluteTime, QueryPerformanceCounter...

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 3 of 3
(3,531 Views)