LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loosing data between loops

Hello,

 

i created the VI for signal aquisition with NI 6009.

In first while loop, signal is aquired, and samples are saved in csv. (working good)

In second while loop i have need to save only samples starting when signal pass 0 for the first time, and ends when signal pass 0 fifth time.

Problem is that sometimes, i have all samples in second loop, and sometimes some samples are lost.

I belive that buffer cause the problem, because cannot save all samples.

Can someone advise how to overcome this problem.

If i put lower sampling rate, result are a little bit better, but still insufficient . And I need solid solution.

Please check VI and example in att.

 

Thank you on your help.

Milan

Download All
0 Kudos
Message 1 of 5
(2,004 Views)

Don't have time for thorough analysis or response.  Two major points:

 

1. DATAFLOW!!!   The array makes a dataflow dependency such that your 2nd loop *cannot* start executing until after your 1st loop has *finished* executing.  (And the 1st loop can only terminate when you click your stop button.) 

 

2. Do some research on the Producer / Consumer pattern that uses 2 *independent* loops with no dataflow dependency.

 

 

- Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 5
(1,972 Views)

You don't understand the Principle of Data Flow, the central "idea" that lets LabVIEW do such a good job as an "Engineering Workbench" (the last two letters of "LabVIEW").  You also don't understand the Concept of Time in LabVIEW, and how data acquisition is designed to be done in LabVIEW.

 

First, DAQ.  You have (correctly, I think) set up your DAQ routine to collect samples at 1kHz, and to acquire them 1000 at a time (which means that every second, you get 1000 points).  You collect them inside a While Loop (but aren't collecting the entire sample, which is a "mis-understanding" error), save them to a file, and output nothing until you stop sampling (that's part of the Principle of Data Flow).

 

Drat.  I don't have enough time to write a mini-essay on understanding DAQmx, thinking through your problem by concentrating on what you want to do and knowing enough LabVIEW to determine better determine how you want to do it, the Principle of Data Flow and how it can enable parallel processing, etc.  So I'm going to simplify this and suggest one way to approach this.

 

Let's say you set up your DAQ to always collect 1000 samples at a time.  This takes precisely 1 second.  I'm going to suggest you build a State Machine.  I'm giving only the 30,000 ft (or 10,000 m) view of this -- look up LabVIEW State Machine to fill in the gaps.

 

Here I encounter a semantic problem -- there is the "State" of the "State machine" (i.e. "what does it do next?") and the "State" of the "Problem", namely "Have I crossed threshold for saving?".  

  • "Collect" State -- take 1000 points and go to Next State, initially "Look for Threshold".
  • Look for Threshold -- this is the initial next State, where you see if you've crossed the Data-Saving Threshold.  If no, you do nothing and go to Next State = Collect.  If Yes, go to Start Saving.
  • Start Saving -- open output file, start saving data, keep track of points saved and set flag to know you want to "Keep saving".  Go to Next State = Collect.
  • Keep Saving -- add data to output file, determine if you need to keep collecting (in which case Next State = Collect) or Time to Quit (Next State = Time to Quit).
  • Time to Quit -- close the file, exit the loop, stop the DAQ.

Notice that this displays no data.  You can add that in later -- the important "What" you need to figure out is how to start and stop data saving.

 

Bob Schor

0 Kudos
Message 3 of 5
(1,970 Views)

Hello,

 

just to inform you that I solved problem.

I used producer-consumer design, to reduce time in producer loop.

Thanks for your sugestions and advice.

 

Best regards.

Milan

0 Kudos
Message 4 of 5
(1,925 Views)

Glad that you got it working.

I'll point out what seems to be a fairly crushing problem with the VI you uploaded just in case it appears in a future VI you write: your stop condition for the first loop is a button which will end the loop when it becomes true - this value is then passed out of the loop and into the second where it will immediately stop the second loop at the end of the first iteration.

In the mean time, you'll only get the first element via the indexing input, which prevents you managing to process any of the data.


GCentral
0 Kudos
Message 5 of 5
(1,903 Views)