LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timed Loop Is Not Working

Hello,

 

I am trying to do a graduate assignment in which I record data for a certain amount of time at specified time intervals.  I am using the Timed Loop to try to achieve that, however, the loop does not record for the time I specify in the Configuration dialog box.  It saves the data much longer than I would like: indefinitely!  Right now I am using the Time Elapsed VI to manually determine how long the loop has been running and when I should shut it off.  The loop and the Write To File does not start unless the Record ON button is pressed.

 

Please help me to troubleshoot the problem of the Timed Loop not listening to my input period, offset, and deadline.  I have attached my vi.

 

Thank you,

Uchechi Okeke

0 Kudos
Message 1 of 14
(5,794 Views)

Several things...

 

The first is don't use stacked sequence structures. They break program flow, they hide code, and they are not scalable. Instead, use a state machine architecture as described at: http://zone.ni.com/devzone/cda/tut/p/id/3024

 

Second, I don't understand why you are trying to save data with a timed loop. What are you trying to acheive with that?

0 Kudos
Message 2 of 14
(5,788 Views)

I assume that you are having problem to log data with a specific interval and duration with the time loop.  If time loop is not giving you the correct interval, how much is it off by?  The code in the time loop may take longer than you like.  You have side a deadline, and that will tell the program how much time each iteration is supposed to take.  If the iteration is finished later than the deadline, you will get a true on the finish late boolean.  You should check for that to see are you finishing late.  Concerning the duration of the whole logging process you can't use the time loop parameters to set this.  Using time elapsed like you are doing would be an idea to do that  

 

 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 3 of 14
(5,781 Views)

Zenthoef,

 

The coding has biomedical engineering


@zenthoef wrote:

Several things...

 

The first is don't use stacked sequence structures. They break program flow, they hide code, and they are not scalable. Instead, use a state machine architecture as described at: http://zone.ni.com/devzone/cda/tut/p/id/3024

 

Second, I don't understand why you are trying to save data with a timed loop. What are you trying to acheive with that?


applications.  In another version of this program that will utilize a DAQ Assist, a person's EMG signal will be acquired.  The Timed Loop is supposed to allow me to acquire data and save it at time intervals.  For instance, I would tell the person to lift 5lbs for 10 seconds, then rest for another 10 seconds (at this point no data recording), then lift 10lbs for another 10 seconds, etc.  In this version, I am using Simulate Signal because I am not always around a DAQ hardware but I still need to make this code work.

 

 

As far as using a State Machine, I've never used that before nor heard of it.  Is this a vi that is generally available because I have not seen that.  The stacked sequence structure is used because there are certain sequences that have to be executed in that order.

 

 

0 Kudos
Message 4 of 14
(5,771 Views)

 


@GradStudent wrote:

Zenthoef,

 

The coding has biomedical engineering applications.  In another version of this program that will utilize a DAQ Assist, a person's EMG signal will be acquired.  The Timed Loop is supposed to allow me to acquire data and save it at time intervals.  For instance, I would tell the person to lift 5lbs for 10 seconds, then rest for another 10 seconds (at this point no data recording), then lift 10lbs for another 10 seconds, etc.  In this version, I am using Simulate Signal because I am not always around a DAQ hardware but I still need to make this code work.

 

 

As far as using a State Machine, I've never used that before nor heard of it.  Is this a vi that is generally available because I have not seen that.  The stacked sequence structure is used because there are certain sequences that have to be executed in that order.

 

 


 

Timed loops are generally for FPGA or microprocessor targets (maybe some others too?). As long as you're running on a PC, I'm not sure there is much point to it. Understood that you are using the simulate signal vi because you don't always have a DAQ. 

 

The state machine isn't really a VI, but it is a software architecture. You can make the state machine execute states in order, just like the stacked sequence structure. The benefit is that the state machine architecture is easily scalable for future development/debugging. You can read about how to use it at the link I provided above.

 

See, in a state machine you could have a state called "Acquire Data" where you record the data as well as information about what weight the person is lifting. Then you could save that in another state called "Save Data".

 

If you must save the data as its being taken the Producer/Consumer architecture is good for that. You can read about that at http://zone.ni.com/devzone/cda/tut/p/id/3023

 

 

0 Kudos
Message 5 of 14
(5,762 Views)

Jyang,

 

I used the indicators on the left data node as suggested and found that the boolean is true within 1 second of starting the loop. If it is to finish late, then I assume that it should finish AFTER the deadline. 

 

For clarification, can you please confirm my understanding of the input settings?  I don't think LabView made these definitions clear and the context help gives examples of 2 different time loops and not or two frames within the same time loop.

1.  Deadline --> The time in which the entire time loop must complete saving data

2.  Period --> The time that the loop should save data

3.  Offset -->  The time to wait before executing the time loop. 

4.  Timeout -->  The longest that the loop can wait before "activating"

 

For instance, if I had a deadline of 10s, a period of 3s, and an offset of 2s, when triggered, the time loop should wait 3s, save data for 5s, wait again for 3s, save again for 5s, and finally end.  Total 10s run time.  Is this correct?

0 Kudos
Message 6 of 14
(5,752 Views)

These toolkits/applications are nice suggestions and would probably solve the problem, however, I am a broke grad student working on a project (free labor).  Smiley Sad  I am limited to what the school offers and they don't have these toolkits.

 

Are there any suggestions for solving the issue of misbehaving timed loops without having to purchase something?  I find it hard to believe that LabView would only have vi's and loops that cannot be applied generally.  A For Loop is my dead last option as I have modified this code several times for months to get this far.  But, if a For loop is the solution, please advise. 

0 Kudos
Message 7 of 14
(5,744 Views)

When you say toolkits/applications are you referring to the state machine architecture and the producer consumer loop architecture? These things are not toolkits or applications, but rather ways to code. You create them yourself with items on the block diagram palettes that LabVIEW already offers. For example, the state machine is a while loop containing a case structure driven by an enum data type. I'd strongly recommend you familiarize yourself with those articles I linked to. You won't have to buy anything and they will really help!

0 Kudos
Message 8 of 14
(5,738 Views)

The timed loop is not misbehaving at all. You just don't understand how it works. What you have is completely inappropriate. You certainly don't need any toolkits any more than you need the timed loop. You do need the acquisition inside some sort of loop. The way you have it, you will only get one signal. A normal while loop will probably be fine. A timed loop will not help that much unless you do move to the sort of real-time LabVIEW that has been mentioned. Inside your loop, you can use the elapsed time function to stop the writing. Once you change Record ON to false, reset the timer so that when you make it true again, the timer will restart and stop the writing after the specified period.

 

0 Kudos
Message 9 of 14
(5,735 Views)

1. Deadline - you can't use this to force an iteration to run faster than it can.  With the deadline, the time loop can only tell you when your iteration exceed the deadline.

2. Period - time between the starts of each iterations.  If the time it takes one iteration to execute is longer than the period, the period will not mean much.  It would be useful if you have a loop that would take 1s per iteration, and you set the period to 10s.  After each iteration run, the loop will wait for 9 second before running the next iteration.

3. Offset - I agree with you

4. Timeout - I agree with you

 

For your example, deadline of 10s, a period of 3s, and an offset of 2s.  The time loop will wait offset=2s before executing the 1st iteration, but the deadline and period will not mean much to you if each iteration will take more than 3s to run.  However, if each loop only take 1s to run, after an iteration run, it will wait for 2s.

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 10 of 14
(5,730 Views)