Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

AI DAQmx read continuous samples read most recent

 

Hi everyone,

I’m working on an analog acquisition task where I continuously read out samples after switching between multiple PCBA boards.

Here’s my setup:

  • Sample rate: 100 kS/s

  • Each readout: 100 samples

  • Before each readout, I use digital output lines to select the target PCBA board (address lines).

  • After switching, I insert a 20 ms delay to ensure the board output is stable before reading.

To test this, I alternately switch between two boards:

  • Board 1: ~3.9 V output

  • Board 2: ~3.2 V output

However, the results show it has error, but if i change the delay into 50 ms, it works

 

So it seems the readout order is misaligned.

I’m using continuous sampling mode to avoid repeatedly calling Start and Stop, but it appears difficult to control exactly which samples are read from the buffer. I’m not fully clear on how the buffering works — does DAQmx keep reading until the PC-side buffer is full? How large is this buffer by default?

At a 100 kS/s sampling rate, the buffer fills very quickly, and after a 20 ms delay there should already be plenty of new data — theoretically enough to read only the most recent 100 samples. However, in practice this doesn’t seem to work as expected, and the readout doesn’t always align with the timing of the board switching.

Coherent_L_0-1763111184213.png

Coherent_L_1-1763111974189.png

 

 

 

0 Kudos
Message 1 of 9
(175 Views)

I made some edits to your VI, try it. I believe there might be a problem with the "stall data flow.VI". I believe the reason for your misalignment is in the part where it reads from the buffer, it is set to read a certain number of elements from the buffer at a time.

Example of elements in buffer when "stall" happens (should be an even number of samples):

ch1

ch2

ch1

ch2

ch1 <---- misalignment (total # of samples = 5)

after the stall and on the next cycle you end reading 

ch2

ch1

ch2

ch1

 

0 Kudos
Message 2 of 9
(143 Views)

Hi Thank you for your reply, I noticed you delete the "stall"

But I need some delay like a 1 ms delay, to make sure the address selection is stable then to read out the latest volts using AI. Do you have some ideas on that?

0 Kudos
Message 3 of 9
(137 Views)

Seems like you should not be using the Continuous Samples mode. Change your timing to be Finite Samples. Then when you do a read, it starts the acquisition.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
0 Kudos
Message 4 of 9
(126 Views)

Also, first of all — I ran the VI you shared, but it threw an error as shown in the first picture.

 

Second, I’ve encountered the same error before. It seems to occur because there isn’t enough offset available for the initial readout, according to the discussion in the link below. Following the suggestion in that post, I tried adding an overwrite with an initial offset of 0 before the first readout, as the post recommended. The idea is that when there aren’t enough samples to apply an offset, the offset should be set to 0.

After the first loop iteration, I set the offset to -100. However, the results I obtained seem misaligned:

The first value is 3.2,

The second through eleventh values are all 3.9,

And the twelfth through fifteenth values are all 3.2.

 

I’m quite confused about how the readout mechanism works with the buffer and how the offset impacts it.

 

Reference:
NI Forum Discussion – Error 200277: Invalid combination of position and offset in DAQ Read

 https://forums.ni.com/t5/LabVIEW/Error-200277-Invalid-combination-of-position-and-offset-in-Daq/td-p...

Coherent_L_0-1763163661009.png

Coherent_L_1-1763164577527.png

 

 

0 Kudos
Message 5 of 9
(121 Views)

Thank you for your reply, I also just run your code, but it has another error.

Error code: -200278
Message: Attempted to read samples that are no longer available — The requested sample was previously available, but has since been overwritten.

Coherent_L_0-1763165595723.png

 

0 Kudos
Message 6 of 9
(115 Views)

Oh, by the way, when I run the VI in debug (highlight execution) mode, only the first loop iteration returns valid data — in the following loops, the readout is zero.
I believe this happens because the task is configured to acquire only 100 samples.
If I want to use finite sampling, I have to start and stop the task inside the loop. I’ve tried this approach before — it works, but it’s quite slow, since starting the task takes about 20 ms and stopping it takes around 7 ms.

0 Kudos
Message 7 of 9
(113 Views)

Lots of comments & questions here in no particular order.

 

1. I don't see an obvious problem in the original screencap.  Are you sure you're using a device capable of sampling 16 channels at 100 kHz *EACH*?   This question is inspired by your remark about "working" with a 50 msec delay rather than a 20 msec delay.

 

2. You make reference to "misalignment".  What exactly do you mean by that?

 

3. The suggestion from crossrulz to use finite sampling is a simpler approach conceptually.  I can't experiment on hw now, but try his code after *removing* the AI task call to DAQmx Start before the loop.  Then each call to DAQmx Read in the loop might auto-start a distinct finite acquisition.  I think that's what he was going for.

 

4. What exactly are your requirements around timing from digital write to dataset to be collected?  I ask because you are combining the imprecise and variable software timing of "Stall Data Flow" with the much more precise and repeatable timing of your DAQ device's sample clock.  If you need precise and *repeatable* timing from digital write to AI capture, you would need careful hardware level sync between your Digital and AI task.

 

5. What DAQ device are you using?  (I ask because some devices won't support the timing sync referenced in #4).

 

6. To follow my example you linked to, your code in msg #5 should read 100 AI samples *before* the loop (while offset is 0)  to preload the buffer.

 

7. I'd highly recommend simplifying your acquisition as part of troubleshooting.  You're accumulating a 3D array and it can be tricky to be sure you're indexing into it correctly for the data subsets you're interpreting.  Do a 1 channel AI acquisition, read a 1D array, and accumulate a 2D array instead -- that's much more straightforward to display and interpret.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 8 of 9
(89 Views)

Thank you for joining our discussion. 

 

I am using NI USB-6451 

 

Coherent_L_0-1763666470140.png

 

 

I adopted a different approach to achieve my goal, as described below.
I use an internal trigger to synchronize both the AI and DO modules so that all samples—including those taken during the switching of the board—are captured. This requires preparing the same number of DO samples in advance and applying changes at specific time points. With this method, the final AI samples will still include the unstable switching voltages, but I can filter those out afterward.

Coherent_L_1-1763666512589.png

 

However, I am still interested in understanding the mechanism and usage of the AI “most recent samples” property.
First, is there any official example demonstrating how to use this feature? 

Also, when using an offset such as –100, is it necessary to fill the entire buffer, or is it sufficient to load only the number of samples you actually need (for example, just 100 samples)?  Does it should allow pre-loading samples before the acquisition loop—was it designed for that purpose?

 

I just shared this post link to a NI engineer, hope we can get a answer.

 

0 Kudos
Message 9 of 9
(35 Views)