LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synced aquisition

Hi,

 

I need to acquire data, take pictures and send a trigger (synchronised) in labview. These 3 actions have seperate frequencies but these frequencies will be a multiple of each other and the starting point should be the same. The data need to be saved in a csv and showed on graphs.  I use the DAQ assist for acuiring the data (6 voltage samples, 3 on 9215 BNC, 2 on 9237 and 1 on 9211), IMAQdx for the pictures and one 9401 digital line for the trigger.
I'm pretty new to labview and had some ideas but I'm not sure which would work for the application I need to build. I was wondering if i can acquire the data in a timed loop while writing to a buffer and use another timed loop synced with the first to write the data from the buffer to a csv and show them on the graphs and if necessery (every n cycles with the iteration as a counter) take pictures and/or send the trigger. If someone has a better idea on how to get this done I'm open to suggestions since I had doubts myself.

The max rate the DAQ needs to sample at would be +- 300 Hz. The pictures would be less frequent max 1 hz or something. I was worrying about the timing of the loops. If a pic needs to be taken, a sample send and the data written to the graphs and csv the loop will take a long time, which gives me the problem the first loop needs to take longer as well so the buffer increases. (btw I have no idea how to create this buffer it was just an idea)

 

Any help would be welcome

Thanks in advance,

Cedric

0 Kudos
Message 1 of 3
(3,308 Views)

Boy, do I dislike the DAQ Assistant!  There's an excellent NI White Paper on DAQmx (which, unfortunately, starts with the DAQ Assistant, but read the rest of it and learn!) that you can find by doing a Web search for "Learn 10 Functions in NI-DAQmx ..." -- there's even a Video of an NI Engineer "reading the paper" for you (but I recommend you read it for yourself).

 

You can use the hardware clock of the DAQ device to be your timing source.  [Oh, dear, I didn't see that you are trying to synchronize 3 different DAQ devices -- that complicates things a little, but there are ways to send synch signals ...].  Here's one scenario that I'm simplifying for the purpose of this discussion:

 

Assume you are sampling at 300 Hz, and have set your DAQ device to sample continuously at 300 Hz for 300 points.  You can probably figure out that this loop will "fire" at 1 Hz, delivering an array of 300 samples.  You have a second loop that is set to take a single frame from your camera using IMAQdx (and do something with it -- are you just displaying it, or are you trying to save it as an AVI or a series of PNGs?).  Finally, you also want to send a Trigger signal (how often?  you don't say, but let's assume every 5 seconds, in synch with the DAQ and Camera).

 

You set up three loops running in parallel, and set up a mechanism to communicate between the loops.  One way to do this, with examples that come with LabVIEW, is to use a Producer/Consumer Design Pattern (there are some Producer/Consumer Templates that you can try that show you how this works).  Start with the DAQ loop, which will "fire" once a second as it "produces" 300 points at 300 Hz.  You put this in a Producer/Consumer Queue, which gets dequeued in the Consumer Loop where you can (a) write it to a Chart and (b) write it to a disk file.

 

You need a second (well, really a third) loop to fire once/second and tell the Camera to take a picture and "do something" with it.  You can't use the same Queue for this loop, as you can Enqueue Many but Dequeue Once.  However, you could put a Notifier in the Producer Loop and fire off a Notification when the Producer Fires.  The Camera loop could Wait on Notifier, and take a picture every time it receives one.  That takes care of the once/second Camera Loop.

 

The Trigger is also in its own loop.  It can also take the Notifier, since, unlike Queues, there can be many loops waiting on the same Notifier.  You only want to send the Trigger every 5 seconds, so count the Notifications (1, 2, 3, 4, 5, ...) and when they are divisible by 5, fire off the Trigger.

 

How do you stop all of these parallel loops?  An easy way is to use a VIG (also called a Functional Global Variable), a VI that "stores" a Boolean, initially False, but can be called to set the Boolean to True.  When your "Stop" condition is sensed (perhaps you are using a Stop button), you set the VIG to True.  In each of your parallel loops, you wire the output of the VIG to the Stop Indicator of the While Loop.  Now, whenever the VIG is "turned on", all of the loops, when reading the VIG, will get the "True" output, and will all stop.  No Local Variables, no race conditions.

 

Bob Schor

Message 2 of 3
(3,270 Views)

@Bob_Schor wrote:

Boy, do I dislike the DAQ Assistant!  There's an excellent NI White Paper on DAQmx (which, unfortunately, starts with the DAQ Assistant, but read the rest of it and learn!) that you can find by doing a Web search for "Learn 10 Functions in NI-DAQmx ..." -- there's even a Video of an NI Engineer "reading the paper" for you (but I recommend you read it for yourself).

 

You can use the hardware clock of the DAQ device to be your timing source.  [Oh, dear, I didn't see that you are trying to synchronize 3 different DAQ devices -- that complicates things a little, but there are ways to send synch signals ...].  Here's one scenario that I'm simplifying for the purpose of this discussion:

 

Assume you are sampling at 300 Hz, and have set your DAQ device to sample continuously at 300 Hz for 300 points.  You can probably figure out that this loop will "fire" at 1 Hz, delivering an array of 300 samples.  You have a second loop that is set to take a single frame from your camera using IMAQdx (and do something with it -- are you just displaying it, or are you trying to save it as an AVI or a series of PNGs?).  Finally, you also want to send a Trigger signal (how often?  you don't say, but let's assume every 5 seconds, in synch with the DAQ and Camera).

 

You set up three loops running in parallel, and set up a mechanism to communicate between the loops.  One way to do this, with examples that come with LabVIEW, is to use a Producer/Consumer Design Pattern (there are some Producer/Consumer Templates that you can try that show you how this works).  Start with the DAQ loop, which will "fire" once a second as it "produces" 300 points at 300 Hz.  You put this in a Producer/Consumer Queue, which gets dequeued in the Consumer Loop where you can (a) write it to a Chart and (b) write it to a disk file.

 

You need a second (well, really a third) loop to fire once/second and tell the Camera to take a picture and "do something" with it.  You can't use the same Queue for this loop, as you can Enqueue Many but Dequeue Once.  However, you could put a Notifier in the Producer Loop and fire off a Notification when the Producer Fires.  The Camera loop could Wait on Notifier, and take a picture every time it receives one.  That takes care of the once/second Camera Loop.

 

The Trigger is also in its own loop.  It can also take the Notifier, since, unlike Queues, there can be many loops waiting on the same Notifier.  You only want to send the Trigger every 5 seconds, so count the Notifications (1, 2, 3, 4, 5, ...) and when they are divisible by 5, fire off the Trigger.

 

How do you stop all of these parallel loops?  An easy way is to use a VIG (also called a Functional Global Variable), a VI that "stores" a Boolean, initially False, but can be called to set the Boolean to True.  When your "Stop" condition is sensed (perhaps you are using a Stop button), you set the VIG to True.  In each of your parallel loops, you wire the output of the VIG to the Stop Indicator of the While Loop.  Now, whenever the VIG is "turned on", all of the loops, when reading the VIG, will get the "True" output, and will all stop.  No Local Variables, no race conditions.

 

Bob Schor


 

Hi bob,

 

First of all thanks for the quick reply. There is really only one DAQ device (9174 frame with 4 cdaq card slots) but there are 3 cards which i use for input and the 9401 card as output for the trigger. I noticed I'd gave little info so here's some extra...
The camera's need to take 1 shot and save it when the loop runs. The trigger is for a third party device which has labview based software (compressed) but supports shared variables which I'd like to integrate in my program.

I tried some things in my vi and managed to get it running with timed loops and using the difference between the frequencies as indicator for the amount of ticks between the loops itterations. I did not use the daq assist  though 😄
I will also look into the stuff you said though since a lot sounds new (and interesting) to me. I'll take my time to look at everything and do some experimenting with it and if I'm not able to figure it out I'll post some more questions in another reply...

 

Cedric

0 Kudos
Message 3 of 3
(3,243 Views)