LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you save waveform data w/ a variable iteration?

Solved!
Go to solution

An 'iteration' is the number of times that a loop operates.

If the loop runs 5 times, you could say that it iterates 5 times.

 

The little blue 'i' is the current iteration, just so you can keep track in your code.

 

Now to do what you described, "saving every n seconds" you will need a little bit of code for timing.

Unless told otherwise, a While loop will run as fast as it can, until the Stop condition is met.

 

You should put a Wait function in the loop, to control data aquisition timing.

So if you put a Wait in the loop and wire 1000 to it, it will wait 1000 ms (= 1 sec) before taking another data point.

If you wanted to save every 10th point, you would do the code I showed before.

 

So the data in the file would show 0:10, 0:20, 0:30, etc.

You can change the aquisition rate by changing the Wait time,

and you can change the saving rate by changing the 'Variable' input.

Cory K
Message 11 of 34
(2,053 Views)

Don't stack while loops. The inner whil loop will prevent the outer while loop from spinning.

 

Just use the elapsed time express VI (configured for auto reset and your desired interval) and connect the "elapsed?" output to a case structure in the big loop.

Message 12 of 34
(2,044 Views)

So I moved the while loop (the one inside the large one) outside of the large one, and now the graph moves, but the loop still does not iterate at the proper times.

I have a "wait" VI hooked up to a number control (as shown in my block diagram) but that does not do anything, neither does the Boolean switch I put on there, I ran the VI, and canceled it without pressing the "save" button, but it still saved a new file, so I suspect that the loop iterates one time, no matter what, and that my switches and controls actually do nothing.

 

Is there a reason my switches and whatnot don't do anything?

0 Kudos
Message 13 of 34
(2,015 Views)
Please attach your code again. I don't understand your description.
0 Kudos
Message 14 of 34
(2,007 Views)
Partsblock.jpg
0 Kudos
Message 15 of 34
(2,004 Views)

The string wire between the two loops forces the the second (logging) to wait until the other loop is done.

 

Please take a look at the Producer/Consumer design pattern to see how a Queue can be used to pass the data between your loops.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 16 of 34
(1,995 Views)

I looked at the consumer/producer page, and I see how it 'works' but I don't really know how I can apply it to my VI, I mean, I see how I could, but I don't know how.

Would I have to esentially start from scratch to make it work?

0 Kudos
Message 17 of 34
(1,990 Views)

Complete re-write, no.

 

0) Toss the wire between the loops. It will be replaced by a queue. 

 

1)reate the queue prior to the two lops and pass the queue ref to both loops. The two llops will not start until they get the ref.

 

2) In the producer use an enqueue function que-up the dat coming out of the Index array".

 

3) Use a Check queue status in the consumer (logging) and if more han one entry found then use dequeue element to get the data.

 

Re:#3

 

If it is not time to log a value then don't do anything with what came out of the queue. If it is time, then log it.

 

Backup what you have, try what I described and then post back with new images so we can coach you through the next challenge.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 18 of 34
(1,978 Views)
partsblock2.jpg
0 Kudos
Message 19 of 34
(1,969 Views)

I didn't really understand steps two and three.

In step two, did you want me to link the data coming out of the 'Index Array' VI into the queue? (Instead of whatever I have)

 

0 Kudos
Message 20 of 34
(1,968 Views)