Jump to content

Loop timing


Recommended Posts

Hi ,

I am using while loop inside some code. The code execution time is approx 3 minutes.

The moment while loop starts it's first iteration, it should record the system time first and then execute the code inside.

Once the code being executed, before it's next iteration it needs to wait till the system time reaches the next five minutes.

for example : while loop starts at 5.00:00, after the code execution it needs to wait 5:05:00 and then it should start it's next iteration

i want to control each iteration of while/For loop 5 minutes exactly. because i need to measure DUT voltages every five minutes up to 24 Hours :)

Thanks .

Link to comment

Hi ,

I am using while loop inside some code. The code execution time is approx 3 minutes.

The moment while loop starts it's first iteration, it should record the system time first and then execute the code inside.

Once the code being executed, before it's next iteration it needs to wait till the system time reaches the next five minutes.

for example : while loop starts at 5.00:00, after the code execution it needs to wait 5:05:00 and then it should start it's next iteration

i want to control each iteration of while/For loop 5 minutes exactly. because i need to measure DUT voltages every five minutes up to 24 Hours :)

How exact is exactly? If you talk about microseconds you better employ an RT system or some hardware timer. If seconds is enough a little (abortable) wait loop is all that you need.

Link to comment

to add to Rolf's post:

for an abortable wait loop, I just use a notifier as the loop timer. I set the timeout so that it will time out at the correct point in time. Then I can abort it early by sending a notification.

I'm sure other people have other ways of doing this, but I've found it works for me and seems fairly clean to me. YMMV

Link to comment

for an abortable wait loop, I just use a notifier as the loop timer. I set the timeout so that it will time out at the correct point in time. Then I can abort it early by sending a notification.

I'm sure other people have other ways of doing this, but I've found it works for me and seems fairly clean to me. YMMV

The obvious step further with this is an event structure, but that's only necessary if you need to respond to a variety of events, user input, and so on. The notifier method is clean and simple if you only have one source of interrupt.

Link to comment

Hi Grey,

If I understood you correctly, each iteration of your loop takes 3 minutes, but you want it to be 5 minutes.

In my opinion you can just place a 'wait for next ms' next to your active code (in parallel) within your while loop and set it to 5000ms.

Greetings, LogMAN

Link to comment

Hi prabha

Loop time1 is the one i'm looking for.

many thanks.

Note that this vi will use about 100% of cpu time (it will also interfere with timing of other code if you only have one core) on one of your cores due to the lack of a wait function.

Adding wait (ms) with an input of 0 ms inside the body of the loop will still use 100% of cpu time, but it will not interfere with other code as much. A 10 ms wait drops that to be close to 0% (assuming you can tolerate being up to 10 ms late).

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.