LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx start and reference trigger

Solved!
Go to solution

Hello,

 

I try to understand deeper the DAQmx data acquisition VIs, but even after reading many white papers, I have still some questions.

 

In my project, I would like to start a data acq. triggered by a start trigger (external trigger source connected to the PFI3 connector, I have an older PCI MIO16E DAQ card),

and I need to stop the data collection when another trigger occures (reference trigger, same source, PFI3). I have found this KB page, and an example VI:

KB page for DAQmx

I would like to modify this VI to be able to collect all data during 10 rising edge trigger. And I have to stop DAQ when the 10th trigger occures. So how can I stop the DAQ in the while loop, not at the first reference trigger, but after a given number of reference trigger?

 

Also, could someone explain me the idea behind the "pre-trigger" and "post-trigger" samples? Why do I need these parameters? I only would like to collect all data during N reference trigger, and I need to collect them in chunks (Samples per read in the example VI) since I would like to put an RMS value of these data portions to a Chart. So, how should I specify the above parameters, if I only need data between the start trigger, and the specified Nth reference trigger?

Also, what is the best way to save all the raw data (converted to 4 byte floats) into a little endian binary file (for a C program post processing)?

 

Thanks for help!

Regards,

 

 

 

Message 1 of 14
(10,305 Views)

After some more reading on the topic, I think I may understood what is pre - and pro-trigger samples.

 

If I want to read only the data between the start trigger and the reference trigger (stop trigger), I need to know in advance, how many samples are produced by the card between the two trigger signals. I have to set the pre-trigger samples to be equal to the above number. Also, I set the post-trigger samples to the smallest possible value: 2, since I do not need data after the stop trigger happened.

 

So I need to calculate the exact time between two trigger signal (in my project, I will change this trigger rate for different measurements), and multiply it with the DAQ rate.

Am I right?

 

My other question is still open: how can I stop the daq after N reference triggers?

thanks!

 

0 Kudos
Message 2 of 14
(10,286 Views)

Hello,

 

please find my VI attached, in this VI I try to implement what I have learned so far (i started from an example).

I have the strong feeling, I do not understand whats going on 100%, so please direct me to the best solution.

 

In this VI, first I measure the time between two adjacent triggers, in sec. I multiply this time with the DAQ rate, to get the number of samples in one time period. I use this number after that to get the data. Could you comment on my VI please?

 

What I guess, is that, if I want to measure for example 3 periods of data, I have to set the buffer size and the post-trigger samples accordingly. But I guess there is an upper limit in buffer size...? (in my final project, one period will be several minutes, and the rate will be 200kHz, so huge amount of data expected) Or is there a better way to stop DAQ after N number of trigger signals? In this case, I could set the buffer to a smaller value?

 

So in a nutshell: I do not 100% understand the relation between these parameters (and how should I set them, to fulfill my needs):

 

-num of pre-trigger samples

-num of post-trigger samples

-buffer size (DAQmx configure input)

-DAQmx Read property node - Relative to ....

- and the conditional structure in the while loop.

 

 

Thanks very much for any help!

Regards,

 

 

 

0 Kudos
Message 3 of 14
(10,273 Views)

I have found this page:

http://zone.ni.com/devzone/cda/epd/p/id/5028

I am not at my work PC, I will check this out, if I have the solution, I will post it here.

 

0 Kudos
Message 4 of 14
(10,263 Views)

pretrigger samples per channel specifies the minimum number of samples to acquire per channel before recognizing the Reference Trigger. The number of post-trigger samples per channel is equal to number of samples per channel in the DAQmx Timing VI minus pretrigger samples per channel.

 

So all you need to do is to set pretrigger samples per channel to a sample number that fits your acquisition requirements.

0 Kudos
Message 5 of 14
(10,251 Views)

Hello,

 

I tried to implement the second example what I have found.

Please find it attached. This code occasionally crashes, with this error:

 

"Some or all of the samples requested have not yet been acquired.

To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger,  make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.

Property: RelativeTo
Corresponding Value: Current Read Position
Property: Offset
Corresponding Value: 0

Task Name: _unnamedTask<4A>"

 

But other times, the code runs ok, and giving me the required results. What can be the problem? In the final code, the RMS calculation will be outside of this subVI, and I will send the 20k samples out at every iteration via a Queue line, so I do not load the DAQmx loop with additional calculation.

Can be the error caused by this, or I have other problematic parts in this code?

 

Thanks for any advice, and comments!

Regards,

0 Kudos
Message 6 of 14
(10,248 Views)

The error was caused by a simple timeout, I just realized. The DAQmx Read had a given timeout parameter 10 sec, and sometimes when I use my system in slow scan mode, the time can be several minutes between two trigger signals (also several minutes until the first, start trigger arrives). I set the timeout to -1, so the DAQmx Read waits indefinitely until the start trigger arrives. Actually my code just gives me the required results, with parameter pre-trigger samples set to 2, the lowest possible number.

I extract 20 000 samples in every iteration (rate is 200 kHz, so one tieration takes approx. 0.1 sec), and I send these data chunks out from the subVI via a QUEUE.

Message 7 of 14
(10,232 Views)
Solution
Accepted by Blokk

exactly!  This might be one of those times you want to catch and ignore timeout errorsSmiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 14
(10,226 Views)

May I have an additional question regarding to the official example VI?

http://zone.ni.com/devzone/cda/epd/p/id/5028

 

Here I would like to know the actual value of the counter during the while loop is running (I need to send this info beside the data chunks out via the queue line).

What is the best methode to do this? Shell I just put a DAQmx Read Counter U32 1Samp in the while loop? Becuse I could not find a property node to extract the actual value of the counter...

 

thanks!

Message 9 of 14
(10,221 Views)

You can connect a  wire to the "i" (for iteration) in the while structure in order to read the counter value of the while loop.

 

I hope this is the "counter" you were asking for.

0 Kudos
Message 10 of 14
(10,176 Views)