Grey Posted July 4, 2012 Report Share Posted July 4, 2012 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 . Quote Link to comment
Rolf Kalbermatter Posted July 4, 2012 Report Share Posted July 4, 2012 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. Quote Link to comment
Stagg54 Posted July 5, 2012 Report Share Posted July 5, 2012 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 Quote Link to comment
asbo Posted July 5, 2012 Report Share Posted July 5, 2012 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. Quote Link to comment
Prabhakant Patil Posted July 6, 2012 Report Share Posted July 6, 2012 Hi You can try follwing simple VI. Loop Time 1.vi Loop Time 2.vi Quote Link to comment
LogMAN Posted July 6, 2012 Report Share Posted July 6, 2012 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 Quote Link to comment
Grey Posted July 7, 2012 Author Report Share Posted July 7, 2012 Hi You can try follwing simple VI. Hi prabha Loop time1 is the one i'm looking for. many thanks. 1 Quote Link to comment
TomOrr0W Posted July 7, 2012 Report Share Posted July 7, 2012 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). Quote Link to comment
Ton Plomp Posted July 7, 2012 Report Share Posted July 7, 2012 I would use a timed loop with a timing of 5 minuts. You get pretty good timing, and options to have a constant phase and core utilization. Ton 1 Quote Link to comment
Prabhakant Patil Posted July 9, 2012 Report Share Posted July 9, 2012 As per discussion, the attached sample VI might help you to resolve your problem. Just try this. Prabhakant Loop Time 1.vi Loop Time 3.vi Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.