LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed loop with irregular intervals?

Hello all, 

 

I'm trying to program a vi that writes a serial output at predetermined times, but I'm not sure where to start and I don't seem to be able to find anything in the examples (but perhaps i'm not looking in the right place). 

 

All the timed structures in labview work in fixed, regular intervals (the time between each loop execution is the same).

I need to somehow trigger my output based on an array with timepoints that can vary quite a bit: the minimum interval would be a few seconds, the maximum a couple of minutes.

 

Any ideas?  

0 Kudos
Message 1 of 4
(2,478 Views)

@WorkingCat wrote:

 

All the timed structures in labview work in fixed, regular intervals (the time between each loop execution is the same).



Not from what I've seen.  With the Timed While Loop, you can set the inside node on the right hand side to have a dT input that allows you to change the loop iteration period on every iteration of the loop.

0 Kudos
Message 2 of 4
(2,464 Views)
Using a timed loop on Windows is actually kind of silly. A normal while loop will work just as well. I do not advise a regular wait or delay function to set the interval. With the Elapsed Time function, you can stop the loop early. Setting a delay of seconds ot minutes will make your VI completely unresponsive for the wait time.
0 Kudos
Message 3 of 4
(2,455 Views)

If you don't mind multiple parallel loops, you can implement a "scheduler".  It works by using something like a Queued Message Handler to execute "Commands" at specified times.  One loop is the "clock" -- use Timed Loop or a While Loop with a Wait until Next Multiple.  Each "tick",fire a Notifier with the current time (in my case, I use a millisecond counter, so I put a millesecond count in the notifier).. We'll get to what to do with the Notifier in a minute.  The Scheduler is an Action Engine, with four actions -- Initialize (save the current time, or milliseconds), "Save Action" which saves the time (in the future) you want a Command to be executed, and the name of the Command (for example, "Write to Disk" = command, "1000 msec" = when to do this, "Do Action" which looks at all the saved Actions and, if it is time to do any of them, calls the Queued Message Handler to do them (e.g. put the message "Write to Disk" on the QMH Queue).  If it does call the Message Handler, it removes the Command from the Schedule.  Finally, there is a Quit, which flushes the Schedule and exit.  Note that I also clear the Schedule when I Initialize the Scheduler -- this lets me set several "Time Zeros".   Now for the Notifier -- have a loop that simply "fires" the "Do Action" action of the Scheduler.  So why use a Notifier?  it basically allo you to "miss" a clock tick.  Finally,there's the QMH do the Commands.

 

It sounds a little complicated, but it works quite well.  The amount of overhead it pretty trivial -- if you run on a millisecond clock, I'd estimate that the overhead is no more than a few microseconds, much less than 1%.  So you can schedule what you want to do when y ou want to do it.

0 Kudos
Message 4 of 4
(2,429 Views)