LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pausing DAQmx between loops

Solved!
Go to solution

Hello,

I'm performing a force tracing study and I'm trying to develop a program that will write the acquired data to a spreadsheet and then stop DAQmx for 5 seconds between trials to provide the participant rest. In this program the participant is trying to match a force tracing to a sine wave. When I have used the wait function in my program by adding an additional sequence and placing the wait function within it the program waits 5 seconds, but then the sine wave and force tracing show up on the waveform chart with a 5 second delay.

My VI is attached, does anyone know how I can implement a wait period in this program without a delay in the plot?

0 Kudos
Message 1 of 13
(2,990 Views)

Here are a few (varied) suggestions:

  • You don't need to use underscores in VI names (call if "Force Trace Sine V2.vi").
  • You (almost) never need to use a Sequence structure -- the Error Line and Principle of Data Flow should handle serialization for you.
  • If I understand what you want to do, the DAQmx sequence is as follows:
    • Initialize DAQmx parameters.
    • For each of N Trials,
      • Start Task.
      • Loop (For or While) and Read until Acquisition done.
      • Stop Task
      • Wait 5 seconds
    • Clear DAQmx Task (you're all done).

Give that a try, see if adding Start Task and Stop Task, moving Initialize out of Trials loop, etc. makes it better.

 

I notice in your Acquire loop that you've wired 2000 to N.  That means that you take 2000 epochs of N samples (I don't know how many points are in your waveform) -- is that what you want to do?

 

Bob Schor

0 Kudos
Message 2 of 13
(2,964 Views)

You also might want to change your DAQmx Read to be 1 Channel 1 Sample since that will better match your simulated sine wave and it will limit your loop rate.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 13
(2,958 Views)

Hi Bob,

Yes, I'm sampling at 100 Hz. When you refer to "move initialize outside of the loop are you referring to "Create Channel" and "Sample Clock"? Also is there a specific time delay function I should be using? Is there a VI part of the DAQmx family that will stall data transfer between the blocks?

Thank you for your suggestions. I will try them when I get home later tonight.

0 Kudos
Message 4 of 13
(2,928 Views)

Well, "Wait (ms)" waits the specified number of milliseconds.  Note there is no Error Line in the Wait function, so you need to think about Data Flow and make sure that the Wait happens between the end of the Data Collection loop and the end of the "Trial" Loop (i.e. it has to be "in the spaces" between one set of records and the next one).

 

Try leaving out all the DAQ code, build a dummy routine (like turn an Indicator On while you are supposed to be acquiring, and Off during the "between trials" times, and see if you can get the loop and timing logic right (you should see the Boolean be True during the time of acquisition, turn False (off) for 5 seconds between trials, the back to On, etc.).

 

Bob Schor

0 Kudos
Message 5 of 13
(2,918 Views)

The Wait ms function is not working in the code. There is still zero delay between trials. I have attached my VI. Have I placed the wait function in the correct location?

0 Kudos
Message 6 of 13
(2,912 Views)
Solution
Accepted by Liddy

I tried to drop hints, but I guess I was too subtle.  Do you know/understand the key LabVIEW Principle of Data Flow?  "Disconnected functions" (like your Wait function) should be considered as all executing in parallel, that is, because there is no "data dependence" between them, there is no way to predict which comes first. 

 

Consider the Wait Function and everything else in the While Loop.  The latter are all "connected by wires" (most prominently by the Error Line), so they all run in strict serial order.  Indeed, the For Loop doesn't begin until the computations that feed its inputs are done, and the processing of the data and writing to file don't take place until the For loop exits.

 

Aha -- when does the History get reset, before or after you enter the For loop and start putting data into the Chart?  The Correct Answer is -- you have no idea, because it has no data dependency!  I presume you want to clear the chart before the For loop, so use the Error Line on the Property Node and place it before the Error Line enters the For Loop.

 

I'm going to guess (because LabVIEW is pretty good about running code in parallel) that the Wait 5 seconds starts at the same time as the Data Acquisition, so if it takes more than 5 seconds, it's already finished by the time the inner For Loop exits.  How to fix this?

 

This is one of the rare times that a Flat Sequence (around the Wait function) makes sense -- it allows you to run the Error Line through the Frame and force the Wait to occur after the loop.  [Another way to do this is to put the Wait "time", 5000, inside the For loop and tunnel it out to the Wait -- until the For Loop exits, the value of 5000 won't be available to the Wait, so it will (you'll forgive the play on words) have to "wait" until it can start executing its 5-second Wait.

 

Bob "Data Flow" Schor

Message 7 of 13
(2,890 Views)

Hi Bob,

I tried your suggestions and they work for the first trial (data is plotted for 20 seconds at 100 Hz and then pauses for 5 seconds). However, on the second trial (loop) the data is plotted for 15 seconds with a 5 second pause. So I'm having the same problem. Also the clear history property node is not clearing the chart after every trial. I'm not sure what to do here. I really appreciate your help and am doing LabVIEW research everyday to get this working, but I've been stuck for over a week now. Both my sine wave and DAQ are set at continuous sample generation do you think this is why I'm observing this behavior? I have attached the VI with your suggestions included. I really appreciate your help.

0 Kudos
Message 8 of 13
(2,888 Views)

I figured it out. Thank you for your help.

0 Kudos
Message 9 of 13
(2,877 Views)

Hi Liddy,

 

I'm glad to see one of our entrusted veterans of NI could assist you in getting past this hiccup in your development! Would you mind posting a quick summary of exactly what you did to resolve it so that others who stumble upon this thread can see the solution?

Mike B.
Technical Support Engineer
National Instruments
0 Kudos
Message 10 of 13
(2,864 Views)