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: 

Timer Control sometimes runs fast

I am using a timer control on the UI to control an event using what I think is relativly standard code(below). The interval is set to 1 second. I have used this for years without problems, but now the program is running on a new computer (Windows 7) and mostly counts down seconds as before, but occassionally something happens and it starts counting down about 1.60 times faster than real time until the program is restarted. I would greatly appreciate any suggestions on what could be happening and how to resolve this.

 

 

int CVICALLBACK timerWait (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int waitTime, waitFlag;
char ttt[4];

switch (event)
{
case EVENT_TIMER_TICK:
GetCtrlVal(panelHandle, PANEL_numWaitTime, &waitTime);
waitTime = waitTime - 1;
SetCtrlVal(panelHandle, PANEL_numWaitTime, waitTime);

if (waitTime == 0) {
SetCtrlAttribute(panelHandle, PANEL_timerWait, ATTR_ENABLED, 0);
SetCtrlVal(panelHandle, PANEL_ledWait, 0);
sprintf(ttt, "%d\0", gwaitTime);
Error_LOG(1, ER_ETC_WAIT, 4, 8, ttt);
CmtGetThreadPoolFunctionAttribute(DEFAULT_THREAD_POOL_HANDLE, RunThreadID1, ATTR_TP_FUNCTION_THREAD_HANDLE, &runThreadHandle);
ResumeThread(runThreadHandle);
}
break;
}
return 0;
}

0 Kudos
Message 1 of 2
(4,243 Views)
Use the asynchron timer. Search the example files.
0 Kudos
Message 2 of 2
(4,141 Views)