LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple timer

Hi,

I am trying to implement a few timers on a common user interface. All of them are to be running at the same time but with different timing callback intervals (eg 1s, 5s, 8s) and with different function callback. I wonder if this will work properly as for example at time 5s after the start, assuming two timers are scheduled to perform its own task... what will happen? one task after another or just one task and other is skipped as both are running on the same thread.

Do i need to create asynchronous timers instead? anyone has any gd examples in creating and running concurrent multiple timers?

thanks
0 Kudos
Message 1 of 3
(3,242 Views)
I would either use asynchronous timers or one timer that looks for multiples for the higher time increments. One of these two options would give you better performance. In the second case for example (with 1s, 5s, and 8s intervals) you timer callback would have an interval of 1 second and have code like:

int CVICALLBACK TimerCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_TIMER_TICK:
//Insert code to do every second
countToFive++;
countToEight++;
if(countToFive >= 5)
{
//Insert code to do every 5 seconds
countToFive = 0;
}

if(countToEight >= 😎
{
//Insert code to do every 8 seconds
countToEight = 0;
}
break;
}
return 0;
}

where countToFive and countToEigth are static int globals initialized to 0.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 3
(3,242 Views)
Hey Chris,

I have question regarding similar topic on Timers.
I have two timers one with interval of 1 ms and ohter with 1 sec now i used the same logic as u have explained but my problem is i want to run both the codes in parallel mode but the program gets stuck in one of the loops until the function is complete and then comes out of it ...and i am loosing the other function in between......i tried seperate timers also but in that case the 1 second timer callback doesn't get triggered if i stop the timer in between and start again.....is there anyway i can come over this....I am just Disabling the timer which stops my callback function...but again enabling the 1second timer doesn't start the callback function....though the 1 ms callback work perfectly fin
e
0 Kudos
Message 3 of 3
(3,242 Views)