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?
Solved! Go to Solution.
Here are a few (varied) suggestions:
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?
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.
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.
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.).
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?
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
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.
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?