LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to initiate two simultaneous tasks? First waits on second.

I'm looking for guidance. I feel my problem is likely very common. It involves performing two tasks simultaneously.

I have a digitizer (pxi5105) and a waveform generator (pxi5412). I need to generate a pulse and record the response simultaneously. My experiment basically works like this. Imagine that a hammer strikes an object causing it to vibrate. I need to record the resulting vibration beginning with the hammer strike. The generator is the hammer, it generates a pulse. The digitizer records the vibration.

I can imagine a couple of ways to do this. One is to first initialize the digitizer (set it up to measure voltage), then start the generator. The rising generator signal would trigger the digitizer to take a reading. The reading would be returned to the program for processing.  I'm thinking the digitizer task would have to run in a separate thread. Upon completion, the digitizer task would invoke a callback function in the main program to process the data. I think there's an example program demonstrating this kind of threaded programming. Is this the best way?

Another approach might be to first turn on the generator and let it run continuously. Then activate the digitizer to trigger off the generator signal as before. This would avoid the complexity of a separate thread. Is this a better approach?

Is there a way to trigger generator and digitizer simulaneously?

If there is documentation/example of this please point me there.

Any recommendations are greatly appreciated.


thanks!

0 Kudos
Message 1 of 2
(2,623 Views)

Hi,

 

I do not think you have to use multiple threads.

Being very expensive devices, the digitizer and the wave gen are capable of handling most of the stuff on their own.

 

First, you configure the generator to generate and the digitizer to trigger and acquire.

Then, you start the wave generation by software command (digitizer starts acquiring automatically after the waveform crosses the trigger level).

Then, you wait for the acquisition to finish.

Then, you read the samples from the digitizer into your array.

Then, you process them.

 

As you see the flow of operations that your program should implement are sequential, not parallel.

So I do not see a point where you will need multiple threads.

 

If the generated waveform is very slow and thus the acquisition is supposed to last too long,

you can use a small timeout value for your "Fetch waveform" function and loop on it.

This way, since you can process events within this loop, your program will keep being responsive.

 

Hope this helps,

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 2
(2,607 Views)