12-18-2007 01:22 PM
12-19-2007 12:25 PM - edited 12-19-2007 12:26 PM
12-20-2007 05:21 PM - edited 12-20-2007 05:21 PM
Hi George,
Neal makes some great points about your code. After getting more information
from you, I've been able to determine some good ways as to accomplish what you
are attempting (acquire a single sample every time the PFI line is asserted
over varying amounts of time). First off, let's configure your hardware before
heading into the while loop by using a "DAQmx Control Task." This
will set the hardware settings until the task is cleared and not be continually
programmed by a start VI (which now simply tells the board to start), which can
be inefficient. Inside your while loop, we'll call the "Start Task,"
"Read," and also "Stop" functions. Since your trigger will
be coming in at any time (10m seconds all the way up to 5 minutes), we should
set the timeout to -1. This will read one value right when you assert the PFI
line with your ion beam and continue to do so while the program runs. The
downside to this is that when you click the stop button, TWO more triggers must
come in before the program exits the while loop. This is because of the timeout
blocking execution of anything else. I've attached this VI (test5good.vi) for
you to view.
One way to get around this is to set the timeout value to be small, let the
"Read" VI timeout, programmatically discard that specific error code,
and allow the loop to run again. You should still catch your triggers. See the
picture below:
One way to avoid the 'blocking' nature of reading finite sample(s) is to set
your timing VI to “continuously sample”. This will allow you to press the stop
button at any time during execution. Because DAQ boards require at least 2
samples before sending the samples to memory, we will have to fill this buffer
with 2 samples every time you send a start trigger and then discard the 2nd
sample. To do this is a little tricky but the attached vi (test5better.vi)
accomplishes the task. In a nutshell, I set up my M-series card's counter to
generate 2 pulses whenever a trigger is received. This is linked to the analog
task's timing clock (sample clock) so your DAQmx Read VI (set to 1 ch, N samples)
will sample twice. Then, using a case statement, we discard the second sample
if data is available.
I Neal and I's advise has helped you and again, thanks for using the National
Instruments Forums!
-Patrick Barrett | Applications Engineering | National Instruments