LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

real time: timed loop vs while loop

hello all,
 
I have made a VI which needs to execute a loop every 50 ms because of closed loop stability problems (and calculation :))
 
there just this loop in my VI.
 
first I made it with a while loop and I found between 30ms and 38 ms for execution (mean at ~31.25)
 
then I replaced the while loop with a timed loop which I set for 50 ms (period).
 
the trouble is that I measure now the loop at 66 ms (in fact, it depends. in a given execution, it is always the same time from one iteration to an other but never the time I want it to be)
 
What happens? I mean with a while loop, I never exceed my time and with a timed loop, I never have the same time from one execution to the other and ever more than what I ask. Is there a problem with the LabView 7.1 timed loop?
 
many thanks
 
CHKDSK

Message Edited by CHKDSK on 01-10-2007 11:50 AM

Message Edited by CHKDSK on 01-10-2007 11:51 AM

0 Kudos
Message 1 of 8
(5,165 Views)
How "full" is the loop, i.e. does it take close to the desired loop time to execute all code in it?
 
What is your OS? Are you on e.g. windows or on a RT box? Have you placed any indicator on e.g. the "finished late" terminal inside the timed loop. What else is running on your machine?
 
Are there any other parallel loops in your code, possibly not containing any wait statement?

Message Edited by altenbach on 01-10-2007 09:59 AM

0 Kudos
Message 2 of 8
(5,153 Views)

To add to Altenbach's questions:

Can you explain what you are trying to achieve? 

0 Kudos
Message 3 of 8
(5,146 Views)
I checked the programm, there is no other loop anywhere and no delay.
 
I'm using labview 7.1 under windows XP 32bits with a mc affee anti-virus behind (not searching for viruses, just doing what it does when it is launched at starting up), this is a 2.8GHz celeron Smiley Mad with 512mB of RAM
 
I don't know what is a R.T Box.
 
I tried to improve the priority of labview in the task manager but this don't seem to change a lot of things.
 
I have a machine which I made go from 0 to 400um and from 400 to 0um, both at 400um/sec.
I hear it moving for about one second.
 
I do this 25 times to make one test and the loop checks the position to decide wether it has to give the next goal to reach or not
 
with a while loop, I get from 26 to 35 checkings, the number is varying during one test
with a timed loop, I get from 14 to 17 checkings, the number is always the same for all the 25 travels of one test.
 
I make the same test, just changing the type of loop and I don't do anything with the computer while testing.
0 Kudos
Message 4 of 8
(5,132 Views)

Hi CHKDSK,

What Altenbach is referring to with a R.T. Box is a computing device (often single board computer) that supports Real-Time Operating Systems (RTOS).   I think the confusion may have come from the title of this thread "real time: timed loop vs while loop".  Unfortunately, Windoze is not the best OS to guarantee precise timing of events, as it prefers sending messages to home base telling it what you are doing and with what SW, rather than doing it's tasks.  I did see recent postings (on some other forum) on how to set the priority of Windoze-specific tasks within the Registry.

Can you show or post the loop section of your code? 

On a side note.. Your PC should be more than adequate for the job.  May I ask what Motherboard you are using, if it is a Clone.  I also have a 2.8GHZ PC with an ASUS P4P88Del board which has given me performance issues since day-one.  It runs Win-2k.  My other PC's (2.4G, 1.8G & 3.4G) all run as expected.

Are you using "Wait Until Next ms Multiple" to adjust to deltas in time to process the loops?

 

0 Kudos
Message 5 of 8
(5,105 Views)
there you have my code, I'm affraid there are few commentaries and some of them are in french
 
so the "POS" vi sends <a, 26> on rs232 ports and reads back something like <a, sxxxxxdd> a being 1 or 2 and sxxxxxdd is an integer giving the position of my machine
 
during the test, all stop buttons are off so "hlt" and "0" are never used
 
"mode control" is logic sending number 6 to choose the case
 
the "draw" subvi is never used
 
"Script Open" reads a text file at a given line
 
"But" sends <a,24, xxxxdd> and <a,25, sxxxxxdd> on rs232 a being 1 or 2 and the others being respectively speed and position to reach
0 Kudos
Message 6 of 8
(5,077 Views)
You did not include the subVIs, so we cannot see if any of them may be causing your slow performance.

On thing which would likely help would be to separate the user interface, which certainly does not need to run at 50 ms increments, from the data acquisition part. Divide the program into (at least) two parallel loops. The first loop will be the user interface. It has all the controls and indicators and runs 5-10 times per second for indicators or less if no indicator updates have occurred. It would use an event structure to process the user inputs efficiently. The second loop does the communication with the external device and the closed loop control calculations. It has no control or indicator terminals and no property nodes or anything else which would force it to run in the UI thread. It could easily run at the desired rate if nothing in the subVIs for the external device slows it too much. The two loops would communicate via queues.

The HaltSUBVI.vi and the 0axisSUBVI.vi are called twice but without any data dependency between them. If it is important that they execute in a particular sequence, you need to do something additional to assure the desired behavior.

Building a array in a loop can lead to memory allocation problems and slow performance. It is preferred to initialize the array outside the loop and use replace array element within the loop. If you initialize with NaN (Not a Number) the points will not be lplotted on your graphs until they have been replaced with data.

Lynn
0 Kudos
Message 7 of 8
(5,067 Views)

I agree with everything Lynn said.

You are building two arrays of clusters and the only way to reset the size is a manual control. This means that an unattended program will grow without bounds and will consume all memory at one point in the future. Even stopping and restarting the program will not clear the shift registers, since they are not initialized.

I don't see anything that determines the speed of the loop.

Here's a simple wiring suggestion. If you replace only one single element in a cluster, you don't need to rewire all elements as you always do. The picture shows three different ways.

A: Your method
B: Your method simplified...
C: Using "bundle by name". This is preferred because it is self-documenting and compact.

Imagine your cluster has 50 elements. Only C would be reasonable.

Message Edited by altenbach on 01-12-2007 10:23 AM

0 Kudos
Message 8 of 8
(5,046 Views)