LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop DAQmx after movement & variable delay

Hi all,

 

I am very new to LV and am having a tough time with what seems like it should be a simple problem.

 

I am designing an experiment where I want to detect when people perform a thumb movement (over a threshold movement size criterion), then play a sound, then wait somewhere between 1-2 seconds and stop reading/ writing the output to tdms file.

 

 

It was working when I initialised the program (because 'change time' was initialised to 0)

Therefore, when my threshold was reached, this set 'change time' to the current loop time from 0 --> comparison time became less than change time (by the amount of my variable interval) --> it sent a stop signal

 

But I want to run multiple trials and I can't work out how to get the 'change time' to start at 0 again for each while loop...

 

VI is attached (sorry about all the indicators, was using them to try help work out the problem)

 

Any help would be greatly appreciated - I am going to have a problem with my boss if I can't get something working soon!!

 

Thank you,

 

Harriet

0 Kudos
Message 1 of 6
(2,619 Views)

Learn about Shift Registers.  You brought your Time values into the While Loop through a "Tunnel" (the filled-in square on the edge of the loop).  Each time the loop repeats, that same value is read.

 

A Shift Register (right-click the While Loop and choose Add Shift Register) is a pair of triangular-shaped edge connectors.  The first time the loop runs, it takes whatever is wired from outside as the value for that loop.  On the output side, you must wire (from the inside) the value you want the Shift Register to have on the next iteration.  Shift Registers (like Tunnels) can take any LabVIEW Data Type, but the same data type must be wired (from the left) to both Input and Output Registers.  [Think of a Shift Register as local "memory" that gets updated each time through the loop].

 

Example -- Wire Current Time to the Shift Register.  Inside the Loop, put a Delay of, say, 2 seconds.  After the delay finishes (this is a trick stipulation -- how do you ensure "after the delay finishes"?), get the Current Time, subtract the earlier Current Time, and call the result "Elapsed Time" and wire it to an indicator.  Also, take the "inner" Current Time and wire it to the output Shift Register.

 

The next time the loop runs, it will use the first-loops-ending Current Time, compute a new "delayed Current Time", and get the same Elapsed Time.  [Of course, you remembered to wire a Stop button to stop the While loop ...].

 

Bob Schor

Message 2 of 6
(2,586 Views)

Hey hdempseyjones,

 

for being "very new" to LabVIEW your code already looks quite good! Nice to see the producer-consumer loops and that you know how to use error wires!

 

I found a tutorial on Shift Registers and more: Passing Data Between Loop Iterations in LabVIEW

 

Although it feels like you already attended the LabVIEW Core 1 and 2 courses, there is of course also an explanation of loops in them. Depending on your license you might have access to the Self-Paced Online Training course versions from NI. Maybe also useful for you: How Do I Access Online Training on an NI Academic Site License?


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
0 Kudos
Message 3 of 6
(2,571 Views)

Hi Bob, I definitely needed to learn about shift registers! I have now solved my issue using your suggestions and some other bits and pieces

 

Code is attached if you are interested

 

Thank you very much!

0 Kudos
Message 4 of 6
(2,512 Views)

Thanks for the info! went back and did some back to basics stuff which helped a lot (including more about shift registers)

 

I attached the working code to Bob's comment if you are interested

 

Thanks again 🙂

0 Kudos
Message 5 of 6
(2,511 Views)

Now all you have to do is to learn a little "restraint", namely to resist the temptation to put everything in one humongous Block Diagram.  Having to scroll around (or else have at least 4 large monitors) in order to see what you are doing is not fun (so I didn't bother).  What's the secret?  Sub-VIs, especially ones where you've taken the (very minor) trouble to create a VI Icon for it, something as simple as a Square that has 3 lines of text saying what the sub-VI does.  Now your Top Level Block Diagram can show Important Structures (like the Producer/Consumer pattern) with most of the "busy work" taking place inside sub-VIs with Icons like "Read DAQmx", "Update Time", "Scale Voltage", etc.  Simplifying your code by "hiding the details" will make it much clearer what you are doing in the Top Level (it's not easy following your logic with wires going all over the place -- try to keep wires straight, left-to-right, no kinks).

 

Bob Schor

Message 6 of 6
(2,507 Views)