LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with Timer Control and Timer() Function using CVI 2009 on win XP system

I developed a basic UI that updates values every second, based on a timer control placed on UI panel. The program works just great on windows 7 system, but the timer triggers eracticly when I run on Win XP system. I installed /  compiled on the XP system - no help.

 

I ran an experiment whereby a simple program (no Timer control or callbacks) calls the Timer() function and updates a panel indicator. I found the Timer() function works as described - UNLESS I call the function too frequently. If I call it too frequently (more than 10-20 times / second, the values returned from the function do not even closely resemble "seconds"... I verified similair results without the UI updates, but using several variable watches.

 

I assume I have some Windows timer software conflict / or that there is a bug in CVI 2009 with XP. Is anyone else having problems like this?

 

 for(x=0;x<1000000;x++)
 {
  SetCtrlVal (panelHandle,PANEL_NUMERIC , Timer());
  for(y=0;y<2000000;y++)
  {
   y++;
  }
 }

 

 

 

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

Hi mcbeer,

 

I have just tried your code snippet on CVI2009 and XP (64) and it works as expected: time is increasing regularly...

 

so I may guess only: from the help:

 

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,973 Views)

Well - I rebooted the PC, and behavior is more normal. I also un-installed agilent run-ime and libraries... not sure if the reboot or un-install did the trick. Thanks for the reply.

 

regarding the registry entry to use 55ms (or is it 10ms) timer - that entry is not currently in my registry, so I don't know where to define it...

 

Thanks for the test and reply! If I learn more about the problem (or where to define the registry value), I'll post it...

 

 

 

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

You can also use the performance counters in a Pentium micro if you're using one.  I wrote the function below that works like Timer (). 

 

If you compile this with CVI native compiler, it needs to be a somewhat recent version as the CVI compiler had a problem with long long & static storage class in an expression at some point, NI fixed it.

 

/*******************************************************************************************************************

*
* Function: PerformanceMonitorTime
*
* Description:
*    Returns a double with the time, in seconds, since last called. 
*
* Limitations:
*     N/A
*
* Parameters:
*           
*  
*
* Return Value:
*     Returns a double with the time, in seconds, since last called.
*
*
********************************************************************************************************************/  

DOUBLE PerformanceMonitorTime (VOID) {
   
    //  Returns a double with the time, in seconds, since last called. 
   
   
    //  It's not clear how this routine behaves on a multi-core (hyper-threaded or multi processor) system.   Is the performance counter
    //  a global counter (available to all threads) or is it thread specific or is it core specific?  Win32 SDK claims it does not matter
    //  which processor the call is made on - this sounds like the counters must be thread specific.
   
    static BOOL         Initialized = FALSE;
    DOUBLE              dTime;
    LARGE_INTEGER       liPerformanceCounterStart;
    LARGE_INTEGER       liPerformanceCounter;
    LARGE_INTEGER       liPerformanceFreq;
    long long           llPerformanceCounter;
    static long long    llPerformanceCounterStart; 
    static long long    llPerformanceCounterFrequency;
   
    if (!Initialized) {      
        QueryPerformanceFrequency (&liPerformanceFreq);
        llPerformanceCounterFrequency = liPerformanceFreq.QuadPart;   
        QueryPerformanceCounter (&liPerformanceCounterStart);                
        llPerformanceCounterStart = liPerformanceCounterStart.QuadPart; 
        Initialized = TRUE;
        dTime = 0.0;                                                                                                                        
    }
    else {

        QueryPerformanceCounter (&liPerformanceCounter);
        llPerformanceCounter = liPerformanceCounter.QuadPart;   
        dTime = (DOUBLE)(((DOUBLE)(llPerformanceCounter-llPerformanceCounterStart))/(DOUBLE)llPerformanceCounterFrequency);
        llPerformanceCounterStart = llPerformanceCounter;                                                                                                                                                                                                                          
    }
                                                                                                                                       
    return dTime;                                                                                                                                                                                                                    
}     // end, PerformanceMonitorTime
    

Message Edited by menchar on 02-24-2010 05:28 PM
Message Edited by menchar on 02-24-2010 05:29 PM
Message 4 of 4
(3,936 Views)