LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a limit to the time span on an asynchronous timer in CVI 7.0?

We're using an asynchronous timer to trigger recording data. TDUMP is
defined as a double (on the UIR) with +/- infinity limits. timedump is
also a double. TDUMP is in minutes, so we multiply by 60 to get seconds.

The code looks like ...

if (LOGSTAT == 0)
{
uir_err = GetCtrlVal (page_0, LABT0_TDUMP, &timedump);
timedump = timedump * 60;
err = SetAsyncTimerAttribute (g_logTimerID, ASYNC_ATTR_INTERVAL, timedump);
err = SetAsyncTimerAttribute (g_logTimerID, ASYNC_ATTR_ENABLED, 1);
}

The code works fine for TDUMP values of 7 or less. Somewhere between 7 and
8 the timer starts firing much too quickly. At 10 minutes (600 seconds)
we're seeing triggers at around 171 seconds.

Any suggestions about what the problem is?
0 Kudos
Message 1 of 10
(5,000 Views)
Hi Groggy1,

i'm not too sure about the limit of the time span for the async timer, but i'm pretty sure it can work for at least 15 minutes (900 sec). i have tried running 10 mins and 15 mins repectively using the async timer on my application and it works fine.

i'm not too sure what's the cause of your problem maybe you could give more details.

Async timer runs in threads by the way. You only use NewAsyncTimer once in yr whole code?
g_logTimerID = NewAsyncTimer (timedump, -1, 0, Timer, NULL);


Regards
AL
0 Kudos
Message 2 of 10
(4,991 Views)
Al,

I'm working with groggy1 on this code.

Actually the code looks like:

g_logTimerID = NewAsyncTimer(timedump, count, disabled, log_data, NULL);

where count is -1, disabled is 0, and log_data is the callback routine.

Async timer runs in threads by the way. You only use NewAsyncTimer once in yr whole code?

Is that NewAsyncTimer once for this timer? Yes.
Do I start other Async timers, yes. 2 of them. Their calls look like

g_monitorTimerID = NewAsyncTimer(60.0, count, disabled, monitor_routine, NULL);
g_suspendTimerID = NewAsyncTimer(1.0, count, disabled, endSuspendRoutine, NULL);

Does this create problems? If so, how do I create multiple async timers?

The callback code does check for EVENT_TIMER_TICK before processing.
0 Kudos
Message 3 of 10
(4,981 Views)
Hi all.

Is it only the time before the _first_ callback that is wrong? If so, what is probably happening is this:

1. You disable the timer, which suspends the callbacks
2. You set the interval to a different value
3. You re-enable the timer

From the help for SuspendAsyncTimerCallbacks():

"Stops all timer callbacks until a call is made to
ResumeAsyncTimerCallbacks.

Note: This function does not alter the ongoing schedule of timer
intervals. It merely inhibits the calling of callback
functions."

The new interval will not be implemented until the next timer tick after Step 3 above.

To prevent this happening, you need to call DiscardAsyncTimer(), then when you want to resume, call NewAsyncTimer() with the new interval.

Check out this discussion for more information.

Colin.
0 Kudos
Message 4 of 10
(4,953 Views)
Hello Groggy1 and Yakker,

I was able to reproduce the issue you are describing when you set the timer interval to be > 600 seconds. I will forward this to our R&D team for investigation. On the other hand, it might be better to use the timer control instead. With such large timeouts the async timer might not buy you that much in terms of accuracy.

Regarding your second question, asynchronous timers are all run in the same thread outside the user interface thread. So if there are delays in your timer callbacks, the delay will propogate to the other timers since they are run in a common thread.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 5 of 10
(4,948 Views)
Wendy,

Thanks for letting me know I'm not nuts. OK, I am nuts, but at least this time it's the software, not me! Does this mean we get a free upgrade from 7.0 to 7.1? ;{)

My work around was to change the time to 1 second, count the calls and throw in a comparison. Looks like

if (event == EVENT_TIMER_TICK)
{
if (LOGSTAT == 1)
{
countLogData+=1.0;
if (countLogData >= timedump)
{
countLogData = 0.0;
processing goes here.

And everything works fine.
0 Kudos
Message 6 of 10
(4,940 Views)
Hi,

I have also encountered this problem with another application and it's correct for values less then 1 minute. Anything more then 60 seconds, it does not fire correctly anymore.

Any ideas why and has this problem been solved?

Regards
AL
0 Kudos
Message 7 of 10
(4,908 Views)
The CVI asynchronous timers rely on using the windows multi-media timers ( see ..\CVI\toolslib\toolbox\asynctmr.c for details) to fire the event at the appropriate time. It turns out that there is a bug in the windows timers where they wrap around every 429496 milli seconds. Basically, this means that for any interval x larger than 429496 milliseconds, a wrap occurs and the timing interval is actually x-429496 milliseconds. We have reported this to Microsoft.

Yakker's workaround is probably the best way to get around this for now. I'll make sure to have this information available in a knowledgebase.

Message Edited by bilalD on 06-16-2005 08:41 AM

Bilal Durrani
NI
0 Kudos
Message 8 of 10
(4,901 Views)

 

5 years has passed. 

Is this issue ever fixed?

0 Kudos
Message 9 of 10
(4,310 Views)

Hello - 

 

This issue does seem to be resolved in Vista and later, and with the release of CVI 2009, it was fixed for XP (ID 129094). 

 

NickB

National Instruments 

0 Kudos
Message 10 of 10
(4,280 Views)