LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Timer application

Hi all

 

I have a very simple question. If i want to calculate the time required for one iteration
in a program then how can i do it? Please show it eith an example.

0 Kudos
Message 1 of 4
(3,578 Views)

How accurately do you want to measure the time?

 

CVI's Timer() function returns the time from the last time it was called.

 

Here's the CVI help on Timer()

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.

 

0 Kudos
Message 2 of 4
(3,567 Views)

Part of my post keeps getting cut off.

 

Here's a simple program that uses Timer().

 

#include <utility.h>
#include <ansi_c.h>
main()
{
 double startTime, endTime;
 int i;
 
 startTime = Timer();
 
 for (i=0; i<5; i++)
 {
  Delay (1);
  endTime = Timer();
  printf("Time in loop = %f seconds.\n", endTime - startTime);
  startTime = endTime;
 }
 printf("Press any key to continue...\n");
 GetKey();
 
}

Message 3 of 4
(3,562 Views)

No ready-to-use code, but a simple sketch and two comments:

 

First, you should not rely on one interation only but call the code many times, ~100 or 1000 repetitions should do for sufficient statistics (Windows is not a RT OS and processing time may change dramatically).

Second, put your code of interest in a timer callback and set the timer interval to zero (i.e. run as fast as possible), using SetCtrlAttribute (panel, PANEL_TIMER, ATTR_INTERVAL, 0.0 );

 

something like

 

int CVICALLBACK TimerCallback ( int panel...), 
{

   switch ( event )
    {
        case EVENT_TIMER_TICK:
// call your code of interest here
                time = *( ( double * ) eventData1 ); // current time

                interval = *( ( double * ) eventData2 ); // time elapsed since the last EVENT_TIMER_TICK callback.

Message 4 of 4
(3,551 Views)