LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems discarding and renewing an asynchronous timer

I can start an asynchronous timer and use it once, but when I try to use another async timer problems occur. The new created timer doesn't start at zero but continues as if it was started simultaneously with the first one. It doesn't matter if I discard the old one or not - the result is always the same. The sample program ..\samples\toolbox\asyncdem.c doesn't help much as it only contains the creation of one single timer. What do I do?
0 Kudos
Message 1 of 2
(3,151 Views)
Hello Bent,
You can find the source code to the async. timer in "\toolslib\toolbox\asynctmr.c". Looking at the source, you will notice that it is a wrapper for Windows Multimedia Timer SDK functions. When the first timer is started, the Multimedia timer is reset, but starting subsequent async. timers does not reset the value of the timer. The value returned from MMTimer() is passed as "eventData1" to all timer callbacks (they share this clock value). If you wish your additional timers to start at zero, there are two major methods. The first method (recommended) would be to modify your source code to detect new timer id�s and save the timer offsets. For example, a second timer is started with an interval of 1 second 5.8 seconds after an initial timer is st
arted. At 6.8 seconds, its timer callback is called with a new timer id, 6.8 in eventData1 and 1.0 in eventData2. Since the timer id is new, we save (eventData1 - eventData2) = 5.8 into a variable called timer2_starttime. Whenever the timer callback is called with this timer id, we know that it has been running for (eventData1 - timer2_starttime) seconds. The second method would be to modify the async. timer to store the start times of each timer and pass the difference (MMTimer() - asyncTimerPtr->starttime) to eventData1. I wish you the best of luck with your program.

Jeremiah
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 2
(3,151 Views)