Current Position:Home > Wait time within a While Loop

Wait time within a While Loop

Update:11-30Source: network consolidation
Advertisement
I was always under the impression that Wait Timers (e.g. Wait and Wait Ms Multiple) always executed last within a while loop. As I'm reading up on timing of real-time loops I'm finding that NI suggested using a stacked sequence structure to force timing to run last. Has my assumption of wait timer execution been wrong all this time or do PC and RT systems differ in how loops handle timing?
Thanks,
Craig

The Best Answer

Advertisement
So, ok, coming back on this.
Attached you find a small example to show my remarks in the previous post.
How to use it:
The main focus is in the first iterations once "Wait now!" is pressed. So it is usually not of interest to run the "waiting" for more than 5-10 iterations.
In order to see an "understandable" behavior, i suggest to wait at least 100ms. I configured "Time To Wait" to be at least 10 (coercing).
The second focus is "Time Value".
For "Wait (ms)", the "Time Value" will have any number, but increase each iteration by the amount of "Time To Wait".
For "Wait Until Next Multiple (ms)", "Time Value" will be initialized to a value, which is a integer multiple of the "Time To Wait" and will increase each iteration to the next multiple.
My example does not contain parallel code, so it does not show the parallelism of the waiting functions!
Nevertheless, understanding the shown behavior is the key. Because if the code running in parallel to the waiting requires less execution time than the wait function will wait, the behavior will be exactly as shown.
If the parallel code requires more execution time than the waiting, "Wait (ms)" is already finished and therefore the loop will immediatly continue with the next iteration (high CPU load!).
If the parallel code requires more execution time than the waiting, "Wait Until Nexty Multiple (ms)" will wait that long that the "Time Value" is again in line to an integer multiple of the "Time To Wait" (so this one keeps on running in parallel until waiting time is calculated and over). Hence, "Wait Until Next Multiple" will still introduce a waiting time (reduced CPU load), but you will "miss complete iteration slots".
As you can see, using a single "Wait Until Next Multiple" outside the loop for initialization can make sense if the first iteration should also have a "close to normal" execution time.
Please note that the Timed Loop does something similar once started. As it does it during the iterations, the first 1-3 iteration(s) are called "warmup iterations". Most often, the first single iteration is sufficient for this though....
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Attachments:
TimingVI_Behavior_2011.vi ‏29 KB
  • A problem with Threads and loops. Update:10-11

    Hi, I have some code that needs to be constantly running, like while(true)       //code here }However, the code just checks to see if the user has input anything (and then if the user has, it goes to do some other stuff) so I don't need it constantly

  • Previewing loops Update:10-11

    Have had no luck with PCs trying to do music recoding so I swithced over to Mac because I heard it so easy, seamless, and problem free. Now, on opening Garageband for the first time and trying to preview loops I get an error mesage that says: "the so

  • Adobe Cloud membership - I am stuck in the loop of Licensing VERY Frustrating!!! Update:10-11

    I have an Adobe Cloud membership - I am stuck in the loop of Licensing as well VERY Frustrating - I have a project due and have been troubleshooting for days - Un Installing - Re installing - NIGHTMARE  - Please someone help me!!! Thanks in advance -

  • Lock ups and sound looping! Update:10-11

    I remember reading something here about people having trouble with their systems locking up and then getting a loud static noise then a sound loop when playing games.    I am getting this about 2-3 times a night now and it is driving me nuts, I do no

  • Help with if statement in cursor and for loop to get output Update:10-11

    I have the following cursor and and want to use if else statement to get the output. The cursor is working fine. What i need help with is how to use and if else statement to only get the folderrsn that have not been updated in the last 30 days. If yo

  • Sy-tabix in loop : Doubt Update:10-11

    LOOP AT i_lfa1 INTO wa_lfa1 WHERE werks = space.           wf_tabix = sy-tabix.                                     APPEND wa_lfa1 TO i_lfa1_werks.                          DELETE i_lfa1 index wf_tabix.                         ENDLOOP.               

  • Sy-tabix in relation to LOOP AT and READ TABLE Update:10-11

    Hi All, As per SAP documentation, 1) While looping through an internal table (LOOP AT), sy-tabix contains the index number of current row(for standard and sorted tables) 2)When successfully reading from an internal table(READ TABLE), sy-tabix is set

  • SY-TABIX value of a loop in other loop in other loop. Update:10-11

    Hello Gurus, I have a problem i want to modify some columns in final internal table and it is possible by using Transporting and Index but when i see SY-TABIX value it is not really giving particular loop iteration value. Because my present loop is i

  • Sy-index / sy-tabix wrong within loop Update:10-11

    Hi friends, i do a loop over a a table and am writing out the field contents like this: LOOP AT <dyn_table> INTO <dyn_wa>.         do.       assign component sy-index          of structure <dyn_wa> to <dyn_field>.         if sy-sub

  • Loops "missing" but still in library Update:10-11

    Upon update, many loops went 'Missing" although they are in the loop library still. Have tried several attempts to re-index loops to no avail. For instance, "Live Edgy Drums 07" remains, but "Live Edgy Drums 29.2" does not and has