LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Either or Function from two sourses

Writing a program which reads a digital 5volt pulse from one of two infra red relays.  I play a stimulus (magnetic field, light etc) and then ask the animal to say if the stimulus is present or absent by moving to one end of the test chamber and tripping a infra red beam. If the animal trips the correct one I want to give it a food reward, and a time out penalty if it trips the wrong one. Currently I can't work out how to get the program to stop once one of the two beams is tripped, it will only stop one both beams have been crossed. This means I can't detect the choice made which is the whole point.  

Is there a node or way getting an impulse from one source to stop checking the other?

0 Kudos
Message 1 of 9
(3,632 Views)

When you read both signals, build them into an array and then use the "search 1D array" function to determine which of the signals came back "T".  Then base your decision making on that (i.e. element 0 came back "T", so give the animal a treat) and use a case structure to execute the appropriate code.

 

Message 2 of 9
(3,628 Views)
Sorry...incomplete post on that last one.  Use an "OR" function to stop your acquisition loop.  I meant to put that in the previous post.  Read both signals.  Use an "OR" function to stop the data acquisition, then use the "search 1D array" function to determine which signal stopped the loop and execute a case structure based on that.
0 Kudos
Message 3 of 9
(3,625 Views)
Thanks for the reply! However, I'm was already doing that as a solution, problem is due to the experimental design. I can't have the animal trigger both. Is there away to stop looking for one put once the othe one has been triggered. Is there any way in lab view?
0 Kudos
Message 4 of 9
(3,583 Views)

Here is a picture showing what I suggested in my previous post.  If the animal trips one of the signals, the loop will stop.

 

 

0 Kudos
Message 5 of 9
(3,574 Views)
I'm self taught and using lab view 8.2 so I really appreciate this help! Sweet I think I see what you are doing but I'm not so certain about the two lines bit. How do you set that up?

Currently I can only get one line in. Here are two pics, one of my current sub vI for checking the infrared set up and another for selecting between the choices

 

Thanks again

Josh 
Download All
0 Kudos
Message 6 of 9
(3,567 Views)

Hi Josh,

 

Here is the reason your VI isn't working:

 

In order for your sub-VI (infrared checker) to stop executing, the digital line must return a value of "T".  A "T" value is what stops your loop in your subVI.  Therefore, in your outer loop, you have to have both of your subroutines return "T" in order for the loop to iterate.  (the loop can't iterate until all of the subroutines inside of it have finished executing.)  That is why the animal has to trip both lines before your outer loop will stop...both of your subVIs need to finish executing, and they can't finish executing until the digital line has returned a "T" value.  Does that make sense?

 

In the picture I showed, both lines are read at the same time, so only one of them has to return "T" in order for the loop to iterate. 

 

You either need to read both lines at the same time, as I showed, or you need to remove the loop from your subVI.  When you remove the loop from your subVI, you'll essentially be duplicating what I showed you -- you'll just be using two tasks to accomplish what I accomplished with a single task.

 

To read both signals with a single task, you need to tell the task to read both lines simultaneously.  I did this by specifying two digital channels:  lines 0 and 1.  (look at the syntax for the physical channel in my picture)  Then use the same DAQmx Read instance that I used:  multiple channels, single sample.

 

If you want to do this using a task in MAX, simply specify lines 0 and 1 (or whichever lines you're using to read your signals) as the physical channels for that task.  Use <ctrl> to select multiple lines, the same way you'd use it to select multiple files in any Windows application.

 

Hope that makes things clear...

Diane

Message 7 of 9
(3,552 Views)
Yup thanks that makes sense. Wrote the program you sent (please check) it runs but I don't get an input or the loop being terminated. I'm teaching on a field trip for the next 10 days so if I don't get back to you with a result after that its coz I'm lost in the forest with 30 undergrads and a panicing proffessor....wish me luck. 😉
0 Kudos
Message 8 of 9
(3,535 Views)

Good luck with your field trip.  🙂

 

You will want to add a small delay time to your loop, to ensure that it doesn't hog up the entire CPU.  You will also want to add a "stop" button so you can exit out of your routine at will.  Using the "abort" button to stop a VI is NOT good practice.

 

Also note that I have assumed that a returned value of "T" means that the animal tripped one of the sensors.  If a "F" value means that the animal tripped one of the sensors, you will need to adjust your loop-stopping logic accordingly.

 

The attached picture shows the time delay and a "stop" button.  I'll leave you to play with your own Boolean logic so that it fits your needs.

0 Kudos
Message 9 of 9
(3,513 Views)