LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

execute code every set time

I know this is a fairly basic topic that has been discussed here before and I appologize for that in advance. I need to a chunk of code to begin execution every set time interval regardless of how long the code takes to execute. I understand the wait function inserts some amount of time BETWEEN the executions (ie from the the end of one iteration to the beginning of the next) and the wait for next millisecond multiple is like starting at the top of every hour on the hour (or however long) regardless of how long the execution takes on any given iteration. This is what I need since my code execution time varies greatly from one iteration to the next but I need it to begin execution every minute regardless of whether it took the whole minut
e the last time or only a few seconds. The problem is that I want it to begin the first execution at the time I hit the button and go minutely from there and not wait for the top of the next minute like I understand the wait for next millisecond multiple function would.
What then, is the best way to do this. I could use the timer funtion and time how long the code takes to execute, then subtract that from the time I want between executions and then "wait" the remaining time. Is there a better way to do what I want than this?

Thanks.
0 Kudos
Message 1 of 5
(3,104 Views)
One way is to use either the Tick Count function or Get Date/Time in Seconds and a shift register to keep track of start time and current time. The example I've attached initializes the shift register with the current tick count and every loop iteration checks the current tick, subtracts it from the initial count and sees if it is greater than some interval. When the interval is reached, the current tick count becomes the new value in the shift register.
Message 2 of 5
(3,104 Views)
Thank you for that example code. I have attached a sample of the way I solved the problem that appears to work. I was hoping you could tell me if there are any advantages/disadvantages of one method over the other.

Thanks.
0 Kudos
Message 3 of 5
(3,104 Views)
It should work. I just never use sequences.
0 Kudos
Message 4 of 5
(3,104 Views)
> What then, is the best way to do this. I could use the timer
> funtion and time how long the code takes to execute, then subtract
> that from the time I want between executions and then "wait" the
> remaining time. Is there a better way to do what I want than this?
>

Do what you describe. You have a particular time, when the button was
pressed, that you want to make all delay delta relative to. Since you
can measure what that is, and the other LV primitives don't know what it
is, just make it as you describe.

Greg McKaskle
0 Kudos
Message 5 of 5
(3,104 Views)