LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can Two Timers run in Paraller in LabWindows

Hello There

I want to run two timers in parallel mode for two different process. One process is data acquisition which i want to do as fast as i can to read the data and plot it on stripchart.
The other process is a cyclic loop which takes time as per user inputs varying from like 100 to 500 seconds now when i run the program and use command button to start the Timer callbacks it works perfect.

I am doing automation of this system in which i have written some Macros which control the system. In these Macros I have to set the system to idle condition ie stop everything at the start and at the end of each Macro. Now as i disable the Timer for this it stops both the Timers and stop the callback function too.
Now when i enable the timer again...the faster timer gets enabled and starts acquiring data with specified conditions and plots it on stripchart.
But the other Timer gets enabled but doesn't trigger the functions it is suppose to run.
So i removed the slower timer and put it in the faster that is data acquisition timer loop with counter so it will trigger only if the counter is greater than or equal the time needed to complete the slower timer cycle.
Now once the slower cyclic loop starts it gets stuck in the loop even though i have PROCESSSYSTEMEVENT function in it. It doesn't do the data acquisition untill the inner cyclic loop is complete...the PROCESSSYSTEMEVENT doesn't work.
CAN YOU HELP ME PLEASE.
My timer function looks something like this

THE TIMER HAS INTERVAL OF 0.1 second

int CVICALLBACK UPDATE_TIMER (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int status,k;
switch (event)
{
case EVENT_TIMER_TICK:
if(Acquisition_Flag!=0)
{
f_read_acquired_analog_in_data();
f_acquire_and_update_digital_in_data();
DISPLAYCOUNTER++;
if( DISPLAYCOUNTER >= stat_Display_frequency)
f_display_acquired_analog_in_data(),DISPLAYCOUNTER=0;
}
balancecounter++;
if( BalanceOnFlag !=0 &&
balancecounter >= cycletime
{
// THIS FUNCTION TAKES LIKE 150-500 seconds//
f_startBalance_measurements(), balancecounter=0;
}
break;
}
return 0;
}
0 Kudos
Message 1 of 4
(3,393 Views)
The GUI timers will only work one at a time cause in this mode they will execute when they get time to do so.

Just a comment, in terms of your aquisition speed I would be really concerned about processor overhead logging and displaying data at such a high rate. Dependeing on the hardware and the specifiec capabilities it might be really tough to pull of.

In terms of simultaniously processing some events and data logging I would normally rather use the asynchronous timer that runns in seperate threats.

Running your code is the way it's done now you will have to wait for 150-500 seconds for that function to finish before it will process the timers again.

If the process f_startBalance_measurements() takes so long to run it might even have an affect on a v
ery fast aquisition process running in a seperate threat.
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 2 of 4
(3,393 Views)
Hey Jattie,

Thanks for your response.
I am acquiring at very fast rate as my control depends on the acquisition rate only but i am not reading and diplaying at the same rate. It is done much slower rate like once in 1-2 seconds that way even i though i am reading at slower rate i have THE LATEST value.....which is ok i think..

And about the balance it just takes upto 500 seconds to complete its cycle....and it is not running all the time.

I am sorry i forgot to mention that i am using Windows 2000 Operating system on Dell P4 1.3 GHz with 384MB RAM and I have LabWindows/CVI 5.0 which doesn't allow me to run the mutithreading in debuging environment. And asynchronous timer works in other thresd so i am not able to develop the code and test it......thats
what what i am thinking....if i am wrong please let me know i will try to use asynchronous timer then.

I was trying different things and one thing kind of worked...i made balance time interval same as data acquisition Timer interval but i have inserted a counter which gets updated with every callback...and i am setting condition like

TIMER CALLBACK LOOKS SOMTETHING LIKE THIS

{
balance_Counter++;

if(balance_Counter >= (cycletime/timerinterval)
f_start_balancemeasurement(),balance_Counter=0;

}

and it is working ok so far.... atleast the percentage error in missing this callback is much much less than earlier when it was just missing it all the time....

is there any other way i can accomplised this.....please let me know

Aadesh
0 Kudos
Message 3 of 4
(3,393 Views)
Hi Aadesh,

Creating a mutithreaded application would definatelly the way to go. But as you say CVI 5.0 does not supports multiple threads, since Windows did not suported them back then.

You can definatelly have parallel timers, however they will execute in the same thread; if one of the timer functions takes longer, the other functions will have to wait.

For an application that requires high perfromance, I would not use a timer at all. You may want to change to a model where you have a while loop runnign all the time doing the acquisition and checking for UI events. You can have a counter going in your loop to perform some operations every X iterations of the loop.

Without multiple threads this applicatio is quite a challenge. I sugg
est you consider and upgrade to make thisng better.

I hope this helps.

Regards,

Juan Carlos
N.I.
0 Kudos
Message 4 of 4
(3,393 Views)